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
- Constructors
- Destructors
- Equivalences
- Getters
- Models
- Parts (interface)
- Type (class)
- uncalculatedFromTimestamp (static method)
- uncalculatedFromZonedTimestamp (static method)
- fromTimestamp (static method)
- now (static method)
- fromParts (static method)
- [MData.idSymbol] (method)
- _setTimestamp (method)
- _setZoneOffset (method)
- _setGregorianDate (method)
- _setIsoDate (method)
- _setTime (method)
- [Hash.symbol] (method)
- [MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
- [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
- timestamp (property)
- zoneOffset (property)
- zonedTimestamp (property)
- Module markers
- Offsetters
- offsetDays
- offsetDaysOrThrow
- offsetHours
- offsetHoursOrThrow
- offsetIsoYears
- offsetIsoYearsOrThrow
- offsetMilliseconds
- offsetMillisecondsOrThrow
- offsetMinutes
- offsetMinutesOrThrow
- offsetMonths
- offsetMonthsOrThrow
- offsetSeconds
- offsetSecondsOrThrow
- offsetYears
- offsetYearsOrThrow
- toFirstIsoYearDay
- toFirstMonthDay
- toFirstYearDay
- toLastIsoYearDay
- toLastIsoYearWeek
- toLastMonthDay
- toLastYearDay
- Predicates
- Setters
- setHour11
- setHour11OrThrow
- setHour23
- setHour23OrThrow
- setIsoWeek
- setIsoWeekOrThrow
- setIsoYear
- setIsoYearOrThrow
- setMeridiem
- setMillisecond
- setMillisecondOrThrow
- setMinute
- setMinuteOrThrow
- setMonth
- setMonthDay
- setMonthDayOrThrow
- setMonthOrThrow
- setOrdinalDay
- setOrdinalDayOrThrow
- setSecond
- setSecondOrThrow
- setWeekday
- setWeekdayOrThrow
- setYear
- setYearOrThrow
- setZoneOffsetKeepParts
- setZoneOffsetKeepPartsOrThrow
- setZoneOffsetKeepTimestamp
- setZoneOffsetKeepTimestampOrThrow
- Utils
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
MAX_FULL_YEAR
Maximal usable year (ECMA-262)
Signature
declare const MAX_FULL_YEAR: number
MAX_TIMESTAMP
Maximal usable timestamp (ECMA-262)
Signature
declare const MAX_TIMESTAMP: 8640000000000000
MIN_FULL_YEAR
Minimal usable year (ECMA-262)
Signature
declare const MIN_FULL_YEAR: number
MIN_TIMESTAMP
Minimal usable timestamp (ECMA-262)
Signature
declare const MIN_TIMESTAMP: number
Constructors
fromDate
Builds a MDateTime from a Javascript Date
Signature
declare const fromDate: (date: Date) => Type
fromEffectDateTime
Builds a MDateTime from an effect/DateTime.Zoned
Signature
declare const fromEffectDateTime: (date: DateTime.Zoned) => Type
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
yearandmonthare set,monthDayis taken equal to 1. - If
yearandmonthDayare set,monthis taken equal to 1. - If
yearis set and bothmonthandmonthDayare undefined, the day is taken to be the first one in the year. - If
isoYearandisoWeekare set,weekdayis taken equal to 1. - If
isoYearandweekdayare set,isoWeekis taken equal to 1. - If
isoYearis set and bothisoWeekandweekdayare undefined, the day is taken to be the first one in the iso year. - If both
yearandisoYearare 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
meridiemis set,hour11is taken equal to 0. - If
hour11is set,meridiemis taken equal to 0. - Otherwise,
meridiemandhour11are 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,zoneSecondis 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>
fromPartsOrThrow
Same as fromParts but returns directly a MDateTime or throws if it cannot be built
Signature
declare const fromPartsOrThrow: (parts: Parts) => Type
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:
zoneHourwhich must be greater than or equal to -12 and less than or equal to 14.zoneMinutewhich must be greater than or equal to 0 and less than or equal to 59.zoneSecondwhich 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>
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
now
Builds a MDateTime using Date.now() as timestamp. zoneOffset is set to 0.
Signature
declare const now: () => Type
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/dateTimeContextpair 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>>
parseOrThrow
Same as parse but throws in case of failure
Signature
declare const parseOrThrow: (
dateTimeFormat: MDateTimeFormat.Type,
dateTimeContext: MDateTimeContext.Type
) => MTypes.OneArgFunction<string, Type>
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/dateTimeContextpair 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>>
formatOrThrow
Same as format but throws in case of failure
Signature
declare const formatOrThrow: (
dateTimeFormat: MDateTimeFormat.Type,
dateTimeContext: MDateTimeContext.Type
) => MTypes.OneArgFunction<Type, string>
getHour11
Returns the hour11 of self for the given time zone
Signature
declare const getHour11: MTypes.OneArgFunction<Type, number>
getHour23
Returns the hour23 of self for the given time zone
Signature
declare const getHour23: MTypes.OneArgFunction<Type, number>
getIsoString
Returns the ISO representation of this DateTime
Signature
declare const getIsoString: (self: Type) => string
getIsoWeek
Returns the isoWeek of self for the given time zone
Signature
declare const getIsoWeek: MTypes.OneArgFunction<Type, number>
getIsoYear
Returns the isoYear of self for the given time zone
Signature
declare const getIsoYear: MTypes.OneArgFunction<Type, number>
getMeridiem
Returns the meridiem of self for the given time zone
Signature
declare const getMeridiem: MTypes.OneArgFunction<Type, 0 | 12>
getMillisecond
Returns the millisecond of self for the given time zone
Signature
declare const getMillisecond: MTypes.OneArgFunction<Type, number>
getMinute
Returns the minute of self for the given time zone
Signature
declare const getMinute: MTypes.OneArgFunction<Type, number>
getMonth
Returns the month of self for the given time zone
Signature
declare const getMonth: MTypes.OneArgFunction<Type, number>
getMonthDay
Returns the monthDay of self for the given time zone
Signature
declare const getMonthDay: MTypes.OneArgFunction<Type, number>
getOrdinalDay
Returns the ordinalDay of self for the given time zone
Signature
declare const getOrdinalDay: MTypes.OneArgFunction<Type, number>
getSecond
Returns the second of self for the given time zone
Signature
declare const getSecond: MTypes.OneArgFunction<Type, number>
getWeekday
Returns the weekday of self for the given time zone
Signature
declare const getWeekday: MTypes.OneArgFunction<Type, number>
getYear
Returns the (Gregorian) year of self for the given time zone
Signature
declare const getYear: MTypes.OneArgFunction<Type, number>
getZoneHour
Returns the hour part of the zoneOffset of self
Signature
declare const getZoneHour: MTypes.OneArgFunction<Type, number>
getZoneMinute
Returns the minute part of the zoneOffset of self
Signature
declare const getZoneMinute: MTypes.OneArgFunction<Type, number>
getZoneSecond
Returns the second part of the zoneOffset of self
Signature
declare const getZoneSecond: MTypes.OneArgFunction<Type, number>
Equivalences
equivalence
Equivalence
Signature
declare const equivalence: Equivalence.Equivalence<Type>
Getters
gregorianDate
Returns the gregorianDate property of self
Signature
declare const gregorianDate: MTypes.OneArgFunction<Type, GregorianDate.Type>
isoDate
Returns the isoDate property of self
Signature
declare const isoDate: MTypes.OneArgFunction<Type, IsoDate.Type>
time
Returns the time property of self
Signature
declare const time: MTypes.OneArgFunction<Type, Time.Type>
timestamp
Returns the timestamp property of self as a number
Signature
declare const timestamp: MTypes.OneArgFunction<Type, number>
zoneOffsetParts
Returns the zoneOffsetParts property of self
Signature
declare const zoneOffsetParts: MTypes.OneArgFunction<Type, ZoneOffsetParts.Type>
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
}
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
})
}
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
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
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:
zoneHourwhich must be greater than or equal to -12 and less than or equal to 14.zoneMinutewhich must be greater than or equal to 0 and less than or equal to 59.zoneSecondwhich 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>
now (static method)
Builds a MDateTime using Date.now() as timestamp. zoneOffset is set to 0.
Signature
declare const now: () => Type
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
yearandmonthare set,monthDayis taken equal to 1. - If
yearandmonthDayare set,monthis taken equal to 1. - If
yearis set and bothmonthandmonthDayare undefined, the day is taken to be the first one in the year. - If
isoYearandisoWeekare set,weekdayis taken equal to 1. - If
isoYearandweekdayare set,isoWeekis taken equal to 1. - If
isoYearis set and bothisoWeekandweekdayare undefined, the day is taken to be the first one in the iso year. - If both
yearandisoYearare 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
meridiemis set,hour11is taken equal to 0. - If
hour11is set,meridiemis taken equal to 0. - Otherwise,
meridiemandhour11are 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,zoneSecondis 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>
[MData.idSymbol] (method)
Returns the id of this
Signature
declare const [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
declare const _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
declare const _setZoneOffset: (
keepTimestamp: boolean,
zoneOffset?: number | { readonly zoneHour: number; readonly zoneMinute: number; readonly zoneSecond: number }
) => Result.Result<Type, MInputError.Type>
_setGregorianDate (method)
Returns a copy of this with _gregorianDate set to gregorianDate
Signature
declare const _setGregorianDate: (gregorianDate: GregorianDate.Type) => Type
_setIsoDate (method)
Returns a copy of this with isoDate set to isoDate
Signature
declare const _setIsoDate: (isoDate: IsoDate.Type) => Type
_setTime (method)
Returns a copy of this with time set to time
Signature
declare const _setTime: (time: Time.Type) => Type
[Hash.symbol] (method)
Calculates the hash value of this
Signature
declare const [Hash.symbol]: () => number
[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
Function that implements the equivalence of this and that
Signature
declare const [MEquivalenceBasedEqualityData.isEquivalentToSymbol]: (this: this, that: this) => boolean
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
Predicate that returns true if that has the same type marker as this
Signature
declare const [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
declare const moduleTag: "@parischap/effect-lib/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
declare const offsetDays: (offset: number) => MTypes.OneArgFunction<Type, Result.Result<Type, MInputError.Type>>
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>>
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>>
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>>
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>
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>
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>
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>>
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>>
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>>
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>
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>
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>>
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>>
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>>
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>
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>
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>
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
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
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
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
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
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>
isFirstMonthDay
Returns true if self is the first day of a month in the given timezone
Signature
declare const isFirstMonthDay: Predicate.Predicate<Type>
isFirstYearDay
Returns true if self is the first day of a year in the given timezone
Signature
declare const isFirstYearDay: Predicate.Predicate<Type>
isLastIsoYearDay
Returns true if self is the last day of an iso year in the given timezone
Signature
declare const isLastIsoYearDay: Predicate.Predicate<Type>
isLastMonthDay
Returns true if self is the last day of a month in the given timezone
Signature
declare const isLastMonthDay: Predicate.Predicate<Type>
isLastYearDay
Returns true if self is the last day of a year in the given timezone
Signature
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
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
declare const yearIsLeap: Predicate.Predicate<Type>
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>
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>>
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>
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>>
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>
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>>
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>
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>>
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
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>
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>>
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>
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>>
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>
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>
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>>
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>>
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>
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>>
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>
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>>
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>
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>>
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>
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>>
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>
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>
>
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:
zoneHourwhich must be greater than or equal to -12 and less than or equal to 14.zoneMinutewhich must be greater than or equal to 0 and less than or equal to 59.zoneSecondwhich 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>
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>
>
Utils
toDate
Builds a Javascript Date from a MDateTime
Signature
declare const toDate: (self: Type) => Date
toEffectDateTime
Builds an effect/DateTime.Zoned from a MDateTime
Signature
declare const toEffectDateTime: (self: Type) => DateTime.Zoned