Skip to main content Link Search Menu Expand Document (external link)

DateTime overview

This module implements an immutable CVDateTime object.

CVDateTime objects keep an internal state. But all provided functions are pure insofar as they always yield the same result whatever the state the object is in. The state is only used to improve performance but does not alter the results.

Unlike the JavaScript Date objects and the Effect DateTime objects, CVDateTime objects handle both the Gregorian and Iso calendars. So you can easily get/set the iso year and iso week of a CVDateTime object.

A CVDateTime object has a zoneOffset which is the difference in hours between the time in the local zone and UTC time (e.g. zoneOffset=1 for timezone +1:00). All the data in a CVDateTime object is zoneOffset-dependent, except timestamp. An important thing to note is that a CVDateTime object with a timestamp t and a zoneOffset zo has exactly the same date parts (year, ordinalDay, month, monthDay, isoYear…) as a CVDateTime object with timestamp = t+zox3600 and zoneOffset = 0. That’s the reason for the zonedTimestamp field which is equal to t+zox3600. All calculations are performed UTC using zonedTimestamp instead of timestamp.


Table of contents


Constants

LOCAL_TIME_ZONE_OFFSET

Local time zone offset in hours of the machine on which this code runs. The value is calculated once at startup.

Signature

export declare const LOCAL_TIME_ZONE_OFFSET: number

MAX_FULL_YEAR

Maximal usable year (ECMA-262)

Signature

export declare const MAX_FULL_YEAR: number

MAX_TIMESTAMP

Maximal usable timestamp (ECMA-262)

Signature

export declare const MAX_TIMESTAMP: 8640000000000000

MIN_FULL_YEAR

Minimal usable year (ECMA-262)

Signature

export declare const MIN_FULL_YEAR: number

MIN_TIMESTAMP

Minimal usable timestamp (ECMA-262)

Signature

export declare const MIN_TIMESTAMP: number

Constructors

fromDate

Builds a CVDateTime from a Javascript Date

Signature

export declare const fromDate: (date: Date) => Type

fromEffectDateTime

Builds a CVDateTime from an Effect.DateTime.Zoned

Signature

export declare const fromEffectDateTime: (date: DateTime.Zoned) => Type

fromParts

Tries to build a CVDateTime from the provided parts. Returns a Success if successful, a Failure otherwise.

year must comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. ordinalDay must be greater than or equal to 1 and less than or equal to the number of days in the current year. month must be greater than or equal to 1 (January) and less than or equal to 12 (December). monthDay must be greater than or equal to 1 and less than or equal to the number of days in the current month.

isoYear must be comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. isoWeek must be greater than or equal to 1 and less than or equal to the number of iso weeks in the current year. weekday must be greater than or equal to 1 (monday) and less than or equal to 7 (sunday).

If there is not sufficient information to determine the exact day of the year, i.e. none of the three following tuples is fully determined [year, ordinalDay], [year, month, monthDay], [isoYear, isoWeek, weekday], default values are determined in the following order (the first match stops the process):

  • If year and month are set, monthDay is taken equal to 1.
  • If year and monthDay are set, month is taken equal to 1.
  • If year is set and both month and monthDay are undefined, the day is taken to be the first one in the year.
  • If isoYear and isoWeek are set, weekday is taken equal to 1.
  • If isoYear and weekday are set, isoWeek is taken equal to 1.
  • If isoYear is set and both isoWeek and weekday are undefined, the day is taken to be the first one in the iso year.
  • If both year and isoYear are undefined, an error is raised.

hour23 must be greater than or equal to 0 and less than or equal to 23. hour11 must be greater than or equal to 0 and less than or equal to 11. meridiem must be one of 0 (AM) or 12 (PM). If there is not sufficient information to determine the hour of the day, i.e. none of the two following tuples is fully determined [hour23], [hour11, meridiem], default values are determined as follows:

  • If meridiem is set, hour11 is taken equal to 0.
  • If hour11 is set, meridiem is taken equal to 0.
  • Otherwise, meridiem and hour11 are taken equal to 0.

minute must be greater than or equal to 0 and less than or equal to 59. If omitted, minute is assumed to be 0.

second must be greater than or equal to 0 and less than or equal to 59. If omitted, second is assumed to be 0.

