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

DateTime.ts overview

This module implements an immutable MDateTime object.

MDateTime 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, MDateTime objects handle both the Gregorian and Iso calendars. So you can easily get/set the iso year and iso week of a MDateTime object.

A MDateTime 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 MDateTime object is zoneOffset-dependent, except timestamp. An important thing to note is that a MDateTime object with a timestamp t and a zoneOffset zo has exactly the same date parts (year, ordinalDay, month, monthDay, isoYear…) as a MDateTime 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.


Exports Grouped by Category


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

declare const LOCAL_TIME_ZONE_OFFSET: number

Source

MAX_FULL_YEAR

Maximal usable year (ECMA-262)

Signature

declare const MAX_FULL_YEAR: number

Source

MAX_TIMESTAMP

Maximal usable timestamp (ECMA-262)

Signature

declare const MAX_TIMESTAMP: 8640000000000000

Source

MIN_FULL_YEAR

Minimal usable year (ECMA-262)

Signature

declare const MIN_FULL_YEAR: number

Source

MIN_TIMESTAMP

Minimal usable timestamp (ECMA-262)

Signature

declare const MIN_TIMESTAMP: number

Source

Constructors

fromDate

Builds a MDateTime from a Javascript Date

Signature

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

Source

fromEffectDateTime

Builds a MDateTime from an effect/DateTime.Zoned

Signature

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

Source

fromParts

Tries to build a MDateTime 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

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

Source

fromPartsOrThrow

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

Signature

declare const fromPartsOrThrow: (parts: Parts) => Type

Source

fromTimestamp

Tries to build a MDateTime 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

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

Source

fromTimestampOrThrow

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

Signature

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

Source

now

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

Signature

declare const now: () => Type

Source

parse

Returns a function that tries to parse a string into a MDateTime according to dateTimeFormat and dateTimeContext.

  • Use a precomputed parser when the same dateTimeFormat/dateTimeContext pair will be applied many times.

Example (Parse an ISO date into a MDateTime)

import * as MDateTime from "@parischap/effect-lib/MDateTime"
import * as MDateTimeContext from "@parischap/effect-lib/MDateTimeContext"
import * as MDateTimeFormat from "@parischap/effect-lib/MDateTimeFormat"

const parse = MDateTime.parse(MDateTimeFormat.iso8601, MDateTimeContext.enGB)
console.log(parse("1970-01-01")) // Success(MDateTime with timestamp 0)

Signature

declare const parse: (
  dateTimeFormat: MDateTimeFormat.Type,
  dateTimeContext: MDateTimeContext.Type
) => MTypes.OneArgFunction<string, Result.Result<Type, MInputError.Type>>

Source

parseOrThrow

Same as parse but throws in case of failure

Signature

declare const parseOrThrow: (
  dateTimeFormat: MDateTimeFormat.Type,
  dateTimeContext: MDateTimeContext.Type
) => MTypes.OneArgFunction<string, Type>

Source

Destructors

format

Returns a function that tries to format self into a string according to dateTimeFormat and dateTimeContext.

  • Use a precomputed formatter when the same dateTimeFormat/dateTimeContext pair will be applied many times.

Example (Format a MDateTime as an ISO date)

import * as MDateTime from "@parischap/effect-lib/MDateTime"
import * as MDateTimeContext from "@parischap/effect-lib/MDateTimeContext"
import * as MDateTimeFormat from "@parischap/effect-lib/MDateTimeFormat"

const format = MDateTime.format(MDateTimeFormat.iso8601, MDateTimeContext.enGB)
console.log(format(MDateTime.fromTimestampOrThrow(0, 0))) // Success('1970-01-01')

Signature

declare const format: (
  dateTimeFormat: MDateTimeFormat.Type,
  dateTimeContext: MDateTimeContext.Type
) => MTypes.OneArgFunction<Type, Result.Result<string, MInputError.Type>>

Source

formatOrThrow

Same as format but throws in case of failure

Signature

declare const formatOrThrow: (
  dateTimeFormat: MDateTimeFormat.Type,
  dateTimeContext: MDateTimeContext.Type
) => MTypes.OneArgFunction<Type, string>

Source

getHour11

Returns the hour11 of self for the given time zone

Signature

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

Source

getHour23

Returns the hour23 of self for the given time zone

Signature

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

Source

getIsoString

Returns the ISO representation of this DateTime

Signature

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

Source

getIsoWeek

Returns the isoWeek of self for the given time zone

Signature

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

Source

getIsoYear

Returns the isoYear of self for the given time zone

Signature

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

Source

getMeridiem

Returns the meridiem of self for the given time zone

Signature

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

Source

getMillisecond

Returns the millisecond of self for the given time zone

Signature

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

Source

getMinute

Returns the minute of self for the given time zone

Signature

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

Source

getMonth

Returns the month of self for the given time zone

Signature

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

Source

