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
- Constructors
- Conversions
- Destructors
- Equivalences
- Getters
- Guards
- Models
- 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
Constants
COMMON_YEAR_MS
Duration of a normal year in milliseconds
Signature
export declare const COMMON_YEAR_MS: number
DAY_MS
Duration of a day in milliseconds
Signature
export declare const DAY_MS: number
HOUR_MS
Duration of an hour in milliseconds
Signature
export declare const HOUR_MS: number
LEAP_YEAR_MS
Duration of a leap year in milliseconds
Signature
export declare const LEAP_YEAR_MS: number
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
LONG_YEAR_MS
Duration of a long iso year in milliseconds
Signature
export declare const LONG_YEAR_MS: 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
MINUTE_MS
Duration of a minute in milliseconds
Signature
export declare const MINUTE_MS: number
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
SECOND_MS
Duration of a second in milliseconds
Signature
export declare const SECOND_MS: 1000
SHORT_YEAR_MS
Duration of a short iso year in milliseconds
Signature
export declare const SHORT_YEAR_MS: number
WEEK_MS
Duration of a week in milliseconds
Signature
export declare const WEEK_MS: 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 Right
if successful, a Left
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
andmonth
are set,monthDay
is taken equal to 1. - If
year
andmonthDay
are set,month
is taken equal to 1. - If
year
is set and bothmonth
andmonthDay
are undefined, the day is taken to be the first one in the year. - If
isoYear
andisoWeek
are set,weekday
is taken equal to 1. - If
isoYear
andweekday
are set,isoWeek
is taken equal to 1. - If
isoYear
is set and bothisoWeek
andweekday
are undefined, the day is taken to be the first one in the iso year. - If both
year
andisoYear
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
andhour11
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 to -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.
- If any of
zoneHour
,zoneMinute
,zoneSecond
, the 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: ({
year,
ordinalDay,
month,
monthDay,
isoYear,
isoWeek,
weekday,
hour23,
hour11,
meridiem,
minute,
second,
millisecond,
zoneOffset,
zoneHour,
zoneMinute,
zoneSecond
}: Parts.Type) => Either.Either<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: Parts.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 Right
if successful, a Left
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 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 }
) => Either.Either<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
Conversions
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
Destructors
getIsoString
Returns the ISO representation of this DateTime
Signature
export declare const getIsoString: (self: Type) => string
Equivalences
equivalence
Equivalence
Signature
export declare const equivalence: Equivalence.Equivalence<Type>
Getters
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>
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 minute part of the zoneOffset of self
Signature
export declare const getZoneSecond: MTypes.OneArgFunction<Type, number>
timestamp
Returns the timestamp of self
as a number
Signature
export declare const timestamp: MTypes.OneArgFunction<Type, number>
Guards
has
Type guard
Signature
export declare const has: (u: unknown) => u is Type
Models
Parts (namespace)
Namespace for the different parts of a date
Type (interface)
Type of a Parts
Signature
export interface Type {
/** 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, 12] */
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 sthe start of the current minute, range:[0, 59] */
readonly second?: number
/** Number of milliseconds, since sthe 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 (interface)
Type of a DateTime
Signature
export interface Type extends Equal.Equal, MInspectable.Type, Pipeable.Pipeable {
/** Timestamp of this DateTime (timezone-independent) */
readonly timestamp: number
/** GregorianDate of this DateTime, expressed in given timezone */
readonly gregorianDate: Option.Option<GregorianDate.Type>
/** IsoDate of this DateTime, expressed in given timezone */
readonly isoDate: Option.Option<IsoDate.Type>
/** Time of this DateTime, expressed in given timezone */
readonly time: Option.Option<Time.Type>
/**
* 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[
*/
readonly zoneOffset: number
/** ZoneOffset decomposed into its parts */
readonly zoneOffsetParts: Option.Option<ZoneOffsetParts.Type>
/** @internal */
readonly _zonedTimestamp: number
readonly [_TypeId]: _TypeId
}
Module markers
moduleTag
Module tag
Signature
export declare const moduleTag: "@parischap/conversions/DateTime/"
Offsetters
offsetDays
If possible, returns a Right
of a copy of self
offset by offset
days. Returns a Left
of an error otherwise.
Signature
export declare const offsetDays: (offset: number) => MTypes.OneArgFunction<Type, Either.Either<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>>
offsetHours
If possible, returns a Right
of a copy of self
offset by offset
hours. Returns a Left
of an error otherwise.
Signature
export declare const offsetHours: (offset: number) => MTypes.OneArgFunction<Type, Either.Either<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>>
offsetIsoYears
If possible, returns a Right
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 Left
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) => Either.Either<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 Right
of a copy of self
offset by offset
milliseconds. Returns a Left
of an error otherwise.
Signature
export declare const offsetMilliseconds: (offset: number) => (self: Type) => Either.Either<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>>
offsetMinutes
If possible, returns a Right
of a copy of self
offset by offset
minutes. Returns a Left
of an error otherwise.
Signature
export declare const offsetMinutes: (
offset: number
) => MTypes.OneArgFunction<Type, Either.Either<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>>
offsetMonths
If possible, returns a Right
of a copy of self
offset by offset
months and having the same hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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 Right
of a copy of self
offset by offset
seconds. Returns a Left
of an error otherwise.
Signature
export declare const offsetSeconds: (
offset: number
) => MTypes.OneArgFunction<Type, Either.Either<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>>
offsetYears
If possible, returns a Right
of a copy of self
offset by offset
years and having the same month
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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, Either.Either<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>
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>
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 Right of a CVDateTime
having hour11 hour11
and the same year
, ordinalDay
, meridiem
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setHour23
If possible, returns a Right
of a CVDateTime
having hour23 hour23
and the same year
, ordinalDay
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setIsoWeek
If possible, returns a Right of a CVDateTime
having isoWeek isoWeek
and the same isoYear
, weekday
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setIsoYear
If possible, returns a Right
of a CVDateTime
having isoYear isoYear
and the same isoWeek
, weekday
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
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 Right
of a CVDateTime
having millisecond millisecond
and the same year
, ordinalDay
, hour23
, minute
, second
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setMinute
If possible, returns a Right
of a CVDateTime
having minute minute
and the same year
, ordinalDay
, hour23
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setMonth
If possible, returns a Right
of a CVDateTime
having month month
and the same year
, monthDay
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<Type, MInputError.Type>
setMonthDay
If possible, returns a Right
of a CVDateTime
having monthDay monthDay
and the same year
, month
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
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>>
setOrdinalDay
If possible, returns a Right
of a CVDateTime
having ordinalDay ordinalDay
and the same year
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setSecond
If possible, returns a Right of a CVDateTime
having second second
and the same year
, ordinalDay
, hour23
, minute
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setWeekday
If possible, returns a Right
of a CVDateTime
having weekday weekday
and the same isoYear
, isoWeek
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setYear
If possible, returns a Right
of a CVDateTime
having year year
and the same month
, monthDay
, hour23
, minute
, second
, millisecond
and zoneOffset
as self
. Returns a Left
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) => Either.Either<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>>
setZoneOffsetKeepParts
If possible, returns a Right
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 }
) => MTypes.OneArgFunction<Type, Either.Either<Type, MInputError.Type>>
setZoneOffsetKeepPartsOrThrow
Same as setZoneOffsetKeepTimestamp
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>
>
setZoneOffsetKeepTimestamp
If possible, returns a Right
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 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 }
) => MTypes.OneArgFunction<Type, Either.Either<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>
>