millisecond must be greater than or equal to 0 and less than or equal to 999. If omitted, millisecond is assumed to be 0.

zoneOffset must be strictly greater than -13 and strictly less than 15. zoneHour must be greater than or equal to -12 and less than or equal to 14. zoneMinute must be greater than or equal to 0 and less than or equal to 59. zoneSecond must be greater than or equal to 0 and less than or equal to 59.

If there is not sufficient information to determine the exact time zone offset, i.e. none of the two following tuples is fully determined [zoneOffset], [zoneHour, zoneMinute, zoneSecond], default values are determined as follows :

  • If all parameters are undefined, the local time zone offset of the machine this code is running on is used. ATTENTION: unlike the JavaScript Date constructor, fromParts uses the current time zone offset, not the one that prevails at the given date (so, in Paris, in winter, the time zone offset for date 20250714 is -1 and not -2).
  • If any of zoneHour, zoneMinute, zoneSecond is defined, the remaining undefined parameters are taken equal to 0.

Note that zoneHour=-0, zoneMinute=10, zoneSecond=0 is different from zoneHour=0, zoneMinute=10, zoneSecond=0. The first corresponds to the string ‘GMT-00:10’, a negative 10-minute offset, the second one to the string ‘GMT+00:10’, a positive 10-minute offset.

year, ordinalDay, month, monthDay, isoYear, isoWeek, weekday, hour23, hour11, minute, second, millisecond, zoneHour, zoneMinute and zoneSecond should be integers. zoneOffset does not need to be an integer.

All parameters must be coherent. For instance, year=1970, month=1, monthDay=1, weekday=0 zoneHour=0, zoneMinute=0 and zoneSecond=0 will trigger an error because 1/1/1970 00:00:00:000+0:00 is a thursday. hour23=13 and meridiem=0 will also trigger an error.

Signature

export declare const fromParts: (params: CVDateTimeParts.Type) => Result.Result<Type, MInputError.Type>

fromPartsOrThrow

Same as fromParts but returns directly a CVDateTime or throws if it cannot be built

Signature

export declare const fromPartsOrThrow: (parts: CVDateTimeParts.Type) => Type

fromTimestamp

Tries to build a CVDateTime from timestamp, the number of milliseconds since 1/1/1970 00:00:00:000+0:00, and zoneOffset which gives the offset between the local time and the UTC time. Returns a Success if successful, a Failure otherwise.

timestamp must be greater than or equal to MIN_TIMESTAMP and less than or equal to MAX_TIMESTAMP.

If zoneOffset is omitted, the local time zone offset of the machine this code is running on is used.

zoneOffset can be expressed as a number of hours. In this case, it must be strictly greater to

  • 13 and strictly less than 15.

It can also be expressed as an object containing three components:

  • zoneHour which must be greater than or equal to -12 and less than or equal to 14.
  • zoneMinute which must be greater than or equal to 0 and less than or equal to 59.
  • zoneSecond which must be greater than or equal to 0 and less than or equal to 59.

Note that zoneHour=-0, zoneMinute=10, zoneSecond=0 is different from zoneHour=0, zoneMinute=10, zoneSecond=0. The first corresponds to the string ‘GMT-00:10’, a negative 10-minute offset, the second one to the string ‘GMT+00:10’, a positive 10-minute offset.

timestamp, zoneHour, zoneMinute and zoneSecond should be integers. zoneOffset, when expressed as a number of hours, does not need to be an integer.

Signature

export declare const fromTimestamp: (
  timestamp: number,
  zoneOffset?: number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number }
) => Result.Result<Type, MInputError.Type>

fromTimestampOrThrow

Same as fromTimestamp but returns directly a CVDateTime or throws if it cannot be built

Signature

export declare const fromTimestampOrThrow: (
  timestamp: number,
  zoneOffset?: number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number }
) => Type

now

Builds a CVDateTime using Date.now() as timestamp. zoneOffset is set to 0.

Signature

export declare const now: () => Type

Destructors

getHour11

Returns the hour11 of self for the given time zone

Signature

export declare const getHour11: MTypes.OneArgFunction<Type, number>

getHour23

Returns the hour23 of self for the given time zone

Signature

export declare const getHour23: MTypes.OneArgFunction<Type, number>

getIsoString

Returns the ISO representation of this DateTime