getMonthDay

Returns the monthDay of self for the given time zone

Signature

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

Source

getOrdinalDay

Returns the ordinalDay of self for the given time zone

Signature

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

Source

getSecond

Returns the second of self for the given time zone

Signature

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

Source

getWeekday

Returns the weekday of self for the given time zone

Signature

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

Source

getYear

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

Signature

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

Source

getZoneHour

Returns the hour part of the zoneOffset of self

Signature

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

Source

getZoneMinute

Returns the minute part of the zoneOffset of self

Signature

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

Source

getZoneSecond

Returns the second part of the zoneOffset of self

Signature

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

Source

Equivalences

equivalence

Equivalence

Signature

declare const equivalence: Equivalence.Equivalence<Type>

Source

Getters

gregorianDate

Returns the gregorianDate property of self

Signature

declare const gregorianDate: MTypes.OneArgFunction<Type, GregorianDate.Type>

Source

isoDate

Returns the isoDate property of self

Signature

declare const isoDate: MTypes.OneArgFunction<Type, IsoDate.Type>

Source

time

Returns the time property of self

Signature

declare const time: MTypes.OneArgFunction<Type, Time.Type>

Source

timestamp

Returns the timestamp property of self as a number

Signature

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

Source

zoneOffsetParts

Returns the zoneOffsetParts property of self

Signature

declare const zoneOffsetParts: MTypes.OneArgFunction<Type, ZoneOffsetParts.Type>

Source

Models

Parts (interface)

Type that represents the different parts of a MDateTime

Signature

export interface Parts {
  /** The Gregorian year, range: [MIN_FULL_YEAR, MAX_FULL_YEAR] */
  readonly year?: number
  /** Number of days elapsed since the start of year, range:[1, 366] */
  readonly ordinalDay?: number
  /** Month in the current year, range:[1, 12] */
  readonly month?: number
  /** Day in the current month, range:[1, 31] */
  readonly monthDay?: number
  /** The iso year, range: [MIN_FULL_YEAR, MAX_FULL_YEAR] */
  readonly isoYear?: number
  /** The iso week in the current iso year, range:[1, 53] */
  readonly isoWeek?: number
  /** Week day in the current iso week, range:[1, 7], 1 is monday, 7 is sunday */
  readonly weekday?: number
  /** Number of hours since the start of the current day, range:[0, 23] */
  readonly hour23?: number
  /** Number of hours since the start of the current meridiem, range:[0, 11] */
  readonly hour11?: number
  /** Meridiem offset of this DateTime in hours, 0 for 'AM', 12 for 'PM' */
  readonly meridiem?: 0 | 12
  /** Number of minutes since the start of the current hour, range:[0, 59] */
  readonly minute?: number
  /** Number of seconds, since the start of the current minute, range:[0, 59] */
  readonly second?: number
  /** Number of milliseconds, since the start of the current second, range:[0, 999] */
  readonly millisecond?: number
  /**
   * Offset in hours between the time in the local zone and UTC time (e.g zoneOffset=1 for timezone
   * +1:00). Not necessarily an integer, range: ]-13, 15[
   */
  readonly zoneOffset?: number
  /** Hour part of the zoneOffset. Should be an integer in the range: [-12, 14] */
  readonly zoneHour?: number
  /** Minute part of the zoneOffset. Should be an integer in the range: [0, 59] */
  readonly zoneMinute?: number
  /** Second part of the zoneOffset. Should be an integer in the range: [0, 59] */
  readonly zoneSecond?: number
}

Source

Type (class)

Type that represents a MDateTime

Signature

declare class Type {
  private constructor({
    timestamp,
    _gregorianDate,
    _isoDate,
    _time,
    zoneOffset,
    _zoneOffsetParts,
    zonedTimestamp
  }: {
    readonly timestamp: number
    readonly _gregorianDate: Option.Option<GregorianDate.Type>
    readonly _isoDate: Option.Option<IsoDate.Type>
    readonly _time: Option.Option<Time.Type>
    readonly zoneOffset: number
    readonly _zoneOffsetParts: Option.Option<ZoneOffsetParts.Type>
    readonly zonedTimestamp: number
  })
}

Source

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

declare const uncalculatedFromTimestamp: (timestamp: number, zoneOffset: number) => Type

Source

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

declare const uncalculatedFromZonedTimestamp: (zonedTimestamp: number, zoneOffset: number) => Type

Source

fromTimestamp (static method)

Tries to build a MDateTime 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

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

Source

now (static method)

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

Signature

declare const now: () => Type

Source

fromParts (static method)

Tries to build a MDateTime 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

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

Source

[MData.idSymbol] (method)

Returns the id of this

Signature

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

Source

_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

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

Source

_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

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

Source

_setGregorianDate (method)

Returns a copy of this with _gregorianDate set to gregorianDate

Signature

declare const _setGregorianDate: (gregorianDate: GregorianDate.Type) => Type

