diff --git "a/.opencode/node_modules/effect/src/DateTime.ts" "b/.opencode/node_modules/effect/src/DateTime.ts" --- "a/.opencode/node_modules/effect/src/DateTime.ts" +++ "b/.opencode/node_modules/effect/src/DateTime.ts" @@ -1,4 +1,13 @@ /** + * Works with absolute instants, UTC date-times, zoned date-times, and time + * zones. + * + * A `DateTime` always represents an absolute point in time with epoch + * milliseconds. It may also carry a `TimeZone` for calendar parts, formatting, + * and zone-aware transformations. This module includes constructors, time-zone + * helpers, comparisons, date arithmetic, current-time effects, and formatting + * functions. + * * @since 3.6.0 */ import type { IllegalArgumentError } from "./Cause.ts" @@ -22,14 +31,21 @@ const TimeZoneTypeId = Internal.TimeZoneTypeId * A `DateTime` represents a point in time. It can optionally have a time zone * associated with it. * - * @since 3.6.0 * @category models + * @since 3.6.0 */ export type DateTime = Utc | Zoned /** - * @since 3.6.0 + * Represents a `DateTime` stored as an absolute UTC instant with no associated + * time zone. + * + * **Details** + * + * Use `DateTime.isUtc` to narrow a `DateTime` to this variant. + * * @category models + * @since 3.6.0 */ export interface Utc extends DateTime.Proto { readonly _tag: "Utc" @@ -38,8 +54,16 @@ export interface Utc extends DateTime.Proto { } /** - * @since 3.6.0 + * Represents a `DateTime` with an associated `TimeZone`. + * + * **Details** + * + * A zoned value still represents an absolute instant through + * `epochMilliseconds`, while the time zone is used for wall-clock parts, + * formatting, and zone-aware transformations. + * * @category models + * @since 3.6.0 */ export interface Zoned extends DateTime.Proto { readonly _tag: "Zoned" @@ -51,31 +75,60 @@ export interface Zoned extends DateTime.Proto { } /** + * Companion namespace containing the public helper types used by `DateTime` + * constructors, parts APIs, formatting, and date/time arithmetic. + * * @since 3.6.0 - * @category models */ export declare namespace DateTime { /** - * @since 3.6.0 + * Input accepted by `DateTime.make`, `DateTime.makeUnsafe`, and the zoned + * constructors. + * + * **Details** + * + * Includes existing `DateTime` values, partial date parts, epoch-millisecond + * objects, epoch milliseconds, JavaScript `Date` instances, and parseable date + * strings. + * * @category models + * @since 3.6.0 */ export type Input = DateTime | Partial | Instant | InstantWithZone | Date | number | string /** - * @since 3.6.0 + * Type-level helper used by constructors to preserve a zoned input. + * + * **Details** + * + * When the input type is `DateTime.Zoned`, the result type is + * `DateTime.Zoned`; otherwise the result type is `DateTime.Utc`. + * * @category models + * @since 3.6.0 */ export type PreserveZone = A extends Zoned ? Zoned : Utc /** - * @since 3.6.0 + * Date and time unit name accepted by `DateTime` rounding and arithmetic + * APIs. + * + * **Details** + * + * Includes both singular units, such as `"day"`, and plural units, such as + * `"days"`. + * * @category models + * @since 3.6.0 */ export type Unit = UnitSingular | UnitPlural /** - * @since 3.6.0 + * Singular date and time unit names used by rounding APIs such as + * `DateTime.startOf`, `DateTime.endOf`, and `DateTime.nearest`. + * * @category models + * @since 3.6.0 */ export type UnitSingular = | "millisecond" @@ -88,8 +141,11 @@ export declare namespace DateTime { | "year" /** - * @since 3.6.0 + * Plural date and time unit names used by `DateTime.PartsForMath` for + * amount-based arithmetic. + * * @category models + * @since 3.6.0 */ export type UnitPlural = | "milliseconds" @@ -102,8 +158,16 @@ export declare namespace DateTime { | "years" /** - * @since 3.6.0 + * Calendar and time components of a `DateTime`, including the weekday. + * + * **Details** + * + * `month` is one-based (`1` for January through `12` for December), and + * `weekDay` follows JavaScript `Date#getUTCDay` numbering (`0` for Sunday + * through `6` for Saturday). + * * @category models + * @since 3.6.0 */ export interface PartsWithWeekday { readonly millisecond: number @@ -117,8 +181,14 @@ export declare namespace DateTime { } /** - * @since 3.6.0 + * Calendar and time components of a `DateTime`, without weekday information. + * + * **Details** + * + * `month` is one-based (`1` for January through `12` for December). + * * @category models + * @since 3.6.0 */ export interface Parts { readonly millisecond: number @@ -131,8 +201,14 @@ export declare namespace DateTime { } /** - * @since 3.6.0 + * Plural amount fields accepted by `DateTime.add` and `DateTime.subtract`. + * + * **Details** + * + * Each field represents the number of units to add or subtract for that part. + * * @category models + * @since 3.6.0 */ export interface PartsForMath { readonly milliseconds: number @@ -146,16 +222,26 @@ export declare namespace DateTime { } /** - * @since 4.0.0 + * Object input representing an absolute instant as milliseconds since the Unix + * epoch. + * * @category models + * @since 4.0.0 */ export interface Instant { readonly epochMilliseconds: number } /** - * @since 4.0.0 + * Object input representing an absolute instant plus a time zone identifier. + * + * **Details** + * + * `DateTime.makeZoned` and `DateTime.makeZonedUnsafe` use `timeZoneId` when + * no explicit `timeZone` option is supplied. + * * @category models + * @since 4.0.0 */ export interface InstantWithZone { readonly timeZoneId: string @@ -163,8 +249,15 @@ export declare namespace DateTime { } /** - * @since 3.6.0 + * Shared protocol implemented by all `DateTime` values. + * + * **Details** + * + * Provides the `DateTime` type identifier along with pipe and inspection + * support. + * * @category models + * @since 3.6.0 */ export interface Proto extends Pipeable, Inspectable { readonly [TypeId]: typeof TypeId @@ -172,27 +265,48 @@ export declare namespace DateTime { } /** - * @since 3.6.0 + * Represents a time zone used by `DateTime.Zoned`. + * + * **Details** + * + * A `TimeZone` is either a fixed offset from UTC or a named IANA time zone. + * * @category models + * @since 3.6.0 */ export type TimeZone = TimeZone.Offset | TimeZone.Named /** + * Companion namespace containing the public variant and protocol types for + * `TimeZone`. + * * @since 3.6.0 - * @category models */ export declare namespace TimeZone { /** - * @since 3.6.0 + * Shared protocol implemented by all `TimeZone` values. + * + * **Details** + * + * Provides the `TimeZone` type identifier and inspection support. + * * @category models + * @since 3.6.0 */ export interface Proto extends Inspectable { readonly [TimeZoneTypeId]: typeof TimeZoneTypeId } /** - * @since 3.6.0 + * Fixed-offset time zone. + * + * **Details** + * + * The `offset` is measured in milliseconds from UTC. Positive offsets are + * ahead of UTC, and negative offsets are behind UTC. + * * @category models + * @since 3.6.0 */ export interface Offset extends Proto { readonly _tag: "Offset" @@ -200,8 +314,15 @@ export declare namespace TimeZone { } /** - * @since 3.6.0 + * Named IANA time zone. + * + * **Details** + * + * The `id` field contains the resolved time zone identifier, such as + * `"Europe/London"` or `"America/New_York"`. + * * @category models + * @since 3.6.0 */ export interface Named extends Proto { readonly _tag: "Named" @@ -215,6 +336,8 @@ export declare namespace TimeZone { * A `Disambiguation` is used to resolve ambiguities when a `DateTime` is * ambiguous, such as during a daylight saving time transition. * + * **Details** + * * For more information, see the [Temporal documentation](https://tc39.es/proposal-temporal/docs/timezone.html#ambiguity-due-to-dst-or-other-time-zone-offset-changes) * * - `"compatible"`: (default) Behavior matching Temporal API and legacy JavaScript Date and moment.js. @@ -228,7 +351,8 @@ export declare namespace TimeZone { * * - `"reject"`: Throw an `RangeError` when encountering ambiguous or non-existent times. * - * @example + * **Example** (Resolving ambiguous local times) + * * ```ts * import { DateTime } from "effect" * @@ -268,8 +392,8 @@ export declare namespace TimeZone { * // Time after gap: 2025-03-09T07:30:00.000Z (03:30 EDT) * ``` * - * @since 3.18.0 * @category models + * @since 3.18.0 */ export type Disambiguation = "compatible" | "earlier" | "later" | "reject" @@ -278,48 +402,97 @@ export type Disambiguation = "compatible" | "earlier" | "later" | "reject" // ============================================================================= /** - * @since 3.6.0 + * Checks whether a value is a `DateTime`. + * + * **When to use** + * + * Use to narrow an unknown value before treating it as a `DateTime`. + * + * @see {@link isUtc} for narrowing a known `DateTime` to UTC + * @see {@link isZoned} for narrowing a known `DateTime` to zoned + * * @category guards + * @since 3.6.0 */ export const isDateTime: (u: unknown) => u is DateTime = Internal.isDateTime /** - * Checks if a value is a `TimeZone`. + * Checks whether a value is a `TimeZone`. + * + * **When to use** + * + * Use to narrow unknown input to any `TimeZone` before passing it to APIs that + * accept either fixed-offset or named time zones. + * + * @see {@link isTimeZoneOffset} for narrowing to fixed-offset time zones + * @see {@link isTimeZoneNamed} for narrowing to named time zones * - * @since 3.6.0 * @category guards + * @since 3.6.0 */ export const isTimeZone: (u: unknown) => u is TimeZone = Internal.isTimeZone /** - * Checks if a value is an offset-based `TimeZone`. + * Checks whether a value is an offset-based `TimeZone`. + * + * **When to use** + * + * Use when you need to narrow an unknown or union `TimeZone` value to the + * fixed-offset variant before reading its offset in milliseconds. + * + * @see {@link isTimeZone} for checking either time zone variant + * @see {@link isTimeZoneNamed} for narrowing to named time zones * - * @since 3.6.0 * @category guards + * @since 3.6.0 */ export const isTimeZoneOffset: (u: unknown) => u is TimeZone.Offset = Internal.isTimeZoneOffset /** - * Checks if a value is a named `TimeZone` (IANA time zone). + * Checks whether a value is a named `TimeZone` (IANA time zone). + * + * **When to use** + * + * Use to narrow an unknown value to the `TimeZone.Named` variant before + * reading named-zone fields such as `id`. + * + * @see {@link isTimeZone} for checking either time zone variant + * @see {@link isTimeZoneOffset} for narrowing to fixed-offset time zones * - * @since 3.6.0 * @category guards + * @since 3.6.0 */ export const isTimeZoneNamed: (u: unknown) => u is TimeZone.Named = Internal.isTimeZoneNamed /** - * Checks if a `DateTime` is a UTC `DateTime` (no time zone information). + * Checks whether a `DateTime` is a UTC `DateTime` (no time zone information). + * + * **When to use** + * + * Use to narrow a `DateTime` before passing it to code that requires a UTC + * value without an associated time zone. + * + * @see {@link isZoned} for narrowing to zoned date-times + * @see {@link match} for handling both UTC and zoned cases * - * @since 3.6.0 * @category guards + * @since 3.6.0 */ export const isUtc: (self: DateTime) => self is Utc = Internal.isUtc /** - * Checks if a `DateTime` is a zoned `DateTime` (has time zone information). + * Checks whether a `DateTime` is a zoned `DateTime` (has time zone information). + * + * **When to use** + * + * Use to narrow a known `DateTime` before reading its zone or passing it to + * APIs that require `DateTime.Zoned`. + * + * @see {@link isUtc} for narrowing to UTC date-times + * @see {@link match} for handling both UTC and zoned cases * - * @since 3.6.0 * @category guards + * @since 3.6.0 */ export const isZoned: (self: DateTime) => self is Zoned = Internal.isZoned @@ -328,12 +501,15 @@ export const isZoned: (self: DateTime) => self is Zoned = Internal.isZoned // ============================================================================= /** - * An `Equivalence` for comparing two `DateTime` values for equality. + * Provides an `Equivalence` for comparing two `DateTime` values for equality. + * + * **Details** * * Two `DateTime` values are considered equivalent if they represent the same * point in time, regardless of their time zone. * - * @example + * **Example** (Comparing DateTime values for equivalence) + * * ```ts * import { DateTime } from "effect" * @@ -351,12 +527,15 @@ export const isZoned: (self: DateTime) => self is Zoned = Internal.isZoned export const Equivalence: Equ.Equivalence = Internal.Equivalence /** - * An `Order` for comparing and sorting `DateTime` values. + * Provides an `Order` for comparing and sorting `DateTime` values. + * + * **Details** * * `DateTime` values are ordered by their epoch milliseconds, so earlier times * come before later times regardless of time zone. * - * @example + * **Example** (Sorting DateTime values chronologically) + * * ```ts * import { Array, DateTime } from "effect" * @@ -376,13 +555,16 @@ export const Equivalence: Equ.Equivalence = Internal.Equivalence export const Order: order.Order = Internal.Order /** - * Clamp a `DateTime` between a minimum and maximum value. + * Returns a `DateTime` constrained between a minimum and maximum value. + * + * **Details** * * If the `DateTime` is before the minimum, the minimum is returned. * If the `DateTime` is after the maximum, the maximum is returned. * Otherwise, the original `DateTime` is returned. * - * @example + * **Example** (Clamping DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -394,18 +576,21 @@ export const Order: order.Order = Internal.Order * // clamped equals max (2024-12-31) * ``` * - * @category instances + * @category ordering * @since 3.6.0 */ export const clamp: { /** - * Clamp a `DateTime` between a minimum and maximum value. + * Returns a `DateTime` constrained between a minimum and maximum value. + * + * **Details** * * If the `DateTime` is before the minimum, the minimum is returned. * If the `DateTime` is after the maximum, the maximum is returned. * Otherwise, the original `DateTime` is returned. * - * @example + * **Example** (Clamping DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -417,18 +602,21 @@ export const clamp: { * // clamped equals max (2024-12-31) * ``` * - * @category instances + * @category ordering * @since 3.6.0 */ (options: { readonly minimum: Min; readonly maximum: Max }): (self: A) => A | Min | Max /** - * Clamp a `DateTime` between a minimum and maximum value. + * Returns a `DateTime` constrained between a minimum and maximum value. + * + * **Details** * * If the `DateTime` is before the minimum, the minimum is returned. * If the `DateTime` is after the maximum, the maximum is returned. * Otherwise, the original `DateTime` is returned. * - * @example + * **Example** (Clamping DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -440,7 +628,7 @@ export const clamp: { * // clamped equals max (2024-12-31) * ``` * - * @category instances + * @category ordering * @since 3.6.0 */ (self: A, options: { readonly minimum: Min; readonly maximum: Max }): A | Min | Max @@ -453,9 +641,12 @@ export const clamp: { /** * Create a `DateTime` from a `Date`. * + * **Details** + * * If the `Date` is invalid, an `IllegalArgumentError` will be thrown. * - * @example + * **Example** (Creating DateTime values from Dates) + * * ```ts * import { DateTime } from "effect" * @@ -466,12 +657,19 @@ export const clamp: { * ``` * * @category constructors - * @since 3.6.0 + * @since 4.0.0 */ export const fromDateUnsafe: (date: Date) => Utc = Internal.fromDateUnsafe /** - * Create a `DateTime` from one of the following: + * Create a `DateTime` from supported input values. + * + * **When to use** + * + * Use when creating a `DateTime` from trusted input and construction failures + * should throw an `IllegalArgumentError` instead of returning `Option.none`. + * + * **Details** * * - A `DateTime` * - A `Date` instance (invalid dates will throw an `IllegalArgumentError`) @@ -479,27 +677,39 @@ export const fromDateUnsafe: (date: Date) => Utc = Internal.fromDateUnsafe * - An object with the parts of a date * - A `string` that can be parsed by `Date.parse` * - * @since 3.6.0 - * @category constructors - * @example + * **Example** (Creating DateTime values unsafely) + * * ```ts * import { DateTime } from "effect" * * // from Date - * DateTime.makeUnsafe(new Date()) + * const fromDate = DateTime.makeUnsafe(new Date("2024-01-01T12:00:00Z")) + * console.log(DateTime.formatIso(fromDate)) // "2024-01-01T12:00:00.000Z" * * // from parts - * DateTime.makeUnsafe({ year: 2024 }) + * const fromParts = DateTime.makeUnsafe({ year: 2024 }) + * console.log(DateTime.formatIso(fromParts)) // "2024-01-01T00:00:00.000Z" * * // from string - * DateTime.makeUnsafe("2024-01-01") + * const fromString = DateTime.makeUnsafe("2024-01-01") + * console.log(DateTime.formatIso(fromString)) // "2024-01-01T00:00:00.000Z" * ``` + * + * @category constructors + * @since 4.0.0 */ export const makeUnsafe: (input: A) => DateTime.PreserveZone = Internal.makeUnsafe /** * Create a `DateTime.Zoned` using `DateTime.makeUnsafe` and a time zone. * + * **When to use** + * + * Use when the date/time input and zone options are trusted and invalid or + * rejected ambiguous times should throw instead of returning `Option.none`. + * + * **Details** + * * The input is treated as UTC and then the time zone is attached, unless * `adjustForTimeZone` is set to `true`. In that case, the input is treated as * already in the time zone. @@ -511,14 +721,20 @@ export const makeUnsafe: (input: A) => DateTime.Preser * - `later`: Always choose the later of two possible times * - `reject`: Throw an error when ambiguous times are encountered * - * @since 3.6.0 - * @category constructors - * @example + * **Example** (Creating zoned DateTime values unsafely) + * * ```ts * import { DateTime } from "effect" * - * DateTime.makeZonedUnsafe(new Date(), { timeZone: "Europe/London" }) + * const zoned = DateTime.makeZonedUnsafe("2024-06-15T14:30:00Z", { + * timeZone: "Europe/London" + * }) + * + * console.log(DateTime.formatIsoZoned(zoned)) // "2024-06-15T15:30:00.000+01:00[Europe/London]" * ``` + * + * @category constructors + * @since 4.0.0 */ export const makeZonedUnsafe: (input: DateTime.Input, options?: { readonly timeZone?: number | string | TimeZone | undefined @@ -527,29 +743,43 @@ export const makeZonedUnsafe: (input: DateTime.Input, options?: { }) => Zoned = Internal.makeZonedUnsafe /** - * Create a `DateTime.Zoned` using `DateTime.make` and a time zone. + * Creates a `DateTime.Zoned` safely from an input and a time zone. * - * The input is treated as UTC and then the time zone is attached, unless - * `adjustForTimeZone` is set to `true`. In that case, the input is treated as - * already in the time zone. + * **Details** * - * When `adjustForTimeZone` is true and ambiguous times occur during DST transitions, - * the `disambiguation` option controls how to resolve the ambiguity: - * - `compatible` (default): Choose earlier time for repeated times, later for gaps - * - `earlier`: Always choose the earlier of two possible times - * - `later`: Always choose the later of two possible times - * - `reject`: Throw an error when ambiguous times are encountered + * By default, the input is interpreted as a UTC instant and the time zone is + * attached without changing that instant. When `adjustForTimeZone` is `true`, + * the input is interpreted as wall-clock time in the target zone. * - * If the date time input or time zone is invalid, `None` will be returned. + * When `adjustForTimeZone` is `true`, `disambiguation` controls + * daylight-saving gaps and repeated times: + * + * - `"compatible"` (default): chooses the earlier occurrence for repeated + * times and the later interpretation for gaps + * - `"earlier"`: chooses the earlier possible instant + * - `"later"`: chooses the later possible instant + * - `"reject"`: rejects ambiguous or nonexistent wall-clock times + * + * Returns `Some` when construction succeeds, or `None` when the input, time + * zone, or disambiguation cannot be resolved. + * + * **Example** (Creating optional zoned DateTime values) * - * @since 3.6.0 - * @category constructors - * @example * ```ts * import { DateTime } from "effect" * - * DateTime.makeZoned(new Date(), { timeZone: "Europe/London" }) + * const result = DateTime.makeZoned("2024-06-15T14:30:00Z", { + * timeZone: "Europe/London" + * }) + * + * console.log(result._tag) // "Some" + * if (result._tag === "Some") { + * console.log(DateTime.formatIsoZoned(result.value)) // "2024-06-15T15:30:00.000+01:00[Europe/London]" + * } * ``` + * + * @category constructors + * @since 3.6.0 */ export const makeZoned: ( input: DateTime.Input, @@ -561,40 +791,58 @@ export const makeZoned: ( ) => Option.Option = Internal.makeZoned /** - * Create a `DateTime` from one of the following: + * Creates a `DateTime` safely from supported input values. + * + * **Details** * * - A `DateTime` - * - A `Date` instance (invalid dates will throw an `IllegalArgumentError`) - * - The `number` of milliseconds since the Unix epoch - * - An object with the parts of a date - * - A `string` that can be parsed by `Date.parse` + * - A JavaScript `Date` + * - The number of milliseconds since the Unix epoch + * - An object with date and time parts + * - A string that can be parsed as a date * - * If the input is invalid, `None` will be returned. + * Returns `Some` with the constructed `DateTime` when the input is valid, or + * `None` when construction would fail, including invalid `Date` instances or + * unparseable strings. + * + * **Example** (Creating optional DateTime values) * - * @since 3.6.0 - * @category constructors - * @example * ```ts * import { DateTime } from "effect" * * // from Date - * DateTime.make(new Date()) + * const fromDate = DateTime.make(new Date("2024-01-01T12:00:00Z")) + * console.log(fromDate._tag) // "Some" * * // from parts - * DateTime.make({ year: 2024 }) + * const fromParts = DateTime.make({ year: 2024 }) + * console.log(fromParts._tag) // "Some" * * // from string - * DateTime.make("2024-01-01") + * const fromString = DateTime.make("2024-01-01") + * console.log(fromString._tag) // "Some" + * + * const invalid = DateTime.make("not a date") + * console.log(invalid._tag) // "None" * ``` + * + * @category constructors + * @since 3.6.0 */ export const make: (input: A) => Option.Option> = Internal.make /** - * Create a `DateTime.Zoned` from a string. + * Parses an ISO zoned date-time string into a `DateTime.Zoned` safely. * - * It uses the format: `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]`. + * **Details** + * + * Accepts named-zone strings such as + * `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]` and offset-only strings such as + * `YYYY-MM-DDTHH:mm:ss.sss+HH:MM`. Returns `None` when the input cannot be + * parsed. + * + * **Example** (Parsing zoned DateTime strings) * - * @example * ```ts * import { DateTime } from "effect" * @@ -610,33 +858,36 @@ export const make: (input: A) => Option.Option Option.Option = Internal.makeZonedFromString /** - * Get the current time using the `Clock` service and convert it to a `DateTime`. + * Gets the current time using the `Clock` service and convert it to a `DateTime`. + * + * **Example** (Getting the current DateTime) * - * @since 3.6.0 - * @category constructors - * @example * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function*() { - * const now = yield* DateTime.now + * const now = yield* DateTime.nowAsDate + * console.log(now instanceof Date) // true * }) * ``` + * + * @category constructors + * @since 3.6.0 */ export const now: Effect.Effect = Internal.now /** - * Get the current time using the `Clock` service and convert it to a `DateTime`. + * Gets the current time from the `Clock` service and returns it as a + * JavaScript `Date`. + * + * **Example** (Getting the current Date) * - * @since 3.6.0 - * @category constructors - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -644,16 +895,27 @@ export const now: Effect.Effect = Internal.now * const now = yield* DateTime.now * }) * ``` + * + * @category constructors + * @since 3.14.0 */ export const nowAsDate: Effect.Effect = Internal.nowAsDate /** - * Get the current time using `Date.now`. + * Gets the current time using `Date.now`. + * + * **When to use** + * + * Use when synchronous wall-clock access outside an Effect program is + * acceptable and testability through the `Clock` service is not needed. + * + * **Details** * * This is a synchronous version of `now` that directly uses `Date.now()` * instead of the Effect `Clock` service. * - * @example + * **Example** (Getting the current DateTime unsafely) + * * ```ts * import { DateTime } from "effect" * @@ -662,7 +924,7 @@ export const nowAsDate: Effect.Effect = Internal.nowAsDate * ``` * * @category constructors - * @since 3.6.0 + * @since 4.0.0 */ export const nowUnsafe: LazyArg = Internal.nowUnsafe @@ -671,11 +933,19 @@ export const nowUnsafe: LazyArg = Internal.nowUnsafe // ============================================================================= /** - * For a `DateTime` returns a new `DateTime.Utc`. + * Converts a `DateTime` to a UTC `DateTime`. + * + * **When to use** + * + * Use to represent the same instant in UTC instead of its current time zone. + * + * **Details** + * + * The returned value keeps the same epoch milliseconds and changes only the + * `DateTime` representation to UTC. + * + * **Example** (Converting DateTime values to UTC) * - * @since 3.13.0 - * @category time zones - * @example * ```ts * import { DateTime } from "effect" * @@ -686,15 +956,17 @@ export const nowUnsafe: LazyArg = Internal.nowUnsafe * // set as UTC * const utc: DateTime.Utc = DateTime.toUtc(now) * ``` + * + * @category time zones + * @since 3.13.0 */ export const toUtc: (self: DateTime) => Utc = Internal.toUtc /** - * Set the time zone of a `DateTime`, returning a new `DateTime.Zoned`. + * Sets the time zone of a `DateTime`, returning a new `DateTime.Zoned`. + * + * **Example** (Setting time zones) * - * @since 3.6.0 - * @category time zones - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -706,14 +978,16 @@ export const toUtc: (self: DateTime) => Utc = Internal.toUtc * const zoned: DateTime.Zoned = DateTime.setZone(now, zone) * }) * ``` + * + * @category time zones + * @since 3.6.0 */ export const setZone: { /** - * Set the time zone of a `DateTime`, returning a new `DateTime.Zoned`. + * Sets the time zone of a `DateTime`, returning a new `DateTime.Zoned`. + * + * **Example** (Setting time zones) * - * @since 3.6.0 - * @category time zones - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -725,6 +999,9 @@ export const setZone: { * const zoned: DateTime.Zoned = DateTime.setZone(now, zone) * }) * ``` + * + * @category time zones + * @since 3.6.0 */ ( zone: TimeZone, @@ -734,11 +1011,10 @@ export const setZone: { } ): (self: DateTime) => Zoned /** - * Set the time zone of a `DateTime`, returning a new `DateTime.Zoned`. + * Sets the time zone of a `DateTime`, returning a new `DateTime.Zoned`. + * + * **Example** (Setting time zones) * - * @since 3.6.0 - * @category time zones - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -750,6 +1026,9 @@ export const setZone: { * const zoned: DateTime.Zoned = DateTime.setZone(now, zone) * }) * ``` + * + * @category time zones + * @since 3.6.0 */ ( self: DateTime, @@ -762,13 +1041,14 @@ export const setZone: { } = Internal.setZone /** - * Add a fixed offset time zone to a `DateTime`. + * Adds a fixed offset time zone to a `DateTime`. + * + * **Details** * * The offset is in milliseconds. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting fixed-offset time zones) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -779,16 +1059,20 @@ export const setZone: { * const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000) * }) * ``` + * + * @category time zones + * @since 3.6.0 */ export const setZoneOffset: { /** - * Add a fixed offset time zone to a `DateTime`. + * Adds a fixed offset time zone to a `DateTime`. + * + * **Details** * * The offset is in milliseconds. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting fixed-offset time zones) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -799,6 +1083,9 @@ export const setZoneOffset: { * const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000) * }) * ``` + * + * @category time zones + * @since 3.6.0 */ ( offset: number, @@ -808,13 +1095,14 @@ export const setZoneOffset: { } ): (self: DateTime) => Zoned /** - * Add a fixed offset time zone to a `DateTime`. + * Adds a fixed offset time zone to a `DateTime`. + * + * **Details** * * The offset is in milliseconds. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting fixed-offset time zones) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -825,6 +1113,9 @@ export const setZoneOffset: { * const zoned: DateTime.Zoned = DateTime.setZoneOffset(now, 3 * 60 * 60 * 1000) * }) * ``` + * + * @category time zones + * @since 3.6.0 */ ( self: DateTime, @@ -837,11 +1128,19 @@ export const setZoneOffset: { } = Internal.setZoneOffset /** - * Attempt to create a named time zone from a IANA time zone identifier. + * Attempts to create a named time zone from an IANA time zone identifier. + * + * **When to use** + * + * Use when the IANA zone id is trusted and invalid zones should throw instead + * of returning `Option.none` or failing in `Effect`. + * + * **Details** * * If the time zone is invalid, an `IllegalArgumentError` will be thrown. * - * @example + * **Example** (Creating named time zones unsafely) + * * ```ts * import { DateTime } from "effect" * @@ -855,18 +1154,21 @@ export const setZoneOffset: { * // DateTime.zoneMakeNamedUnsafe("Invalid/Zone") * ``` * - * @since 3.6.0 * @category time zones + * @since 4.0.0 */ export const zoneMakeNamedUnsafe: (zoneId: string) => TimeZone.Named = Internal.zoneMakeNamedUnsafe /** * Create a fixed offset time zone. * + * **Details** + * * The offset is specified in milliseconds from UTC. Positive values are * ahead of UTC, negative values are behind UTC. * - * @example + * **Example** (Creating fixed-offset time zones) + * * ```ts * import { DateTime } from "effect" * @@ -884,11 +1186,14 @@ export const zoneMakeNamedUnsafe: (zoneId: string) => TimeZone.Named = Internal. export const zoneMakeOffset: (offset: number) => TimeZone.Offset = Internal.zoneMakeOffset /** - * Create a named time zone from a IANA time zone identifier. + * Creates a named time zone safely from an IANA time zone identifier. + * + * **Details** * * If the time zone is invalid, `None` will be returned. * - * @example + * **Example** (Creating optional named time zones) + * * ```ts * import { DateTime } from "effect" * @@ -905,11 +1210,15 @@ export const zoneMakeOffset: (offset: number) => TimeZone.Offset = Internal.zone export const zoneMakeNamed: (zoneId: string) => Option.Option = Internal.zoneMakeNamed /** - * Create a named time zone from a IANA time zone identifier. + * Creates a named time zone effectfully from an IANA time zone identifier. * - * If the time zone is invalid, it will fail with an `IllegalArgumentError`. + * **When to use** + * + * Use when invalid IANA zone ids should fail in the Effect error channel + * instead of returning `Option.none` or throwing. + * + * **Example** (Creating named time zones effectfully) * - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -929,18 +1238,18 @@ export const zoneMakeNamedEffect: (zoneId: string) => Effect.Effect Effect.Effect TimeZone.Named = Internal.zoneMakeLocal /** - * Try to parse a `TimeZone` from a string. + * Tries to parse a `TimeZone` from a string safely. + * + * **Details** * * Supports both IANA time zone identifiers and offset formats like "+03:00". * - * @example + * **Example** (Parsing time zones) + * * ```ts * import { DateTime } from "effect" * @@ -972,11 +1284,10 @@ export const zoneMakeLocal: () => TimeZone.Named = Internal.zoneMakeLocal export const zoneFromString: (zone: string) => Option.Option = Internal.zoneFromString /** - * Format a `TimeZone` as a string. + * Formats a `TimeZone` as a string. + * + * **Example** (Formatting time zones) * - * @since 3.6.0 - * @category time zones - * @example * ```ts * import { DateTime } from "effect" * @@ -986,16 +1297,18 @@ export const zoneFromString: (zone: string) => Option.Option = Interna * // Outputs "Europe/London" * DateTime.zoneToString(DateTime.zoneMakeNamedUnsafe("Europe/London")) * ``` + * + * @category time zones + * @since 3.6.0 */ export const zoneToString: (self: TimeZone) => string = Internal.zoneToString /** - * Set the time zone of a `DateTime` from an IANA time zone identifier. If the + * Sets the time zone of a `DateTime` safely from an IANA time zone identifier. If the * time zone is invalid, `None` will be returned. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting named time zones safely) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1005,15 +1318,17 @@ export const zoneToString: (self: TimeZone) => string = Internal.zoneToString * DateTime.setZoneNamed(now, "Europe/London") * }) * ``` + * + * @category time zones + * @since 3.6.0 */ export const setZoneNamed: { /** - * Set the time zone of a `DateTime` from an IANA time zone identifier. If the + * Sets the time zone of a `DateTime` safely from an IANA time zone identifier. If the * time zone is invalid, `None` will be returned. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting named time zones safely) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1023,6 +1338,9 @@ export const setZoneNamed: { * DateTime.setZoneNamed(now, "Europe/London") * }) * ``` + * + * @category time zones + * @since 3.6.0 */ ( zoneId: string, @@ -1032,12 +1350,11 @@ export const setZoneNamed: { } ): (self: DateTime) => Option.Option /** - * Set the time zone of a `DateTime` from an IANA time zone identifier. If the + * Sets the time zone of a `DateTime` safely from an IANA time zone identifier. If the * time zone is invalid, `None` will be returned. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting named time zones safely) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1047,6 +1364,9 @@ export const setZoneNamed: { * DateTime.setZoneNamed(now, "Europe/London") * }) * ``` + * + * @category time zones + * @since 3.6.0 */ ( self: DateTime, @@ -1059,12 +1379,11 @@ export const setZoneNamed: { } = Internal.setZoneNamed /** - * Set the time zone of a `DateTime` from an IANA time zone identifier. If the + * Sets the time zone of a `DateTime` from an IANA time zone identifier. If the * time zone is invalid, an `IllegalArgumentError` will be thrown. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting named time zones unsafely) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1074,15 +1393,17 @@ export const setZoneNamed: { * DateTime.setZoneNamedUnsafe(now, "Europe/London") * }) * ``` + * + * @category time zones + * @since 4.0.0 */ export const setZoneNamedUnsafe: { /** - * Set the time zone of a `DateTime` from an IANA time zone identifier. If the + * Sets the time zone of a `DateTime` from an IANA time zone identifier. If the * time zone is invalid, an `IllegalArgumentError` will be thrown. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting named time zones unsafely) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1092,6 +1413,9 @@ export const setZoneNamedUnsafe: { * DateTime.setZoneNamedUnsafe(now, "Europe/London") * }) * ``` + * + * @category time zones + * @since 4.0.0 */ ( zoneId: string, @@ -1101,12 +1425,11 @@ export const setZoneNamedUnsafe: { } ): (self: DateTime) => Zoned /** - * Set the time zone of a `DateTime` from an IANA time zone identifier. If the + * Sets the time zone of a `DateTime` from an IANA time zone identifier. If the * time zone is invalid, an `IllegalArgumentError` will be thrown. * - * @since 3.6.0 - * @category time zones - * @example + * **Example** (Setting named time zones unsafely) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1116,6 +1439,9 @@ export const setZoneNamedUnsafe: { * DateTime.setZoneNamedUnsafe(now, "Europe/London") * }) * ``` + * + * @category time zones + * @since 4.0.0 */ ( self: DateTime, @@ -1132,16 +1458,17 @@ export const setZoneNamedUnsafe: { // ============================================================================= /** - * Calulate the difference between two `DateTime` values, returning a + * Computes the difference between two `DateTime` values, returning a * `Duration` representing the amount of time between them. * + * **Details** + * * If `other` is *after* `self`, the result will be a positive `Duration`. If * `other` is *before* `self`, the result will be a negative `Duration`. If they * are equal, the result will be a `Duration` of zero. * - * @since 3.6.0 - * @category comparisons - * @example + * **Example** (Measuring distance between DateTime values) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1153,6 +1480,9 @@ export const setZoneNamedUnsafe: { * DateTime.distance(now, other) * }) * ``` + * + * @category comparisons + * @since 3.6.0 */ export const distance: { // ============================================================================= @@ -1160,16 +1490,17 @@ export const distance: { // ============================================================================= /** - * Calulate the difference between two `DateTime` values, returning a + * Computes the difference between two `DateTime` values, returning a * `Duration` representing the amount of time between them. * + * **Details** + * * If `other` is *after* `self`, the result will be a positive `Duration`. If * `other` is *before* `self`, the result will be a negative `Duration`. If they * are equal, the result will be a `Duration` of zero. * - * @since 3.6.0 - * @category comparisons - * @example + * **Example** (Measuring distance between DateTime values) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1181,6 +1512,9 @@ export const distance: { * DateTime.distance(now, other) * }) * ``` + * + * @category comparisons + * @since 3.6.0 */ (other: DateTime): (self: DateTime) => Duration.Duration // ============================================================================= @@ -1188,16 +1522,17 @@ export const distance: { // ============================================================================= /** - * Calulate the difference between two `DateTime` values, returning a + * Computes the difference between two `DateTime` values, returning a * `Duration` representing the amount of time between them. * + * **Details** + * * If `other` is *after* `self`, the result will be a positive `Duration`. If * `other` is *before* `self`, the result will be a negative `Duration`. If they * are equal, the result will be a `Duration` of zero. * - * @since 3.6.0 - * @category comparisons - * @example + * **Example** (Measuring distance between DateTime values) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1209,6 +1544,9 @@ export const distance: { * DateTime.distance(now, other) * }) * ``` + * + * @category comparisons + * @since 3.6.0 */ (self: DateTime, other: DateTime): Duration.Duration } = Internal.distance @@ -1216,7 +1554,8 @@ export const distance: { /** * Returns the earlier of two `DateTime` values. * - * @example + * **Example** (Selecting the earlier DateTime) + * * ```ts * import { DateTime } from "effect" * @@ -1234,7 +1573,8 @@ export const min: { /** * Returns the earlier of two `DateTime` values. * - * @example + * **Example** (Selecting the earlier DateTime) + * * ```ts * import { DateTime } from "effect" * @@ -1252,7 +1592,8 @@ export const min: { /** * Returns the earlier of two `DateTime` values. * - * @example + * **Example** (Selecting the earlier DateTime) + * * ```ts * import { DateTime } from "effect" * @@ -1272,7 +1613,8 @@ export const min: { /** * Returns the later of two `DateTime` values. * - * @example + * **Example** (Selecting the later DateTime) + * * ```ts * import { DateTime } from "effect" * @@ -1290,7 +1632,8 @@ export const max: { /** * Returns the later of two `DateTime` values. * - * @example + * **Example** (Selecting the later DateTime) + * * ```ts * import { DateTime } from "effect" * @@ -1308,7 +1651,8 @@ export const max: { /** * Returns the later of two `DateTime` values. * - * @example + * **Example** (Selecting the later DateTime) + * * ```ts * import { DateTime } from "effect" * @@ -1326,9 +1670,10 @@ export const max: { } = Internal.max /** - * Checks if the first `DateTime` is after the second `DateTime`. + * Checks whether the first `DateTime` is after the second `DateTime`. + * + * **Example** (Checking whether a DateTime is later) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1340,13 +1685,14 @@ export const max: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ export const isGreaterThan: { /** - * Checks if the first `DateTime` is after the second `DateTime`. + * Checks whether the first `DateTime` is after the second `DateTime`. + * + * **Example** (Checking whether a DateTime is later) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1358,13 +1704,14 @@ export const isGreaterThan: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (that: DateTime): (self: DateTime) => boolean /** - * Checks if the first `DateTime` is after the second `DateTime`. + * Checks whether the first `DateTime` is after the second `DateTime`. + * + * **Example** (Checking whether a DateTime is later) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1376,15 +1723,16 @@ export const isGreaterThan: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (self: DateTime, that: DateTime): boolean } = Internal.isGreaterThan /** - * Checks if the first `DateTime` is after or equal to the second `DateTime`. + * Checks whether the first `DateTime` is after or equal to the second `DateTime`. + * + * **Example** (Checking whether a DateTime is later or equal) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1398,13 +1746,14 @@ export const isGreaterThan: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ export const isGreaterThanOrEqualTo: { /** - * Checks if the first `DateTime` is after or equal to the second `DateTime`. + * Checks whether the first `DateTime` is after or equal to the second `DateTime`. + * + * **Example** (Checking whether a DateTime is later or equal) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1418,13 +1767,14 @@ export const isGreaterThanOrEqualTo: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (that: DateTime): (self: DateTime) => boolean /** - * Checks if the first `DateTime` is after or equal to the second `DateTime`. + * Checks whether the first `DateTime` is after or equal to the second `DateTime`. + * + * **Example** (Checking whether a DateTime is later or equal) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1438,15 +1788,16 @@ export const isGreaterThanOrEqualTo: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (self: DateTime, that: DateTime): boolean } = Internal.isGreaterThanOrEqualTo /** - * Checks if the first `DateTime` is before the second `DateTime`. + * Checks whether the first `DateTime` is before the second `DateTime`. + * + * **Example** (Checking whether a DateTime is earlier) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1458,13 +1809,14 @@ export const isGreaterThanOrEqualTo: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ export const isLessThan: { /** - * Checks if the first `DateTime` is before the second `DateTime`. + * Checks whether the first `DateTime` is before the second `DateTime`. + * + * **Example** (Checking whether a DateTime is earlier) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1476,13 +1828,14 @@ export const isLessThan: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (that: DateTime): (self: DateTime) => boolean /** - * Checks if the first `DateTime` is before the second `DateTime`. + * Checks whether the first `DateTime` is before the second `DateTime`. + * + * **Example** (Checking whether a DateTime is earlier) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1494,15 +1847,16 @@ export const isLessThan: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (self: DateTime, that: DateTime): boolean } = Internal.isLessThan /** - * Checks if the first `DateTime` is before or equal to the second `DateTime`. + * Checks whether the first `DateTime` is before or equal to the second `DateTime`. + * + * **Example** (Checking whether a DateTime is earlier or equal) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1516,13 +1870,14 @@ export const isLessThan: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ export const isLessThanOrEqualTo: { /** - * Checks if the first `DateTime` is before or equal to the second `DateTime`. + * Checks whether the first `DateTime` is before or equal to the second `DateTime`. + * + * **Example** (Checking whether a DateTime is earlier or equal) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1536,13 +1891,14 @@ export const isLessThanOrEqualTo: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (that: DateTime): (self: DateTime) => boolean /** - * Checks if the first `DateTime` is before or equal to the second `DateTime`. + * Checks whether the first `DateTime` is before or equal to the second `DateTime`. + * + * **Example** (Checking whether a DateTime is earlier or equal) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1556,15 +1912,16 @@ export const isLessThanOrEqualTo: { * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ (self: DateTime, that: DateTime): boolean } = Internal.isLessThanOrEqualTo /** - * Checks if a `DateTime` is between two other `DateTime` values (inclusive). + * Checks whether a `DateTime` is between two other `DateTime` values (inclusive). + * + * **Example** (Checking whether a DateTime is within bounds) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1580,9 +1937,10 @@ export const isLessThanOrEqualTo: { */ export const between: { /** - * Checks if a `DateTime` is between two other `DateTime` values (inclusive). + * Checks whether a `DateTime` is between two other `DateTime` values (inclusive). + * + * **Example** (Checking whether a DateTime is within bounds) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1598,9 +1956,10 @@ export const between: { */ (options: { minimum: DateTime; maximum: DateTime }): (self: DateTime) => boolean /** - * Checks if a `DateTime` is between two other `DateTime` values (inclusive). + * Checks whether a `DateTime` is between two other `DateTime` values (inclusive). + * + * **Example** (Checking whether a DateTime is within bounds) * - * @example * ```ts * import { DateTime } from "effect" * @@ -1618,11 +1977,14 @@ export const between: { } = Internal.between /** - * Checks if a `DateTime` is in the future compared to the current time. + * Checks effectfully if a `DateTime` is in the future compared to the current time. + * + * **Details** * * This is an effectful operation that uses the current time from the `Clock` service. * - * @example + * **Example** (Checking future DateTime values effectfully) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1639,11 +2001,19 @@ export const between: { export const isFuture: (self: DateTime) => Effect.Effect = Internal.isFuture /** - * Checks if a `DateTime` is in the future compared to the current time. + * Checks synchronously if a `DateTime` is in the future compared to the current time. + * + * **When to use** + * + * Use when checking whether a `DateTime` is in the future with a synchronous + * live-clock read and `Clock`-based testability is not needed. + * + * **Details** * * This is a synchronous version that uses `Date.now()` directly. * - * @example + * **Example** (Checking future DateTime values unsafely) + * * ```ts * import { DateTime } from "effect" * @@ -1655,16 +2025,19 @@ export const isFuture: (self: DateTime) => Effect.Effect = Internal.isF * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ export const isFutureUnsafe: (self: DateTime) => boolean = Internal.isFutureUnsafe /** - * Checks if a `DateTime` is in the past compared to the current time. + * Checks effectfully if a `DateTime` is in the past compared to the current time. + * + * **Details** * * This is an effectful operation that uses the current time from the `Clock` service. * - * @example + * **Example** (Checking past DateTime values effectfully) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -1681,11 +2054,19 @@ export const isFutureUnsafe: (self: DateTime) => boolean = Internal.isFutureUnsa export const isPast: (self: DateTime) => Effect.Effect = Internal.isPast /** - * Checks if a `DateTime` is in the past compared to the current time. + * Checks synchronously if a `DateTime` is in the past compared to the current time. + * + * **When to use** + * + * Use when checking whether a `DateTime` is in the past with a synchronous + * live-clock read and `Clock`-based testability is not needed. + * + * **Details** * * This is a synchronous version that uses `Date.now()` directly. * - * @example + * **Example** (Checking past DateTime values unsafely) + * * ```ts * import { DateTime } from "effect" * @@ -1697,7 +2078,7 @@ export const isPast: (self: DateTime) => Effect.Effect = Internal.isPas * ``` * * @category comparisons - * @since 3.6.0 + * @since 4.0.0 */ export const isPastUnsafe: (self: DateTime) => boolean = Internal.isPastUnsafe @@ -1706,11 +2087,14 @@ export const isPastUnsafe: (self: DateTime) => boolean = Internal.isPastUnsafe // ============================================================================= /** - * Get the UTC `Date` of a `DateTime`. + * Gets the UTC `Date` of a `DateTime`. + * + * **Details** * * This always returns the UTC representation, ignoring any time zone information. * - * @example + * **Example** (Converting DateTime values to UTC Dates) + * * ```ts * import { DateTime } from "effect" * @@ -1722,18 +2106,21 @@ export const isPastUnsafe: (self: DateTime) => boolean = Internal.isPastUnsafe * console.log(utcDate.toISOString()) // "2024-01-01T12:00:00.000Z" * ``` * - * @category conversions + * @category converting * @since 3.6.0 */ export const toDateUtc: (self: DateTime) => Date = Internal.toDateUtc /** - * Convert a `DateTime` to a `Date`, applying the time zone first. + * Converts a `DateTime` to a `Date`, applying the time zone first. + * + * **Details** * * For `DateTime.Zoned`, this adjusts for the time zone before converting. * For `DateTime.Utc`, this is equivalent to `toDateUtc`. * - * @example + * **Example** (Converting DateTime values to Dates) + * * ```ts * import { DateTime } from "effect" * @@ -1746,18 +2133,21 @@ export const toDateUtc: (self: DateTime) => Date = Internal.toDateUtc * console.log(DateTime.toDate(zoned).toISOString()) * ``` * - * @category conversions + * @category converting * @since 3.6.0 */ export const toDate: (self: DateTime) => Date = Internal.toDate /** - * Calculate the time zone offset of a `DateTime.Zoned` in milliseconds. + * Computes the time zone offset of a `DateTime.Zoned` in milliseconds. + * + * **Details** * * Returns the offset from UTC in milliseconds. Positive values indicate * time zones ahead of UTC, negative values indicate time zones behind UTC. * - * @example + * **Example** (Reading zoned offsets) + * * ```ts * import { DateTime } from "effect" * @@ -1769,17 +2159,20 @@ export const toDate: (self: DateTime) => Date = Internal.toDate * console.log(offset) // 0 (London is UTC+0 in winter) * ``` * - * @category conversions + * @category converting * @since 3.6.0 */ export const zonedOffset: (self: Zoned) => number = Internal.zonedOffset /** - * Format the time zone offset of a `DateTime.Zoned` as an ISO string. + * Formats the time zone offset of a `DateTime.Zoned` as an ISO string. + * + * **Details** * * The offset is formatted as "±HH:MM". * - * @example + * **Example** (Formatting zoned offsets) + * * ```ts * import { DateTime } from "effect" * @@ -1791,17 +2184,20 @@ export const zonedOffset: (self: Zoned) => number = Internal.zonedOffset * console.log(offsetString) // "+03:00" * ``` * - * @category conversions + * @category converting * @since 3.6.0 */ export const zonedOffsetIso: (self: Zoned) => string = Internal.zonedOffsetIso /** - * Get the milliseconds since the Unix epoch of a `DateTime`. + * Gets the milliseconds since the Unix epoch of a `DateTime`. + * + * **Details** * * This returns the UTC timestamp regardless of any time zone information. * - * @example + * **Example** (Reading epoch milliseconds) + * * ```ts * import { DateTime } from "effect" * @@ -1809,21 +2205,19 @@ export const zonedOffsetIso: (self: Zoned) => string = Internal.zonedOffsetIso * const epochMillis = DateTime.toEpochMillis(dt) * * console.log(epochMillis) // 1704067200000 - * console.log(new Date(epochMillis).toISOString()) // "2024-01-01T00:00:00.000Z" * ``` * - * @category conversions + * @category converting * @since 3.6.0 */ export const toEpochMillis: (self: DateTime) => number = Internal.toEpochMillis /** - * Remove the time aspect of a `DateTime`, first adjusting for the time + * Removes the time aspect of a `DateTime`, first adjusting for the time * zone. It will return a `DateTime.Utc` only containing the date. * - * @since 3.6.0 - * @category conversions - * @example + * **Example** (Removing time components) + * * ```ts * import { DateTime } from "effect" * @@ -1836,6 +2230,9 @@ export const toEpochMillis: (self: DateTime) => number = Internal.toEpochMillis * DateTime.formatIso * ) * ``` + * + * @category converting + * @since 3.6.0 */ export const removeTime: (self: DateTime) => Utc = Internal.removeTime @@ -1844,11 +2241,14 @@ export const removeTime: (self: DateTime) => Utc = Internal.removeTime // ============================================================================= /** - * Get the different parts of a `DateTime` as an object. + * Gets the time-zone-adjusted parts of a `DateTime` as an object. + * + * **Details** * * The parts will be time zone adjusted if the `DateTime` is zoned. * - * @example + * **Example** (Reading DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -1874,11 +2274,14 @@ export const removeTime: (self: DateTime) => Utc = Internal.removeTime export const toParts: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toParts /** - * Get the different parts of a `DateTime` as an object. + * Gets the UTC parts of a `DateTime` as an object. + * + * **Details** * * The parts will always be in UTC, ignoring any time zone information. * - * @example + * **Example** (Reading UTC DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -1897,129 +2300,150 @@ export const toParts: (self: DateTime) => DateTime.PartsWithWeekday = Internal.t export const toPartsUtc: (self: DateTime) => DateTime.PartsWithWeekday = Internal.toPartsUtc /** - * Get a part of a `DateTime` as a number. + * Gets one UTC part of a `DateTime` as a number. + * + * **Details** * * The part will be in the UTC time zone. * - * @since 3.6.0 - * @category parts - * @example + * **Example** (Reading UTC DateTime parts by key) + * * ```ts * import { DateTime } from "effect" - * import * as assert from "node:assert" * - * const now = DateTime.makeUnsafe({ year: 2024 }) - * const year = DateTime.getPartUtc(now, "year") - * assert.strictEqual(year, 2024) + * const dateTime = DateTime.makeUnsafe({ year: 2024 }) + * const year = DateTime.getPartUtc(dateTime, "year") + * console.log(year) // 2024 * ``` + * + * @category parts + * @since 3.6.0 */ export const getPartUtc: { /** - * Get a part of a `DateTime` as a number. + * Gets one UTC part of a `DateTime` as a number. + * + * **Details** * * The part will be in the UTC time zone. * - * @since 3.6.0 - * @category parts - * @example + * **Example** (Reading UTC DateTime parts by key) + * * ```ts * import { DateTime } from "effect" - * import * as assert from "node:assert" * - * const now = DateTime.makeUnsafe({ year: 2024 }) - * const year = DateTime.getPartUtc(now, "year") - * assert.strictEqual(year, 2024) + * const dateTime = DateTime.makeUnsafe({ year: 2024 }) + * const year = DateTime.getPartUtc(dateTime, "year") + * console.log(year) // 2024 * ``` + * + * @category parts + * @since 3.6.0 */ (part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number /** - * Get a part of a `DateTime` as a number. + * Gets one UTC part of a `DateTime` as a number. + * + * **Details** * * The part will be in the UTC time zone. * - * @since 3.6.0 - * @category parts - * @example + * **Example** (Reading UTC DateTime parts by key) + * * ```ts * import { DateTime } from "effect" - * import * as assert from "node:assert" * - * const now = DateTime.makeUnsafe({ year: 2024 }) - * const year = DateTime.getPartUtc(now, "year") - * assert.strictEqual(year, 2024) + * const dateTime = DateTime.makeUnsafe({ year: 2024 }) + * const year = DateTime.getPartUtc(dateTime, "year") + * console.log(year) // 2024 * ``` + * + * @category parts + * @since 3.6.0 */ (self: DateTime, part: keyof DateTime.PartsWithWeekday): number } = Internal.getPartUtc /** - * Get a part of a `DateTime` as a number. + * Gets one time-zone-adjusted part of a `DateTime` as a number. + * + * **Details** * * The part will be time zone adjusted. * - * @since 3.6.0 - * @category parts - * @example + * **Example** (Reading DateTime parts by key) + * * ```ts * import { DateTime } from "effect" - * import * as assert from "node:assert" * - * const now = DateTime.makeZonedUnsafe({ year: 2024 }, { + * const dateTime = DateTime.makeZonedUnsafe({ year: 2024 }, { * timeZone: "Europe/London" * }) - * const year = DateTime.getPart(now, "year") - * assert.strictEqual(year, 2024) + * const year = DateTime.getPart(dateTime, "year") + * console.log(year) // 2024 * ``` + * + * @category parts + * @since 3.6.0 */ export const getPart: { /** - * Get a part of a `DateTime` as a number. + * Gets one time-zone-adjusted part of a `DateTime` as a number. + * + * **Details** * * The part will be time zone adjusted. * - * @since 3.6.0 - * @category parts - * @example + * **Example** (Reading DateTime parts by key) + * * ```ts * import { DateTime } from "effect" - * import * as assert from "node:assert" * - * const now = DateTime.makeZonedUnsafe({ year: 2024 }, { + * const dateTime = DateTime.makeZonedUnsafe({ year: 2024 }, { * timeZone: "Europe/London" * }) - * const year = DateTime.getPart(now, "year") - * assert.strictEqual(year, 2024) + * const year = DateTime.getPart(dateTime, "year") + * console.log(year) // 2024 * ``` + * + * @category parts + * @since 3.6.0 */ (part: keyof DateTime.PartsWithWeekday): (self: DateTime) => number /** - * Get a part of a `DateTime` as a number. + * Gets one time-zone-adjusted part of a `DateTime` as a number. + * + * **Details** * * The part will be time zone adjusted. * - * @since 3.6.0 - * @category parts - * @example + * **Example** (Reading DateTime parts by key) + * * ```ts * import { DateTime } from "effect" - * import * as assert from "node:assert" * - * const now = DateTime.makeZonedUnsafe({ year: 2024 }, { + * const dateTime = DateTime.makeZonedUnsafe({ year: 2024 }, { * timeZone: "Europe/London" * }) - * const year = DateTime.getPart(now, "year") - * assert.strictEqual(year, 2024) + * const year = DateTime.getPart(dateTime, "year") + * console.log(year) // 2024 * ``` + * + * @category parts + * @since 3.6.0 */ (self: DateTime, part: keyof DateTime.PartsWithWeekday): number } = Internal.getPart /** - * Set the different parts of a `DateTime` as an object. + * Sets time-zone-adjusted parts on a `DateTime`. + * + * **Details** * * The date will be time zone adjusted for `DateTime.Zoned`. * - * @example + * **Example** (Updating DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -2038,11 +2462,14 @@ export const getPart: { */ export const setParts: { /** - * Set the different parts of a `DateTime` as an object. + * Sets time-zone-adjusted parts on a `DateTime`. + * + * **Details** * * The date will be time zone adjusted for `DateTime.Zoned`. * - * @example + * **Example** (Updating DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -2061,11 +2488,14 @@ export const setParts: { */ (parts: Partial): (self: A) => A /** - * Set the different parts of a `DateTime` as an object. + * Sets time-zone-adjusted parts on a `DateTime`. + * + * **Details** * * The date will be time zone adjusted for `DateTime.Zoned`. * - * @example + * **Example** (Updating DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -2086,11 +2516,14 @@ export const setParts: { } = Internal.setParts /** - * Set the different parts of a `DateTime` as an object. + * Sets UTC parts on a `DateTime`. + * + * **Details** * * The parts are always interpreted as UTC, ignoring any time zone information. * - * @example + * **Example** (Updating UTC DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -2108,11 +2541,14 @@ export const setParts: { */ export const setPartsUtc: { /** - * Set the different parts of a `DateTime` as an object. + * Sets UTC parts on a `DateTime`. + * + * **Details** * * The parts are always interpreted as UTC, ignoring any time zone information. * - * @example + * **Example** (Updating UTC DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -2130,11 +2566,14 @@ export const setPartsUtc: { */ (parts: Partial): (self: A) => A /** - * Set the different parts of a `DateTime` as an object. + * Sets UTC parts on a `DateTime`. + * + * **Details** * * The parts are always interpreted as UTC, ignoring any time zone information. * - * @example + * **Example** (Updating UTC DateTime parts) + * * ```ts * import { DateTime } from "effect" * @@ -2158,13 +2597,23 @@ export const setPartsUtc: { // ============================================================================= /** - * @example + * Context service that supplies the ambient `TimeZone` for APIs that work in + * the current zone, such as `DateTime.setZoneCurrent` and + * `DateTime.nowInCurrentZone`. + * + * **Details** + * + * Provide it with `DateTime.withCurrentZone`, one of the `withCurrentZone*` + * helpers, or one of the `layerCurrentZone*` layers. + * + * **Example** (Accessing the current time zone service) + * * ```ts * import { DateTime, Effect } from "effect" * * const program = Effect.gen(function*() { * // Access the current time zone service - * const zone = yield* DateTime.CurrentTimeZone.asEffect() + * const zone = yield* DateTime.CurrentTimeZone * console.log(DateTime.zoneToString(zone)) * }) * @@ -2173,20 +2622,19 @@ export const setPartsUtc: { * Effect.provide(program, layer) * ``` * - * @since 3.11.0 * @category current time zone + * @since 3.11.0 */ export class CurrentTimeZone extends Context.Service()( "effect/DateTime/CurrentTimeZone" ) {} /** - * Set the time zone of a `DateTime` to the current time zone, which is + * Sets the time zone of a `DateTime` to the current time zone, which is * determined by the `CurrentTimeZone` service. * - * @since 3.6.0 - * @category current time zone - * @example + * **Example** (Setting the current time zone) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -2197,16 +2645,18 @@ export class CurrentTimeZone extends Context.Service( * const zoned = yield* DateTime.setZoneCurrent(now) * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) * ``` + * + * @category current time zone + * @since 3.6.0 */ export const setZoneCurrent = (self: DateTime): Effect.Effect => - Effect.map(CurrentTimeZone.asEffect(), (zone) => setZone(self, zone)) + Effect.map(CurrentTimeZone, (zone) => setZone(self, zone)) /** - * Provide the `CurrentTimeZone` to an effect. + * Provides the `CurrentTimeZone` to an effect. + * + * **Example** (Providing the current time zone) * - * @since 3.6.0 - * @category current time zone - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -2216,14 +2666,16 @@ export const setZoneCurrent = (self: DateTime): Effect.Effect(self: Effect.Effect) => Effect.Effect> /** - * Provide the `CurrentTimeZone` to an effect. + * Provides the `CurrentTimeZone` to an effect. + * + * **Example** (Providing the current time zone) * - * @since 3.6.0 - * @category current time zone - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -2250,17 +2704,19 @@ export const withCurrentZone: { * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZone(zone)) * ``` + * + * @category current time zone + * @since 3.6.0 */ (self: Effect.Effect, value: TimeZone): Effect.Effect> } = provideService(CurrentTimeZone) /** - * Provide the `CurrentTimeZone` to an effect, using the system's local time + * Provides the `CurrentTimeZone` to an effect, using the system's local time * zone. * - * @since 3.6.0 - * @category current time zone - * @example + * **Example** (Providing the local time zone) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -2269,6 +2725,9 @@ export const withCurrentZone: { * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneLocal) * ``` + * + * @category current time zone + * @since 3.6.0 */ export const withCurrentZoneLocal = ( effect: Effect.Effect @@ -2276,53 +2735,59 @@ export const withCurrentZoneLocal = ( Effect.provideServiceEffect(effect, CurrentTimeZone, Effect.sync(zoneMakeLocal)) /** - * Provide the `CurrentTimeZone` to an effect, using a offset. + * Provides the `CurrentTimeZone` to an effect, using an offset. + * + * **Example** (Providing a fixed-offset time zone) * - * @since 3.6.0 - * @category current time zone - * @example * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function*() { - * // will use the system's local time zone - * const now = yield* DateTime.nowInCurrentZone + * const zone = yield* DateTime.CurrentTimeZone + * console.log(DateTime.zoneToString(zone)) // "+03:00" * }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000)) * ``` + * + * @category current time zone + * @since 3.6.0 */ export const withCurrentZoneOffset: { /** - * Provide the `CurrentTimeZone` to an effect, using a offset. + * Provides the `CurrentTimeZone` to an effect, using an offset. + * + * **Example** (Providing a fixed-offset time zone) * - * @since 3.6.0 - * @category current time zone - * @example * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function*() { - * // will use the system's local time zone - * const now = yield* DateTime.nowInCurrentZone + * const zone = yield* DateTime.CurrentTimeZone + * console.log(DateTime.zoneToString(zone)) // "+03:00" * }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000)) * ``` + * + * @category current time zone + * @since 3.6.0 */ (offset: number): ( effect: Effect.Effect ) => Effect.Effect> /** - * Provide the `CurrentTimeZone` to an effect, using a offset. + * Provides the `CurrentTimeZone` to an effect, using an offset. + * + * **Example** (Providing a fixed-offset time zone) * - * @since 3.6.0 - * @category current time zone - * @example * ```ts * import { DateTime, Effect } from "effect" * * Effect.gen(function*() { - * // will use the system's local time zone - * const now = yield* DateTime.nowInCurrentZone + * const zone = yield* DateTime.CurrentTimeZone + * console.log(DateTime.zoneToString(zone)) // "+03:00" * }).pipe(DateTime.withCurrentZoneOffset(3 * 60 * 60 * 1000)) * ``` + * + * @category current time zone + * @since 3.6.0 */ (effect: Effect.Effect, offset: number): Effect.Effect> } = dual( @@ -2332,14 +2797,15 @@ export const withCurrentZoneOffset: { ) /** - * Provide the `CurrentTimeZone` to an effect using an IANA time zone + * Provides the `CurrentTimeZone` to an effect using an IANA time zone * identifier. * + * **Details** + * * If the time zone is invalid, it will fail with an `IllegalArgumentError`. * - * @since 3.6.0 - * @category current time zone - * @example + * **Example** (Providing a named time zone) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -2348,17 +2814,21 @@ export const withCurrentZoneOffset: { * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) * ``` + * + * @category current time zone + * @since 3.6.0 */ export const withCurrentZoneNamed: { /** - * Provide the `CurrentTimeZone` to an effect using an IANA time zone + * Provides the `CurrentTimeZone` to an effect using an IANA time zone * identifier. * + * **Details** + * * If the time zone is invalid, it will fail with an `IllegalArgumentError`. * - * @since 3.6.0 - * @category current time zone - * @example + * **Example** (Providing a named time zone) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -2367,19 +2837,23 @@ export const withCurrentZoneNamed: { * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) * ``` + * + * @category current time zone + * @since 3.6.0 */ (zone: string): ( effect: Effect.Effect ) => Effect.Effect> /** - * Provide the `CurrentTimeZone` to an effect using an IANA time zone + * Provides the `CurrentTimeZone` to an effect using an IANA time zone * identifier. * + * **Details** + * * If the time zone is invalid, it will fail with an `IllegalArgumentError`. * - * @since 3.6.0 - * @category current time zone - * @example + * **Example** (Providing a named time zone) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -2388,6 +2862,9 @@ export const withCurrentZoneNamed: { * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) * ``` + * + * @category current time zone + * @since 3.6.0 */ (effect: Effect.Effect, zone: string): Effect.Effect> } = dual( @@ -2400,11 +2877,10 @@ export const withCurrentZoneNamed: { ) /** - * Get the current time as a `DateTime.Zoned`, using the `CurrentTimeZone`. + * Gets the current time as a `DateTime.Zoned`, using the `CurrentTimeZone`. + * + * **Example** (Getting the current time in the current zone) * - * @since 3.6.0 - * @category current time zone - * @example * ```ts * import { DateTime, Effect } from "effect" * @@ -2413,6 +2889,9 @@ export const withCurrentZoneNamed: { * const now = yield* DateTime.nowInCurrentZone * }).pipe(DateTime.withCurrentZoneNamed("Europe/London")) * ``` + * + * @category current time zone + * @since 3.6.0 */ export const nowInCurrentZone: Effect.Effect = Effect.flatMap(now, setZoneCurrent) @@ -2421,14 +2900,22 @@ export const nowInCurrentZone: Effect.Effect = Ef // ============================================================================= /** - * Modify a `DateTime` by applying a function to a cloned `Date` instance. + * Modifies a `DateTime` with a mutable local `Date` copy. + * + * **When to use** + * + * Use to adjust calendar fields in the `DateTime`'s own time zone with an + * existing `Date` mutation API. + * + * **Details** * * The `Date` will first have the time zone applied if possible, and then be * converted back to a `DateTime` within the same time zone. * * Supports `disambiguation` when the new wall clock time is ambiguous. * - * @example + * **Example** (Mutating DateTime values with Dates) + * * ```ts * import { DateTime } from "effect" * @@ -2442,8 +2929,8 @@ export const nowInCurrentZone: Effect.Effect = Ef * console.log(DateTime.formatIso(modified)) // "2024-01-01T15:30:00.000Z" * ``` * - * @since 3.6.0 * @category mapping + * @since 3.6.0 */ export const mutate: { // ============================================================================= @@ -2451,14 +2938,22 @@ export const mutate: { // ============================================================================= /** - * Modify a `DateTime` by applying a function to a cloned `Date` instance. + * Modifies a `DateTime` with a mutable local `Date` copy. + * + * **When to use** + * + * Use to adjust calendar fields in the `DateTime`'s own time zone with an + * existing `Date` mutation API. + * + * **Details** * * The `Date` will first have the time zone applied if possible, and then be * converted back to a `DateTime` within the same time zone. * * Supports `disambiguation` when the new wall clock time is ambiguous. * - * @example + * **Example** (Mutating DateTime values with Dates) + * * ```ts * import { DateTime } from "effect" * @@ -2472,8 +2967,8 @@ export const mutate: { * console.log(DateTime.formatIso(modified)) // "2024-01-01T15:30:00.000Z" * ``` * - * @since 3.6.0 * @category mapping + * @since 3.6.0 */ ( f: (date: Date) => void, @@ -2486,14 +2981,22 @@ export const mutate: { // ============================================================================= /** - * Modify a `DateTime` by applying a function to a cloned `Date` instance. + * Modifies a `DateTime` with a mutable local `Date` copy. + * + * **When to use** + * + * Use to adjust calendar fields in the `DateTime`'s own time zone with an + * existing `Date` mutation API. + * + * **Details** * * The `Date` will first have the time zone applied if possible, and then be * converted back to a `DateTime` within the same time zone. * * Supports `disambiguation` when the new wall clock time is ambiguous. * - * @example + * **Example** (Mutating DateTime values with Dates) + * * ```ts * import { DateTime } from "effect" * @@ -2507,8 +3010,8 @@ export const mutate: { * console.log(DateTime.formatIso(modified)) // "2024-01-01T15:30:00.000Z" * ``` * - * @since 3.6.0 * @category mapping + * @since 3.6.0 */ ( self: A, @@ -2520,9 +3023,15 @@ export const mutate: { } = Internal.mutate /** - * Modify a `DateTime` by applying a function to a cloned UTC `Date` instance. + * Modifies a `DateTime` with a mutable UTC `Date` copy. + * + * **When to use** + * + * Use to adjust the instant with an existing `Date` mutation API that works on + * UTC calendar fields. + * + * **Example** (Mutating DateTime values with UTC Dates) * - * @example * ```ts * import { DateTime } from "effect" * @@ -2537,14 +3046,20 @@ export const mutate: { * console.log(DateTime.formatIso(modified)) // "2024-01-01T18:00:00.000Z" * ``` * - * @since 3.6.0 * @category mapping + * @since 3.6.0 */ export const mutateUtc: { /** - * Modify a `DateTime` by applying a function to a cloned UTC `Date` instance. + * Modifies a `DateTime` with a mutable UTC `Date` copy. + * + * **When to use** + * + * Use to adjust the instant with an existing `Date` mutation API that works on + * UTC calendar fields. + * + * **Example** (Mutating DateTime values with UTC Dates) * - * @example * ```ts * import { DateTime } from "effect" * @@ -2559,14 +3074,20 @@ export const mutateUtc: { * console.log(DateTime.formatIso(modified)) // "2024-01-01T18:00:00.000Z" * ``` * - * @since 3.6.0 * @category mapping + * @since 3.6.0 */ (f: (date: Date) => void): (self: A) => A /** - * Modify a `DateTime` by applying a function to a cloned UTC `Date` instance. + * Modifies a `DateTime` with a mutable UTC `Date` copy. + * + * **When to use** + * + * Use to adjust the instant with an existing `Date` mutation API that works on + * UTC calendar fields. + * + * **Example** (Mutating DateTime values with UTC Dates) * - * @example * ```ts * import { DateTime } from "effect" * @@ -2581,19 +3102,18 @@ export const mutateUtc: { * console.log(DateTime.formatIso(modified)) // "2024-01-01T18:00:00.000Z" * ``` * - * @since 3.6.0 * @category mapping + * @since 3.6.0 */ (self: A, f: (date: Date) => void): A } = Internal.mutateUtc /** - * Transform a `DateTime` by applying a function to the number of milliseconds + * Transforms a `DateTime` by applying a function to the number of milliseconds * since the Unix epoch. * - * @since 3.6.0 - * @category mapping - * @example + * **Example** (Mapping epoch milliseconds) + * * ```ts * import { DateTime } from "effect" * @@ -2602,15 +3122,17 @@ export const mutateUtc: { * DateTime.mapEpochMillis((millis) => millis + 10) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ export const mapEpochMillis: { /** - * Transform a `DateTime` by applying a function to the number of milliseconds + * Transforms a `DateTime` by applying a function to the number of milliseconds * since the Unix epoch. * - * @since 3.6.0 - * @category mapping - * @example + * **Example** (Mapping epoch milliseconds) + * * ```ts * import { DateTime } from "effect" * @@ -2619,15 +3141,17 @@ export const mapEpochMillis: { * DateTime.mapEpochMillis((millis) => millis + 10) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ (f: (millis: number) => number): (self: A) => A /** - * Transform a `DateTime` by applying a function to the number of milliseconds + * Transforms a `DateTime` by applying a function to the number of milliseconds * since the Unix epoch. * - * @since 3.6.0 - * @category mapping - * @example + * **Example** (Mapping epoch milliseconds) + * * ```ts * import { DateTime } from "effect" * @@ -2636,17 +3160,25 @@ export const mapEpochMillis: { * DateTime.mapEpochMillis((millis) => millis + 10) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ (self: A, f: (millis: number) => number): A } = Internal.mapEpochMillis /** - * Using the time zone adjusted `Date`, apply a function to the `Date` and - * return the result. + * Applies a function to a JavaScript `Date` representing the `DateTime` and + * returns the function's result. + * + * **Details** + * + * The callback receives the time-zone-adjusted wall-clock date for + * `DateTime.Zoned` values. Use `DateTime.withDateUtc` when the callback should + * receive the UTC instant. + * + * **Example** (Using time zone adjusted Dates) * - * @since 3.6.0 - * @category mapping - * @example * ```ts * import { DateTime } from "effect" * @@ -2655,15 +3187,23 @@ export const mapEpochMillis: { * DateTime.withDate((date) => date.getTime()) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ export const withDate: { /** - * Using the time zone adjusted `Date`, apply a function to the `Date` and - * return the result. + * Applies a function to a JavaScript `Date` representing the `DateTime` and + * returns the function's result. + * + * **Details** + * + * The callback receives the time-zone-adjusted wall-clock date for + * `DateTime.Zoned` values. Use `DateTime.withDateUtc` when the callback should + * receive the UTC instant. + * + * **Example** (Using time zone adjusted Dates) * - * @since 3.6.0 - * @category mapping - * @example * ```ts * import { DateTime } from "effect" * @@ -2672,15 +3212,23 @@ export const withDate: { * DateTime.withDate((date) => date.getTime()) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ (f: (date: Date) => A): (self: DateTime) => A /** - * Using the time zone adjusted `Date`, apply a function to the `Date` and - * return the result. + * Applies a function to a JavaScript `Date` representing the `DateTime` and + * returns the function's result. + * + * **Details** + * + * The callback receives the time-zone-adjusted wall-clock date for + * `DateTime.Zoned` values. Use `DateTime.withDateUtc` when the callback should + * receive the UTC instant. + * + * **Example** (Using time zone adjusted Dates) * - * @since 3.6.0 - * @category mapping - * @example * ```ts * import { DateTime } from "effect" * @@ -2689,17 +3237,24 @@ export const withDate: { * DateTime.withDate((date) => date.getTime()) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ (self: DateTime, f: (date: Date) => A): A } = Internal.withDate /** - * Using the time zone adjusted `Date`, apply a function to the `Date` and - * return the result. + * Applies a function to a JavaScript `Date` representing the `DateTime`'s UTC + * instant and returns the function's result. + * + * **Details** + * + * This ignores any associated time zone. Use `DateTime.withDate` when the + * callback should receive the time-zone-adjusted wall-clock date. + * + * **Example** (Using UTC Dates) * - * @since 3.6.0 - * @category mapping - * @example * ```ts * import { DateTime } from "effect" * @@ -2708,15 +3263,22 @@ export const withDate: { * DateTime.withDateUtc((date) => date.getTime()) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ export const withDateUtc: { /** - * Using the time zone adjusted `Date`, apply a function to the `Date` and - * return the result. + * Applies a function to a JavaScript `Date` representing the `DateTime`'s UTC + * instant and returns the function's result. + * + * **Details** + * + * This ignores any associated time zone. Use `DateTime.withDate` when the + * callback should receive the time-zone-adjusted wall-clock date. + * + * **Example** (Using UTC Dates) * - * @since 3.6.0 - * @category mapping - * @example * ```ts * import { DateTime } from "effect" * @@ -2725,15 +3287,22 @@ export const withDateUtc: { * DateTime.withDateUtc((date) => date.getTime()) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ (f: (date: Date) => A): (self: DateTime) => A /** - * Using the time zone adjusted `Date`, apply a function to the `Date` and - * return the result. + * Applies a function to a JavaScript `Date` representing the `DateTime`'s UTC + * instant and returns the function's result. + * + * **Details** + * + * This ignores any associated time zone. Use `DateTime.withDate` when the + * callback should receive the time-zone-adjusted wall-clock date. + * + * **Example** (Using UTC Dates) * - * @since 3.6.0 - * @category mapping - * @example * ```ts * import { DateTime } from "effect" * @@ -2742,6 +3311,9 @@ export const withDateUtc: { * DateTime.withDateUtc((date) => date.getTime()) * ) * ``` + * + * @category mapping + * @since 3.6.0 */ (self: DateTime, f: (date: Date) => A): A } = Internal.withDateUtc @@ -2749,12 +3321,15 @@ export const withDateUtc: { /** * Pattern match on a `DateTime` to handle `Utc` and `Zoned` cases differently. * - * @example + * **Example** (Pattern matching DateTime variants) + * * ```ts * import { DateTime } from "effect" * - * const dt1 = DateTime.nowUnsafe() // Utc - * const dt2 = DateTime.makeZonedUnsafe(new Date(), { timeZone: "Europe/London" }) // Zoned + * const dt1 = DateTime.makeUnsafe("2024-01-01T12:00:00Z") // Utc + * const dt2 = DateTime.makeZonedUnsafe("2024-06-15T14:30:00Z", { + * timeZone: "Europe/London" + * }) // Zoned * * const result1 = DateTime.match(dt1, { * onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`, @@ -2765,6 +3340,9 @@ export const withDateUtc: { * onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`, * onZoned: (zoned) => `Zoned: ${DateTime.formatIsoZoned(zoned)}` * }) + * + * console.log(result1) // "UTC: 2024-01-01T12:00:00.000Z" + * console.log(result2) // "Zoned: 2024-06-15T15:30:00.000+01:00[Europe/London]" * ``` * * @category mapping @@ -2774,12 +3352,15 @@ export const match: { /** * Pattern match on a `DateTime` to handle `Utc` and `Zoned` cases differently. * - * @example + * **Example** (Pattern matching DateTime variants) + * * ```ts * import { DateTime } from "effect" * - * const dt1 = DateTime.nowUnsafe() // Utc - * const dt2 = DateTime.makeZonedUnsafe(new Date(), { timeZone: "Europe/London" }) // Zoned + * const dt1 = DateTime.makeUnsafe("2024-01-01T12:00:00Z") // Utc + * const dt2 = DateTime.makeZonedUnsafe("2024-06-15T14:30:00Z", { + * timeZone: "Europe/London" + * }) // Zoned * * const result1 = DateTime.match(dt1, { * onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`, @@ -2790,6 +3371,9 @@ export const match: { * onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`, * onZoned: (zoned) => `Zoned: ${DateTime.formatIsoZoned(zoned)}` * }) + * + * console.log(result1) // "UTC: 2024-01-01T12:00:00.000Z" + * console.log(result2) // "Zoned: 2024-06-15T15:30:00.000+01:00[Europe/London]" * ``` * * @category mapping @@ -2804,12 +3388,15 @@ export const match: { /** * Pattern match on a `DateTime` to handle `Utc` and `Zoned` cases differently. * - * @example + * **Example** (Pattern matching DateTime variants) + * * ```ts * import { DateTime } from "effect" * - * const dt1 = DateTime.nowUnsafe() // Utc - * const dt2 = DateTime.makeZonedUnsafe(new Date(), { timeZone: "Europe/London" }) // Zoned + * const dt1 = DateTime.makeUnsafe("2024-01-01T12:00:00Z") // Utc + * const dt2 = DateTime.makeZonedUnsafe("2024-06-15T14:30:00Z", { + * timeZone: "Europe/London" + * }) // Zoned * * const result1 = DateTime.match(dt1, { * onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`, @@ -2820,6 +3407,9 @@ export const match: { * onUtc: (utc) => `UTC: ${DateTime.formatIso(utc)}`, * onZoned: (zoned) => `Zoned: ${DateTime.formatIsoZoned(zoned)}` * }) + * + * console.log(result1) // "UTC: 2024-01-01T12:00:00.000Z" + * console.log(result2) // "Zoned: 2024-06-15T15:30:00.000+01:00[Europe/London]" * ``` * * @category mapping @@ -2839,11 +3429,26 @@ export const match: { // ============================================================================= /** - * Add the given `Duration` to a `DateTime`. + * Adds the given `Duration` to a `DateTime`. + * + * **When to use** + * + * Use to move a `DateTime` by an elapsed duration such as minutes, seconds, or + * milliseconds. + * + * **Details** + * + * The duration is converted to milliseconds and added to the epoch + * milliseconds. Zoned values keep their original time zone. + * + * **Gotchas** + * + * This is elapsed-time arithmetic, not calendar-aware local date arithmetic. + * Use `add` when adding days, weeks, months, or years should account for the + * date/time zone rules. + * + * **Example** (Adding durations) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -2852,6 +3457,12 @@ export const match: { * DateTime.addDuration("5 minutes") * ) * ``` + * + * @see {@link add} for calendar-aware date/time part arithmetic + * @see {@link subtractDuration} for subtracting an elapsed duration + * + * @category math + * @since 3.6.0 */ export const addDuration: { // ============================================================================= @@ -2859,11 +3470,26 @@ export const addDuration: { // ============================================================================= /** - * Add the given `Duration` to a `DateTime`. + * Adds the given `Duration` to a `DateTime`. + * + * **When to use** + * + * Use to move a `DateTime` by an elapsed duration such as minutes, seconds, or + * milliseconds. + * + * **Details** + * + * The duration is converted to milliseconds and added to the epoch + * milliseconds. Zoned values keep their original time zone. + * + * **Gotchas** + * + * This is elapsed-time arithmetic, not calendar-aware local date arithmetic. + * Use `add` when adding days, weeks, months, or years should account for the + * date/time zone rules. + * + * **Example** (Adding durations) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -2872,6 +3498,12 @@ export const addDuration: { * DateTime.addDuration("5 minutes") * ) * ``` + * + * @see {@link add} for calendar-aware date/time part arithmetic + * @see {@link subtractDuration} for subtracting an elapsed duration + * + * @category math + * @since 3.6.0 */ (duration: Duration.Input): (self: A) => A // ============================================================================= @@ -2879,11 +3511,26 @@ export const addDuration: { // ============================================================================= /** - * Add the given `Duration` to a `DateTime`. + * Adds the given `Duration` to a `DateTime`. + * + * **When to use** + * + * Use to move a `DateTime` by an elapsed duration such as minutes, seconds, or + * milliseconds. + * + * **Details** + * + * The duration is converted to milliseconds and added to the epoch + * milliseconds. Zoned values keep their original time zone. + * + * **Gotchas** + * + * This is elapsed-time arithmetic, not calendar-aware local date arithmetic. + * Use `add` when adding days, weeks, months, or years should account for the + * date/time zone rules. + * + * **Example** (Adding durations) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -2892,16 +3539,21 @@ export const addDuration: { * DateTime.addDuration("5 minutes") * ) * ``` + * + * @see {@link add} for calendar-aware date/time part arithmetic + * @see {@link subtractDuration} for subtracting an elapsed duration + * + * @category math + * @since 3.6.0 */ (self: A, duration: Duration.Input): A } = Internal.addDuration /** - * Subtract the given `Duration` from a `DateTime`. + * Subtracts the given `Duration` from a `DateTime`. + * + * **Example** (Subtracting durations) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -2910,14 +3562,16 @@ export const addDuration: { * DateTime.subtractDuration("5 minutes") * ) * ``` + * + * @category math + * @since 3.6.0 */ export const subtractDuration: { /** - * Subtract the given `Duration` from a `DateTime`. + * Subtracts the given `Duration` from a `DateTime`. + * + * **Example** (Subtracting durations) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -2926,14 +3580,16 @@ export const subtractDuration: { * DateTime.subtractDuration("5 minutes") * ) * ``` + * + * @category math + * @since 3.6.0 */ (duration: Duration.Input): (self: A) => A /** - * Subtract the given `Duration` from a `DateTime`. + * Subtracts the given `Duration` from a `DateTime`. + * + * **Example** (Subtracting durations) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -2942,19 +3598,23 @@ export const subtractDuration: { * DateTime.subtractDuration("5 minutes") * ) * ``` + * + * @category math + * @since 3.6.0 */ (self: A, duration: Duration.Input): A } = Internal.subtractDuration /** - * Add the given `amount` of `unit`'s to a `DateTime`. + * Adds the given `amount` of `unit` to a `DateTime`. + * + * **Details** * * The time zone is taken into account when adding days, weeks, months, and * years. * - * @since 3.6.0 - * @category math - * @example + * **Example** (Adding date and time parts) + * * ```ts * import { DateTime } from "effect" * @@ -2963,17 +3623,21 @@ export const subtractDuration: { * DateTime.add({ minutes: 5 }) * ) * ``` + * + * @category math + * @since 3.6.0 */ export const add: { /** - * Add the given `amount` of `unit`'s to a `DateTime`. + * Adds the given `amount` of `unit` to a `DateTime`. + * + * **Details** * * The time zone is taken into account when adding days, weeks, months, and * years. * - * @since 3.6.0 - * @category math - * @example + * **Example** (Adding date and time parts) + * * ```ts * import { DateTime } from "effect" * @@ -2982,17 +3646,21 @@ export const add: { * DateTime.add({ minutes: 5 }) * ) * ``` + * + * @category math + * @since 3.6.0 */ (parts: Partial): (self: A) => A /** - * Add the given `amount` of `unit`'s to a `DateTime`. + * Adds the given `amount` of `unit` to a `DateTime`. + * + * **Details** * * The time zone is taken into account when adding days, weeks, months, and * years. * - * @since 3.6.0 - * @category math - * @example + * **Example** (Adding date and time parts) + * * ```ts * import { DateTime } from "effect" * @@ -3001,16 +3669,18 @@ export const add: { * DateTime.add({ minutes: 5 }) * ) * ``` + * + * @category math + * @since 3.6.0 */ (self: A, parts: Partial): A } = Internal.add /** - * Subtract the given `amount` of `unit`'s from a `DateTime`. + * Subtracts the given `amount` of `unit` from a `DateTime`. + * + * **Example** (Subtracting date and time parts) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -3019,14 +3689,16 @@ export const add: { * DateTime.subtract({ minutes: 5 }) * ) * ``` + * + * @category math + * @since 3.6.0 */ export const subtract: { /** - * Subtract the given `amount` of `unit`'s from a `DateTime`. + * Subtracts the given `amount` of `unit` from a `DateTime`. + * + * **Example** (Subtracting date and time parts) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -3035,14 +3707,16 @@ export const subtract: { * DateTime.subtract({ minutes: 5 }) * ) * ``` + * + * @category math + * @since 3.6.0 */ (parts: Partial): (self: A) => A /** - * Subtract the given `amount` of `unit`'s from a `DateTime`. + * Subtracts the given `amount` of `unit` from a `DateTime`. + * + * **Example** (Subtracting date and time parts) * - * @since 3.6.0 - * @category math - * @example * ```ts * import { DateTime } from "effect" * @@ -3051,6 +3725,9 @@ export const subtract: { * DateTime.subtract({ minutes: 5 }) * ) * ``` + * + * @category math + * @since 3.6.0 */ (self: A, parts: Partial): A } = Internal.subtract @@ -3058,12 +3735,13 @@ export const subtract: { /** * Converts a `DateTime` to the start of the given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding down DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3073,17 +3751,21 @@ export const subtract: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ export const startOf: { /** * Converts a `DateTime` to the start of the given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding down DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3093,6 +3775,9 @@ export const startOf: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ ( part: DateTime.UnitSingular, @@ -3101,12 +3786,13 @@ export const startOf: { /** * Converts a `DateTime` to the start of the given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding down DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3116,6 +3802,9 @@ export const startOf: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ ( self: A, @@ -3127,12 +3816,13 @@ export const startOf: { /** * Converts a `DateTime` to the end of the given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding up DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3142,17 +3832,21 @@ export const startOf: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ export const endOf: { /** * Converts a `DateTime` to the end of the given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding up DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3162,6 +3856,9 @@ export const endOf: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ ( part: DateTime.UnitSingular, @@ -3170,12 +3867,13 @@ export const endOf: { /** * Converts a `DateTime` to the end of the given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding up DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3185,6 +3883,9 @@ export const endOf: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ ( self: A, @@ -3196,12 +3897,13 @@ export const endOf: { /** * Converts a `DateTime` to the nearest given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding DateTime values to nearest units) + * * ```ts * import { DateTime } from "effect" * @@ -3211,17 +3913,21 @@ export const endOf: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ export const nearest: { /** * Converts a `DateTime` to the nearest given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding DateTime values to nearest units) + * * ```ts * import { DateTime } from "effect" * @@ -3231,6 +3937,9 @@ export const nearest: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ ( part: DateTime.UnitSingular, @@ -3239,12 +3948,13 @@ export const nearest: { /** * Converts a `DateTime` to the nearest given `part`. * + * **Details** + * * If the part is `week`, the `weekStartsOn` option can be used to specify the * day of the week that the week starts on. The default is 0 (Sunday). * - * @since 3.6.0 - * @category math - * @example + * **Example** (Rounding DateTime values to nearest units) + * * ```ts * import { DateTime } from "effect" * @@ -3254,6 +3964,9 @@ export const nearest: { * DateTime.formatIso * ) * ``` + * + * @category math + * @since 3.6.0 */ ( self: A, @@ -3267,14 +3980,19 @@ export const nearest: { // ============================================================================= /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat`. + * + * **Details** + * + * Unless a `timeZone` option is supplied, UTC values are formatted in UTC and + * zoned values are formatted in their named zone or fixed-offset zone. * - * The `timeZone` option is set to the offset of the time zone. + * Fixed-offset zones depend on runtime support for offset `timeZone` + * identifiers. When unsupported, formatting falls back to UTC with the + * `DateTime` adjusted to the offset. * - * Note: On Node versions < 22, fixed "Offset" zones will set the time zone to - * "UTC" and use the adjusted `Date`. + * **Example** (Formatting DateTime values with Intl options) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3291,8 +4009,8 @@ export const nearest: { * console.log(formatted) // "Saturday, June 15, 2024 at 3:30 PM" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ export const format: { // ============================================================================= @@ -3300,14 +4018,19 @@ export const format: { // ============================================================================= /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat`. + * + * **Details** + * + * Unless a `timeZone` option is supplied, UTC values are formatted in UTC and + * zoned values are formatted in their named zone or fixed-offset zone. * - * The `timeZone` option is set to the offset of the time zone. + * Fixed-offset zones depend on runtime support for offset `timeZone` + * identifiers. When unsupported, formatting falls back to UTC with the + * `DateTime` adjusted to the offset. * - * Note: On Node versions < 22, fixed "Offset" zones will set the time zone to - * "UTC" and use the adjusted `Date`. + * **Example** (Formatting DateTime values with Intl options) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3324,8 +4047,8 @@ export const format: { * console.log(formatted) // "Saturday, June 15, 2024 at 3:30 PM" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ ( options?: @@ -3339,14 +4062,19 @@ export const format: { // ============================================================================= /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat`. + * + * **Details** + * + * Unless a `timeZone` option is supplied, UTC values are formatted in UTC and + * zoned values are formatted in their named zone or fixed-offset zone. * - * The `timeZone` option is set to the offset of the time zone. + * Fixed-offset zones depend on runtime support for offset `timeZone` + * identifiers. When unsupported, formatting falls back to UTC with the + * `DateTime` adjusted to the offset. * - * Note: On Node versions < 22, fixed "Offset" zones will set the time zone to - * "UTC" and use the adjusted `Date`. + * **Example** (Formatting DateTime values with Intl options) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3363,8 +4091,8 @@ export const format: { * console.log(formatted) // "Saturday, June 15, 2024 at 3:30 PM" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ ( self: DateTime, @@ -3377,11 +4105,11 @@ export const format: { } = Internal.format /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat` using the system local time + * zone and locale. * - * It will use the system's local time zone & locale. + * **Example** (Formatting DateTime values locally) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3399,16 +4127,16 @@ export const format: { * console.log(local) // Output depends on system locale/timezone * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ export const formatLocal: { /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat` using the system local time + * zone and locale. * - * It will use the system's local time zone & locale. + * **Example** (Formatting DateTime values locally) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3426,8 +4154,8 @@ export const formatLocal: { * console.log(local) // Output depends on system locale/timezone * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ ( options?: @@ -3437,11 +4165,11 @@ export const formatLocal: { | undefined ): (self: DateTime) => string /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat` using the system local time + * zone and locale. * - * It will use the system's local time zone & locale. + * **Example** (Formatting DateTime values locally) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3459,8 +4187,8 @@ export const formatLocal: { * console.log(local) // Output depends on system locale/timezone * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ ( self: DateTime, @@ -3473,11 +4201,14 @@ export const formatLocal: { } = Internal.formatLocal /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat` using the UTC time zone. + * + * **Details** * * This forces the time zone to be UTC. * - * @example + * **Example** (Formatting DateTime values in UTC) + * * ```ts * import { DateTime } from "effect" * @@ -3498,16 +4229,19 @@ export const formatLocal: { * console.log(utcFormatted) // "06/15/2024, 02:30 PM UTC" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ export const formatUtc: { /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat` using the UTC time zone. + * + * **Details** * * This forces the time zone to be UTC. * - * @example + * **Example** (Formatting DateTime values in UTC) + * * ```ts * import { DateTime } from "effect" * @@ -3528,8 +4262,8 @@ export const formatUtc: { * console.log(utcFormatted) // "06/15/2024, 02:30 PM UTC" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ ( options?: @@ -3539,11 +4273,14 @@ export const formatUtc: { | undefined ): (self: DateTime) => string /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` with `Intl.DateTimeFormat` using the UTC time zone. + * + * **Details** * * This forces the time zone to be UTC. * - * @example + * **Example** (Formatting DateTime values in UTC) + * * ```ts * import { DateTime } from "effect" * @@ -3564,8 +4301,8 @@ export const formatUtc: { * console.log(utcFormatted) // "06/15/2024, 02:30 PM UTC" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ ( self: DateTime, @@ -3578,9 +4315,20 @@ export const formatUtc: { } = Internal.formatUtc /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` as a string using the `Intl.DateTimeFormat` API. + * + * **When to use** + * + * Use when you already have an `Intl.DateTimeFormat` and want it to control the + * locale, time zone, and formatting options. + * + * **Details** + * + * The formatter receives the `DateTime` epoch milliseconds. Any time zone + * conversion comes from the supplied formatter. + * + * **Example** (Formatting DateTime values with custom formatters) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3597,17 +4345,31 @@ export const formatUtc: { * }) * * const formatted = DateTime.formatIntl(dt, formatter) - * console.log(formatted) // "15. Juni 2024, 16:30" + * console.log(formatted.length > 0) // true * ``` * - * @since 3.6.0 + * @see {@link formatUtc} for formatting with options forced to UTC + * @see {@link formatIso} for stable ISO formatting + * * @category formatting + * @since 3.6.0 */ export const formatIntl: { /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` as a string using the `Intl.DateTimeFormat` API. + * + * **When to use** + * + * Use when you already have an `Intl.DateTimeFormat` and want it to control the + * locale, time zone, and formatting options. + * + * **Details** + * + * The formatter receives the `DateTime` epoch milliseconds. Any time zone + * conversion comes from the supplied formatter. + * + * **Example** (Formatting DateTime values with custom formatters) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3624,17 +4386,31 @@ export const formatIntl: { * }) * * const formatted = DateTime.formatIntl(dt, formatter) - * console.log(formatted) // "15. Juni 2024, 16:30" + * console.log(formatted.length > 0) // true * ``` * - * @since 3.6.0 + * @see {@link formatUtc} for formatting with options forced to UTC + * @see {@link formatIso} for stable ISO formatting + * * @category formatting + * @since 3.6.0 */ (format: Intl.DateTimeFormat): (self: DateTime) => string /** - * Format a `DateTime` as a string using the `DateTimeFormat` API. + * Formats a `DateTime` as a string using the `Intl.DateTimeFormat` API. + * + * **When to use** + * + * Use when you already have an `Intl.DateTimeFormat` and want it to control the + * locale, time zone, and formatting options. + * + * **Details** + * + * The formatter receives the `DateTime` epoch milliseconds. Any time zone + * conversion comes from the supplied formatter. + * + * **Example** (Formatting DateTime values with custom formatters) * - * @example * ```ts * import { DateTime } from "effect" * @@ -3651,21 +4427,27 @@ export const formatIntl: { * }) * * const formatted = DateTime.formatIntl(dt, formatter) - * console.log(formatted) // "15. Juni 2024, 16:30" + * console.log(formatted.length > 0) // true * ``` * - * @since 3.6.0 + * @see {@link formatUtc} for formatting with options forced to UTC + * @see {@link formatIso} for stable ISO formatting + * * @category formatting + * @since 3.6.0 */ (self: DateTime, format: Intl.DateTimeFormat): string } = Internal.formatIntl /** - * Format a `DateTime` as a UTC ISO string. + * Formats a `DateTime` as a UTC ISO string. + * + * **Details** * * Always returns the UTC representation in ISO 8601 format, ignoring any time zone. * - * @example + * **Example** (Formatting DateTime values as ISO strings) + * * ```ts * import { DateTime } from "effect" * @@ -3684,11 +4466,14 @@ export const formatIntl: { export const formatIso: (self: DateTime) => string = Internal.formatIso /** - * Format a `DateTime` as a time zone adjusted ISO date string. + * Formats a `DateTime` as a time zone adjusted ISO date string. + * + * **Details** * * Returns only the date part (YYYY-MM-DD) after applying time zone adjustments. * - * @example + * **Example** (Formatting DateTime values as ISO dates) + * * ```ts * import { DateTime } from "effect" * @@ -3707,11 +4492,14 @@ export const formatIso: (self: DateTime) => string = Internal.formatIso export const formatIsoDate: (self: DateTime) => string = Internal.formatIsoDate /** - * Format a `DateTime` as a UTC ISO date string. + * Formats a `DateTime` as a UTC ISO date string. + * + * **Details** * * Returns only the date part (YYYY-MM-DD) in UTC, ignoring any time zone. * - * @example + * **Example** (Formatting DateTime values as UTC ISO dates) + * * ```ts * import { DateTime } from "effect" * @@ -3730,12 +4518,15 @@ export const formatIsoDate: (self: DateTime) => string = Internal.formatIsoDate export const formatIsoDateUtc: (self: DateTime) => string = Internal.formatIsoDateUtc /** - * Format a `DateTime.Zoned` as an ISO string with an offset. + * Formats a `DateTime.Zoned` as an ISO string with an offset. + * + * **Details** * * For `DateTime.Utc`, returns the same as `formatIso`. For `DateTime.Zoned`, * includes the time zone offset in the format. * - * @example + * **Example** (Formatting DateTime values with offsets) + * * ```ts * import { DateTime } from "effect" * @@ -3754,11 +4545,14 @@ export const formatIsoDateUtc: (self: DateTime) => string = Internal.formatIsoDa export const formatIsoOffset: (self: DateTime) => string = Internal.formatIsoOffset /** - * Format a `DateTime.Zoned` as a string. + * Formats a `DateTime.Zoned` as a string. + * + * **Details** * * It uses the format: `YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone]`. * - * @example + * **Example** (Formatting zoned DateTime values) + * * ```ts * import { DateTime } from "effect" * @@ -3777,17 +4571,20 @@ export const formatIsoOffset: (self: DateTime) => string = Internal.formatIsoOff * console.log(offsetFormatted) // "2024-06-15T17:30:45.123+03:00" * ``` * - * @since 3.6.0 * @category formatting + * @since 3.6.0 */ export const formatIsoZoned: (self: Zoned) => string = Internal.formatIsoZoned /** * Create a Layer from the given time zone. * + * **Details** + * * This layer provides the `CurrentTimeZone` service with the specified time zone. * - * @example + * **Example** (Providing current time zone layers) + * * ```ts * import { DateTime, Effect } from "effect" * @@ -3813,9 +4610,12 @@ export const layerCurrentZone: (resource: NoInfer) => Layer.Layer Layer.Layer< /** * Create a Layer from the system's local time zone. * + * **Details** + * * This layer provides the `CurrentTimeZone` service using the system's * configured local time zone. * - * @example + * **Example** (Providing local time zone layers) + * * ```ts * import { DateTime, Effect } from "effect" *