Signature

export declare const getIsoString: (self: Type) => string

getIsoWeek

Returns the isoWeek of self for the given time zone

Signature

export declare const getIsoWeek: MTypes.OneArgFunction<Type, number>

getIsoYear

Returns the isoYear of self for the given time zone

Signature

export declare const getIsoYear: MTypes.OneArgFunction<Type, number>

getMeridiem

Returns the meridiem of self for the given time zone

Signature

export declare const getMeridiem: MTypes.OneArgFunction<Type, 0 | 12>

getMillisecond

Returns the millisecond of self for the given time zone

Signature

export declare const getMillisecond: MTypes.OneArgFunction<Type, number>

getMinute

Returns the minute of self for the given time zone

Signature

export declare const getMinute: MTypes.OneArgFunction<Type, number>

getMonth

Returns the month of self for the given time zone

Signature

export declare const getMonth: MTypes.OneArgFunction<Type, number>

getMonthDay

Returns the monthDay of self for the given time zone

Signature

export declare const getMonthDay: MTypes.OneArgFunction<Type, number>

getOrdinalDay

Returns the ordinalDay of self for the given time zone

Signature

export declare const getOrdinalDay: MTypes.OneArgFunction<Type, number>

getSecond

Returns the second of self for the given time zone

Signature

export declare const getSecond: MTypes.OneArgFunction<Type, number>

getWeekday

Returns the weekday of self for the given time zone

Signature

export declare const getWeekday: MTypes.OneArgFunction<Type, number>

getYear

Returns the (Gregorian) year of self for the given time zone

Signature

export declare const getYear: MTypes.OneArgFunction<Type, number>

getZoneHour

Returns the hour part of the zoneOffset of self

Signature

export declare const getZoneHour: MTypes.OneArgFunction<Type, number>

getZoneMinute

Returns the minute part of the zoneOffset of self

Signature

export declare const getZoneMinute: MTypes.OneArgFunction<Type, number>

getZoneSecond

Returns the second part of the zoneOffset of self

Signature

export declare const getZoneSecond: MTypes.OneArgFunction<Type, number>

Equivalences

equivalence

Equivalence

Signature

export declare const equivalence: Equivalence.Equivalence<Type>

Getters

gregorianDate

Returns the gregorianDate property of self

Signature

export declare const gregorianDate: MTypes.OneArgFunction<Type, CVGregorianDate.Type>

isoDate

Returns the isoDate property of self

Signature

export declare const isoDate: MTypes.OneArgFunction<Type, CVIsoDate.Type>

time

Returns the time property of self

Signature

export declare const time: MTypes.OneArgFunction<Type, CVTime.Type>

timestamp

Returns the timestamp property of self as a number

Signature

export declare const timestamp: MTypes.OneArgFunction<Type, number>

zoneOffsetParts

Returns the zoneOffsetParts property of self

Signature

export declare const zoneOffsetParts: MTypes.OneArgFunction<Type, CVZoneOffsetParts.Type>

Models

Type (class)

Type that represents a CVDateTime

Signature

export declare class Type {
  private constructor({
    timestamp,
    _gregorianDate,
    _isoDate,
    _time,
    zoneOffset,
    _zoneOffsetParts,
    zonedTimestamp
  }: {
    readonly timestamp: number
    readonly _gregorianDate: Option.Option<CVGregorianDate.Type>
    readonly _isoDate: Option.Option<CVIsoDate.Type>
    readonly _time: Option.Option<CVTime.Type>
    readonly zoneOffset: number
    readonly _zoneOffsetParts: Option.Option<CVZoneOffsetParts.Type>
    readonly zonedTimestamp: number
  })
}

uncalculatedFromTimestamp (static method)

Constructor that creates a DateTime from a timestamp and a zoneOffset for which no calculations have been carried out yet. The zonedTimestamp field is automatically calculated. Does not check any input parameters

Signature

private static uncalculatedFromTimestamp(timestamp: number, zoneOffset: number): Type

uncalculatedFromZonedTimestamp (static method)

Constructor that creates a DateTime from a zonedTimestamp and a zoneOffset for which no calculations have been carried out yet. The timestamp field is automatically calculated. Does not check any input parameters

Signature

private static uncalculatedFromZonedTimestamp(zonedTimestamp: number, zoneOffset: number): Type