Source

_setIsoDate (method)

Returns a copy of this with isoDate set to isoDate

Signature

declare const _setIsoDate: (isoDate: IsoDate.Type) => Type

Source

_setTime (method)

Returns a copy of this with time set to time

Signature

declare const _setTime: (time: Time.Type) => Type

Source

[Hash.symbol] (method)

Calculates the hash value of this

Signature

declare const [Hash.symbol]: () => number

Source

[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)

Function that implements the equivalence of this and that

Signature

declare const [MEquivalenceBasedEqualityData.isEquivalentToSymbol]: (this: this, that: this) => boolean

Source

[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)

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

Signature

declare const [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol]: (that: unknown) => boolean

Source

timestamp (property)

Timestamp of this DateTime (timezone-independent)

Signature

readonly timestamp: number

Source

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

Source

zonedTimestamp (property)

Calculated field equal to timestamp + zoneOffsetx3600

Signature

readonly zonedTimestamp: number

Source

Module markers

moduleTag

Module tag

Signature

declare const moduleTag: "@parischap/effect-lib/DateTime/"

Source

Offsetters

offsetDays

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

Signature

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

Source

offsetDaysOrThrow

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

Signature

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

Source

offsetHours

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

Signature

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

Source

offsetHoursOrThrow

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

Signature

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

Source

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

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

Source

offsetIsoYearsOrThrow

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

Signature

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

Source

offsetMilliseconds

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

Signature

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

Source

offsetMillisecondsOrThrow

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

Signature

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

Source

offsetMinutes

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

Signature

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

Source

offsetMinutesOrThrow

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

Signature

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

Source

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

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

Source

offsetMonthsOrThrow

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

Signature

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

Source

offsetSeconds

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

Signature

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

Source

offsetSecondsOrThrow

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

Signature

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

Source

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

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

Source

offsetYearsOrThrow

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

Signature

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

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

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

Source

Predicates

isFirstIsoYearDay

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

Signature

declare const isFirstIsoYearDay: Predicate.Predicate<Type>

Source

isFirstMonthDay

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

Signature

declare const isFirstMonthDay: Predicate.Predicate<Type>

Source

isFirstYearDay

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

Signature

declare const isFirstYearDay: Predicate.Predicate<Type>

Source

isLastIsoYearDay

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

Signature

declare const isLastIsoYearDay: Predicate.Predicate<Type>

Source

isLastMonthDay

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

Signature

declare const isLastMonthDay: Predicate.Predicate<Type>

Source

isLastYearDay

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

Signature

declare const isLastYearDay: Predicate.Predicate<Type>

Source

isoYearIsLong

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

Signature

declare const isoYearIsLong: Predicate.Predicate<Type>

Source

yearIsLeap

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

Signature

declare const yearIsLeap: Predicate.Predicate<Type>

Source

Setters

setHour11

If possible, returns a Success of a MDateTime 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

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

Source

setHour11OrThrow

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

Signature

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

Source

setHour23

If possible, returns a Success of a MDateTime 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

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

Source

setHour23OrThrow

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

Signature

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

Source

setIsoWeek

If possible, returns a Success of a MDateTime 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

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

Source

setIsoWeekOrThrow

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

Signature

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

Source

setIsoYear

If possible, returns a Success of a MDateTime 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

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

Source

setIsoYearOrThrow

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

Signature

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

Source

setMeridiem

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

Signature

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

Source

setMillisecond

If possible, returns a Success of a MDateTime 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

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

Source

setMillisecondOrThrow

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

Signature

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

Source

setMinute

If possible, returns a Success of a MDateTime 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

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

Source

setMinuteOrThrow

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

Signature

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

Source

setMonth

If possible, returns a Success of a MDateTime 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

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

Source

setMonthDay

If possible, returns a Success of a MDateTime 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

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

Source

setMonthDayOrThrow

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

Signature

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

Source

setMonthOrThrow

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

Signature

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

Source

setOrdinalDay

If possible, returns a Success of a MDateTime 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

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

Source

setOrdinalDayOrThrow

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

Signature

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

Source

setSecond

If possible, returns a Success of a MDateTime 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

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

Source

setSecondOrThrow

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

Signature

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

Source

setWeekday

If possible, returns a Success of a MDateTime 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

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

Source

setWeekdayOrThrow

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

Signature

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

Source

setYear

If possible, returns a Success of a MDateTime 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

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

Source

setYearOrThrow

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

Signature

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

Source

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

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

Source

setZoneOffsetKeepPartsOrThrow

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

Signature

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

Source

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

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

Source

setZoneOffsetKeepTimestampOrThrow

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

Signature

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

Source

Utils

toDate

Builds a Javascript Date from a MDateTime

Signature

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

Source

toEffectDateTime

Builds an effect/DateTime.Zoned from a MDateTime

Signature

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

Source