fromTimestamp (static method)

Tries to build a CVDateTime from timestamp, the number of milliseconds since 1/1/1970 00:00:00:000+0:00, and zoneOffset which gives the offset between the local time and the UTC time. Returns a Success if successful, a Failure otherwise.

timestamp must be greater than or equal to MIN_TIMESTAMP and less than or equal to MAX_TIMESTAMP.

If zoneOffset is omitted, the local time zone offset of the machine this code is running on is used.

zoneOffset can be expressed as a number of hours. In this case, it must be strictly greater to

  • 13 and strictly less than 15.

It can also be expressed as an object containing three components:

  • zoneHour which must be greater than or equal to -12 and less than or equal to 14.
  • zoneMinute which must be greater than or equal to 0 and less than or equal to 59.
  • zoneSecond which must be greater than or equal to 0 and less than or equal to 59.

Note that zoneHour=-0, zoneMinute=10, zoneSecond=0 is different from zoneHour=0, zoneMinute=10, zoneSecond=0. The first corresponds to the string ‘GMT-00:10’, a negative 10-minute offset, the second one to the string ‘GMT+00:10’, a positive 10-minute offset.

timestamp, zoneHour, zoneMinute and zoneSecond should be integers. zoneOffset, when expressed as a number of hours, does not need to be an integer.

Signature

static fromTimestamp(
    timestamp: number,
    zoneOffset?:
      | number
      | {
          readonly zoneHour: number;
          readonly zoneMinute: number;
          readonly zoneSecond: number;
        },
  ): Result.Result<Type, MInputError.Type>

now (static method)

Builds a CVDateTime using Date.now() as timestamp. zoneOffset is set to 0.

Signature

static now(): Type

fromParts (static method)

Tries to build a CVDateTime from the provided parts. Returns a Success if successful, a Failure otherwise.

year must comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. ordinalDay must be greater than or equal to 1 and less than or equal to the number of days in the current year. month must be greater than or equal to 1 (January) and less than or equal to 12 (December). monthDay must be greater than or equal to 1 and less than or equal to the number of days in the current month.

isoYear must be comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR]. isoWeek must be greater than or equal to 1 and less than or equal to the number of iso weeks in the current year. weekday must be greater than or equal to 1 (monday) and less than or equal to 7 (sunday).

If there is not sufficient information to determine the exact day of the year, i.e. none of the three following tuples is fully determined [year, ordinalDay], [year, month, monthDay], [isoYear, isoWeek, weekday], default values are determined in the following order (the first match stops the process):

  • If year and month are set, monthDay is taken equal to 1.
  • If year and monthDay are set, month is taken equal to 1.
  • If year is set and both month and monthDay are undefined, the day is taken to be the first one in the year.
  • If isoYear and isoWeek are set, weekday is taken equal to 1.
  • If isoYear and weekday are set, isoWeek is taken equal to 1.
  • If isoYear is set and both isoWeek and weekday are undefined, the day is taken to be the first one in the iso year.
  • If both year and isoYear are undefined, an error is raised.

hour23 must be greater than or equal to 0 and less than or equal to 23. hour11 must be greater than or equal to 0 and less than or equal to 11. meridiem must be one of 0 (AM) or 12 (PM). If there is not sufficient information to determine the hour of the day, i.e. none of the two following tuples is fully determined [hour23], [hour11, meridiem], default values are determined as follows:

  • If meridiem is set, hour11 is taken equal to 0.
  • If hour11 is set, meridiem is taken equal to 0.
  • Otherwise, meridiem and hour11 are taken equal to 0.

minute must be greater than or equal to 0 and less than or equal to 59. If omitted, minute is assumed to be 0.

second must be greater than or equal to 0 and less than or equal to 59. If omitted, second is assumed to be 0.

millisecond must be greater than or equal to 0 and less than or equal to 999. If omitted, millisecond is assumed to be 0.

zoneOffset must be strictly greater than -13 and strictly less than 15. zoneHour must be greater than or equal to -12 and less than or equal to 14. zoneMinute must be greater than or equal to 0 and less than or equal to 59. zoneSecond must be greater than or equal to 0 and less than or equal to 59.

If there is not sufficient information to determine the exact time zone offset, i.e. none of the two following tuples is fully determined [zoneOffset], [zoneHour, zoneMinute, zoneSecond], default values are determined as follows :

  • If all parameters are undefined, the local time zone offset of the machine this code is running on is used. ATTENTION: unlike the JavaScript Date constructor, fromParts uses the current time zone offset, not the one that prevails at the given date (so, in Paris, in winter, the time zone offset for date 20250714 is -1 and not -2).
  • If any of zoneHour, zoneMinute, zoneSecond is defined, the remaining undefined parameters are taken equal to 0.

Note that zoneHour=-0, zoneMinute=10, zoneSecond=0 is different from zoneHour=0, zoneMinute=10, zoneSecond=0. The first corresponds to the string ‘GMT-00:10’, a negative 10-minute offset, the second one to the string ‘GMT+00:10’, a positive 10-minute offset.

year, ordinalDay, month, monthDay, isoYear, isoWeek, weekday, hour23, hour11, minute, second, millisecond, zoneHour, zoneMinute and zoneSecond should be integers. zoneOffset does not need to be an integer.

All parameters must be coherent. For instance, year=1970, month=1, monthDay=1, weekday=0 zoneHour=0, zoneMinute=0 and zoneSecond=0 will trigger an error because 1/1/1970 00:00:00:000+0:00 is a thursday. hour23=13 and meridiem=0 will also trigger an error.

Signature

static fromParts({
    year,
    ordinalDay,
    month,
    monthDay,
    isoYear,
    isoWeek,
    weekday,
    hour23,
    hour11,
    meridiem,
    minute,
    second,
    millisecond,
    zoneOffset,
    zoneHour,
    zoneMinute,
    zoneSecond,
  }: CVDateTimeParts.Type): Result.Result<Type, MInputError.Type>

[MData.idSymbol] (method)

Returns the id of this

Signature

[MData.idSymbol](): string | (() => string)

_setTimestamp (method)

If possible, returns a Success of a copy of self with timestamp set to timestamp. Returns a Failure of an error otherwise. timestamp must be an integer comprised in the range [MIN_TIMESTAMP, MAX_TIMESTAMP] representing the number of milliseconds since 1/1/1970 00:00:00:000+0:00.

Signature

_setTimestamp(timestamp: number): Result.Result<Type, MInputError.Type>

_setZoneOffset (method)

If possible, returns a Success of a copy of self with zoneOffset set to zoneOffset. Returns a Failure of an error otherwise. timestamp must be an integer comprised in the range [MIN_TIMESTAMP, MAX_TIMESTAMP] representing the number of milliseconds since 1/1/1970 00:00:00:000+0:00.

Signature

_setZoneOffset(
    keepTimestamp: boolean,
    zoneOffset:
      | number
      | {
          readonly zoneHour: number;
          readonly zoneMinute: number;
          readonly zoneSecond: number;
        } = LOCAL_TIME_ZONE_OFFSET,
  ): Result.Result<Type, MInputError.Type>

_setGregorianDate (method)

Returns a copy of this with _gregorianDate set to gregorianDate

Signature

_setGregorianDate(gregorianDate: CVGregorianDate.Type): Type

_setIsoDate (method)

Returns a copy of this with isoDate set to isoDate

Signature

_setIsoDate(isoDate: CVIsoDate.Type): Type

_setTime (method)

Returns a copy of this with time set to time

Signature

_setTime(time: CVTime.Type): Type

[Hash.symbol] (method)

Calculates the hash value of this

Signature

[Hash.symbol](): number

[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)

Function that implements the equivalence of this and that

Signature

[MEquivalenceBasedEqualityData.isEquivalentToSymbol](this: this, that: this): boolean

[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)

Predicate that returns true if that has the same type marker as this

Signature

[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol](that: unknown): boolean

timestamp (property)

Timestamp of this DateTime (timezone-independent)

Signature

readonly timestamp: number

zoneOffset (property)

Offset in hours between the time of the zone for which all calculations of that DateTime object will be carried out and UTC time (e.g zoneOffset=1 for timezone +1:00). Not necessarily an integer, range: ]-13, 15[

Signature

readonly zoneOffset: number

zonedTimestamp (property)

Calculated field equal to timestamp + zoneOffsetx3600

Signature

readonly zonedTimestamp: number

Module markers

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/conversions/DateTime/"

Offsetters

offsetDays

If possible, returns a Success of a copy of self offset by offset days. Returns a Failure of an error otherwise.

Signature

export declare const offsetDays: (offset: number) => MTypes.OneArgFunction<Type, Result.Result<Type, MInputError.Type>>

offsetDaysOrThrow

Same as offsetDays but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetDaysOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

offsetHours

If possible, returns a Success of a copy of self offset by offset hours. Returns a Failure of an error otherwise.

Signature

export declare const offsetHours: (offset: number) => MTypes.OneArgFunction<Type, Result.Result<Type, MInputError.Type>>

offsetHoursOrThrow

Same as offsetHours but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetHoursOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

offsetIsoYears

If possible, returns a Success of a copy of self offset by offset iso years and having the same weekday, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. If respectYearEnd is true and self is on the last day of an iso year, the new DateTime object’s isoWeek will be the last of the target iso year. Otherwise, it will be the same as self’s.

Signature

export declare const offsetIsoYears: (
  offset: number,
  respectYearEnd: boolean
) => (self: Type) => Result.Result<Type, MInputError.Type>

offsetIsoYearsOrThrow

Same as offsetIsoYears but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetIsoYearsOrThrow: (offset: number, respectYearEnd: boolean) => MTypes.OneArgFunction<Type>

offsetMilliseconds

If possible, returns a Success of a copy of self offset by offset milliseconds. Returns a Failure of an error otherwise.

Signature

export declare const offsetMilliseconds: (offset: number) => (self: Type) => Result.Result<Type, MInputError.Type>

offsetMillisecondsOrThrow

Same as offsetMilliseconds but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetMillisecondsOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

offsetMinutes

If possible, returns a Success of a copy of self offset by offset minutes. Returns a Failure of an error otherwise.

Signature

export declare const offsetMinutes: (
  offset: number
) => MTypes.OneArgFunction<Type, Result.Result<Type, MInputError.Type>>

offsetMinutesOrThrow

Same as offsetMinutes but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetMinutesOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

offsetMonths

If possible, returns a Success of a copy of self offset by offset months and having the same hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. If respectMonthEnd is true and self is on the last day of a month, the new DateTime object’s monthDay will be the last of the target month. Otherwise, it will be the same as self’s

Signature

export declare const offsetMonths: (
  offset: number,
  respectMonthEnd: boolean
) => (self: Type) => Result.Result<Type, MInputError.Type>

offsetMonthsOrThrow

Same as offsetMonths but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetMonthsOrThrow: (offset: number, respectMonthEnd: boolean) => MTypes.OneArgFunction<Type>

offsetSeconds

If possible, returns a Success of a copy of self offset by offset seconds. Returns a Failure of an error otherwise.

Signature

export declare const offsetSeconds: (
  offset: number
) => MTypes.OneArgFunction<Type, Result.Result<Type, MInputError.Type>>

offsetSecondsOrThrow

Same as offsetSeconds but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetSecondsOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

offsetYears

If possible, returns a Success of a copy of self offset by offset years and having the same month, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. If respectMonthEnd is true and self is on the last day of a month, the new DateTime object’s monthDay will be the last of the target month. Otherwise, it will be the same as self

Signature

export declare const offsetYears: (
  offset: number,
  respectMonthEnd: boolean
) => MTypes.OneArgFunction<Type, Result.Result<Type, MInputError.Type>>

offsetYearsOrThrow

Same as offsetYears but returns directly a CVDateTime or throws in case of an error

Signature

export declare const offsetYearsOrThrow: (offset: number, respectMonthEnd: boolean) => MTypes.OneArgFunction<Type>

toFirstIsoYearDay

Returns a copy of self where isoWeek and weekday are set to 1. All time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toFirstIsoYearDay: MTypes.OneArgFunction<Type, Type>

toFirstMonthDay

Returns a copy of self where monthDay is set to the first day of the current month. All time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toFirstMonthDay: MTypes.OneArgFunction<Type, Type>

toFirstYearDay

Returns a copy of self where ordinalDay is set to the first day of the current year. All time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toFirstYearDay: (self: Type) => Type

toLastIsoYearDay

Returns a copy of self where isoWeek is set to the last week of the current iso year and weekday is set to 7. All time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toLastIsoYearDay: (self: Type) => Type

toLastIsoYearWeek

Returns a copy of self where isoWeek is set to the last week of the current iso year. weekday and all time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toLastIsoYearWeek: (self: Type) => Type

toLastMonthDay

Returns a copy of self where monthDay is set to the last day of the current month. All time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toLastMonthDay: (self: Type) => Type

toLastYearDay

Returns a copy of self where ordinalDay is set to the last day of the current year. All time parts (hour23, hour11, meridiem, minute, second, millisecond) are left unchanged

Signature

export declare const toLastYearDay: (self: Type) => Type

Predicates

isFirstIsoYearDay

Returns true if self is the first day of an iso year in the given timezone

Signature

export declare const isFirstIsoYearDay: Predicate.Predicate<Type>

isFirstMonthDay

Returns true if self is the first day of a month in the given timezone

Signature

export declare const isFirstMonthDay: Predicate.Predicate<Type>

isFirstYearDay

Returns true if self is the first day of a year in the given timezone

Signature

export declare const isFirstYearDay: Predicate.Predicate<Type>

isLastIsoYearDay

Returns true if self is the last day of an iso year in the given timezone

Signature

export declare const isLastIsoYearDay: Predicate.Predicate<Type>

isLastMonthDay

Returns true if self is the last day of a month in the given timezone

Signature

export declare const isLastMonthDay: Predicate.Predicate<Type>

isLastYearDay

Returns true if self is the last day of a year in the given timezone

Signature

export declare const isLastYearDay: Predicate.Predicate<Type>

isoYearIsLong

Returns true if the isoYear of self for the given time zone is a long year. Returns false otherwise

Signature

export declare const isoYearIsLong: Predicate.Predicate<Type>

yearIsLeap

Returns true if the (Gregorian) year of self for the given time zone is a leap year. Returns false otherwise

Signature

export declare const yearIsLeap: Predicate.Predicate<Type>

Setters

setHour11

If possible, returns a Success of a CVDateTime having hour11 hour11 and the same year, ordinalDay, meridiem, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. hour11 must be an integer greater than or equal to 0 and less than or equal to 11.

Signature

export declare const setHour11: (hour11: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setHour11OrThrow

Same as setHour11 but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setHour11OrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setHour23

If possible, returns a Success of a CVDateTime having hour23 hour23 and the same year, ordinalDay, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. hour23 must be an integer greater than or equal to 0 and less than or equal to 23

Signature

export declare const setHour23: (hour23: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setHour23OrThrow

Same as setHour23 but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setHour23OrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setIsoWeek

If possible, returns a Success of a CVDateTime having isoWeek isoWeek and the same isoYear, weekday, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. isoWeek must be an integer greater than or equal to 1 and less than or equal to the number of iso weeks in the current year.

Signature

export declare const setIsoWeek: (isoWeek: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setIsoWeekOrThrow

Same as setIsoWeek but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setIsoWeekOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setIsoYear

If possible, returns a Success of a CVDateTime having isoYear isoYear and the same isoWeek, weekday, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. isoYear must be an integer comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR].

Signature

export declare const setIsoYear: (isoYear: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setIsoYearOrThrow

Same as setIsoYear but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setIsoYearOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setMeridiem

Returns a CVDateTime having meridiem meridiem and the same year, ordinalDay, hour11, minute, second, millisecond and zoneOffset as self

Signature

export declare const setMeridiem: (meridiem: 0 | 12) => (self: Type) => Type

setMillisecond

If possible, returns a Success of a CVDateTime having millisecond millisecond and the same year, ordinalDay, hour23, minute, second and zoneOffset as self. Returns a Failure of an error otherwise. millisecond must be an integer greater than or equal to 0 and less than or equal to 999.

Signature

export declare const setMillisecond: (millisecond: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setMillisecondOrThrow

Same as setMillisecond but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setMillisecondOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setMinute

If possible, returns a Success of a CVDateTime having minute minute and the same year, ordinalDay, hour23, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. minute must be an integer greater than or equal to 0 and less than or equal to 59

Signature

export declare const setMinute: (minute: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setMinuteOrThrow

Same as setMinute but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setMinuteOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setMonth

If possible, returns a Success of a CVDateTime having month month and the same year, monthDay, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. month must be an integer greater than or equal to 1 (January) and less than or equal to 12 (December)

Signature

export declare const setMonth: (month: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setMonthDay

If possible, returns a Success of a CVDateTime having monthDay monthDay and the same year, month, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. monthDay must be an integer greater than or equal to 1 and less than or equal to the number of days in the current month.

Signature

export declare const setMonthDay: (monthDay: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setMonthDayOrThrow

Same as setMonthDay but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setMonthDayOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setMonthOrThrow

Same as setMonth but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setMonthOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setOrdinalDay

If possible, returns a Success of a CVDateTime having ordinalDay ordinalDay and the same year, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. ordinalDay must be an integer greater than or equal to 1 and less than or equal to the number of days in the current year

Signature

export declare const setOrdinalDay: (ordinalDay: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setOrdinalDayOrThrow

Same as setOrdinalDay but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setOrdinalDayOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setSecond

If possible, returns a Success of a CVDateTime having second second and the same year, ordinalDay, hour23, minute, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. second must be an integer greater than or equal to 0 and less than or equal to 59

Signature

export declare const setSecond: (second: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setSecondOrThrow

Same as setSecond but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setSecondOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setWeekday

If possible, returns a Success of a CVDateTime having weekday weekday and the same isoYear, isoWeek, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure of an error otherwise. weekday must be an integer greater than or equal to 1 (monday) and less than or equal to 7 (sunday).

Signature

export declare const setWeekday: (weekday: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setWeekdayOrThrow

Same as setWeekday but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setWeekdayOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setYear

If possible, returns a Success of a CVDateTime having year year and the same month, monthDay, hour23, minute, second, millisecond and zoneOffset as self. Returns a Failure otherwise. year must be an integer comprised in the range [MIN_FULL_YEAR, MAX_FULL_YEAR].

Signature

export declare const setYear: (year: number) => (self: Type) => Result.Result<Type, MInputError.Type>

setYearOrThrow

Same as setYear but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setYearOrThrow: MTypes.OneArgFunction<number, MTypes.OneArgFunction<Type, Type>>

setZoneOffsetKeepParts

If possible, returns a Success of a copy of self with the same parts (except zoneOffset) and zoneOffset set to zoneOffset.

See setZoneOffsetKeepTimestamp for more details

Signature

export declare const setZoneOffsetKeepParts: (
  zoneOffset?: number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number }
) => (self: Type) => Result.Result<Type, MInputError.Type>

setZoneOffsetKeepPartsOrThrow

Same as setZoneOffsetKeepParts but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setZoneOffsetKeepPartsOrThrow: MTypes.OneArgFunction<
  number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number },
  MTypes.OneArgFunction<Type, Type>
>

setZoneOffsetKeepTimestamp

If possible, returns a Success of a copy of self with the same timestamp and zoneOffset set to zoneOffset.

If zoneOffset is omitted, the local time zone offset of the machine this code is running on is used.

zoneOffset can be expressed as a number of hours. In this case, it must be strictly greater to

  • 13 and strictly less than 15.

It can also be expressed as an object containing three components:

  • zoneHour which must be greater than or equal to -12 and less than or equal to 14.
  • zoneMinute which must be greater than or equal to 0 and less than or equal to 59.
  • zoneSecond which must be greater than or equal to 0 and less than or equal to 59.

zoneHour, zoneMinute and zoneSecond should be integers. zoneOffset, when expressed as a number of hours, does not need to be an integer.

Signature

export declare const setZoneOffsetKeepTimestamp: (
  zoneOffset?: number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number }
) => (self: Type) => Result.Result<Type, MInputError.Type>

setZoneOffsetKeepTimestampOrThrow

Same as setZoneOffsetKeepTimestamp but returns directly a CVDateTime or throws in case of an error

Signature

export declare const setZoneOffsetKeepTimestampOrThrow: MTypes.OneArgFunction<
  number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number },
  MTypes.OneArgFunction<Type, Type>
>

Utils

toDate

Builds a Javascript Date from a CVDateTime

Signature

export declare const toDate: (self: Type) => Date

toEffectDateTime

Builds an Effect.DateTime.Zoned from a CVDateTime

Signature

export declare const toEffectDateTime: (self: Type) => DateTime.Zoned