Temporal.ZonedDateTime
- Package
- purescript-temporal
- Repository
- philippedev101/purescript-temporal
Construction, arithmetic, and inspection of ZonedDateTime values.
A ZonedDateTime represents a date and time in a specific IANA time zone,
with full awareness of UTC offset and DST transitions. It is the richest
Temporal type.
Key things to know:
- DST disambiguation: when constructing from wall-clock time, the
default
"compatible"mode picks the later time for gaps (spring forward) and the earlier time for ambiguities (fall back). - Arithmetic splits date and time: date components (years, months, days) are added as calendar arithmetic (wall-clock time preserved), while time components (hours, minutes, ...) are added as real elapsed time. Date components are processed first.
startOfDaymay not be midnight: in time zones where DST transitions occur at midnight (e.g. historically in Brazil), the start of day can be 01:00 or another time.- Eq compares instant + timezone: two
ZonedDateTimes with the same instant but different time zones are not equal.
#ZonedDateTimeFromOptions Source
type ZonedDateTimeFromOptions = { disambiguation :: Disambiguation, offset :: OffsetDisambiguation, overflow :: Overflow }Options controlling how ambiguous inputs are resolved during construction.
disambiguation: how to handle wall-clock times that don't exist (spring forward) or are ambiguous (fall back)offset: how to handle conflicts between an explicit UTC offset and the IANA timezone rulesoverflow: how to handle out-of-range field values
#fromEpochNanoseconds Source
fromEpochNanoseconds :: BigInt -> String -> Maybe ZonedDateTimeConstruct from nanoseconds since the Unix epoch and an IANA time zone name.
Returns Nothing for invalid time zones or out-of-range epoch values.
#fromString Source
fromString :: String -> Maybe ZonedDateTimeParse a string with timezone annotation
(e.g. "2024-03-15T10:30:00+00:00[UTC]").
Returns Nothing for invalid strings.
The UTC offset in the string is validated against the timezone rules.
If the offset is inconsistent with the IANA timezone at that instant
(e.g. due to changed DST rules), parsing fails. Use fromStringWith with
offset: Ignore to handle strings where timezone rules may have changed.
#fromStringWith Source
fromStringWith :: ZonedDateTimeFromOptions -> String -> Maybe ZonedDateTimeParse with explicit disambiguation options. See ZonedDateTimeFromOptions.
#getYear Source
getYear :: ZonedDateTime -> IntCalendar year.
#getMonth Source
getMonth :: ZonedDateTime -> IntMonth of the year (1–12).
#getDay Source
getDay :: ZonedDateTime -> IntDay of the month (1–31).
#getHour Source
getHour :: ZonedDateTime -> IntHour of the day (0–23).
#getMinute Source
getMinute :: ZonedDateTime -> IntMinute of the hour (0–59).
#getSecond Source
getSecond :: ZonedDateTime -> IntSecond of the minute (0–59).
#getMillisecond Source
getMillisecond :: ZonedDateTime -> IntMillisecond (0–999).
#getMicrosecond Source
getMicrosecond :: ZonedDateTime -> IntMicrosecond (0–999).
#getNanosecond Source
getNanosecond :: ZonedDateTime -> IntNanosecond (0–999).
#getDayOfWeek Source
getDayOfWeek :: ZonedDateTime -> IntDay of the week (1 = Monday, 7 = Sunday), per ISO 8601.
#getDayOfYear Source
getDayOfYear :: ZonedDateTime -> IntDay of the year (1–366).
#getWeekOfYear Source
getWeekOfYear :: ZonedDateTime -> IntISO 8601 week number (1–53).
#getYearOfWeek Source
getYearOfWeek :: ZonedDateTime -> IntThe year that corresponds to getWeekOfYear.
#getDaysInMonth Source
getDaysInMonth :: ZonedDateTime -> IntNumber of days in this month (28–31).
#getDaysInWeek Source
getDaysInWeek :: ZonedDateTime -> IntAlways 7.
#getDaysInYear Source
getDaysInYear :: ZonedDateTime -> IntNumber of days in this year (365 or 366).
#getMonthsInYear Source
getMonthsInYear :: ZonedDateTime -> IntAlways 12 for the ISO calendar.
#getInLeapYear Source
getInLeapYear :: ZonedDateTime -> BooleanWhether this year is a leap year.
#getTimeZoneId Source
getTimeZoneId :: ZonedDateTime -> StringThe IANA time zone identifier (e.g. "America/New_York", "UTC").
#getOffset Source
getOffset :: ZonedDateTime -> StringThe UTC offset as a string (e.g. "+00:00", "-05:00").
#getOffsetNanoseconds Source
getOffsetNanoseconds :: ZonedDateTime -> IntThe UTC offset in nanoseconds.
#getEpochMilliseconds Source
getEpochMilliseconds :: ZonedDateTime -> NumberMilliseconds since the Unix epoch. May lose sub-millisecond precision.
#getEpochNanoseconds Source
getEpochNanoseconds :: ZonedDateTime -> BigIntNanoseconds since the Unix epoch (full precision).
#getHoursInDay Source
getHoursInDay :: ZonedDateTime -> NumberThe number of real-world hours in this calendar day, accounting for DST. Usually 24, but can be 23 or 25 during DST transitions.
#with Source
with :: ZonedDateTimeFromOptions -> ZonedDateTimeWithFields -> ZonedDateTime -> Maybe ZonedDateTimeCreate a modified copy with the given fields and disambiguation options.
Returns Nothing if the result would be invalid.
#withPlainTime Source
withPlainTime :: PlainTime -> ZonedDateTime -> ZonedDateTimeReplace the time component, keeping date and timezone.
#withTimeZone Source
withTimeZone :: String -> ZonedDateTime -> ZonedDateTimeChange the time zone, preserving the exact instant. The wall-clock time will change to reflect the new timezone.
#add Source
add :: Duration -> ZonedDateTime -> Maybe ZonedDateTimeAdd a duration. Date components are added as calendar arithmetic
(wall-clock time preserved), then time components as real elapsed time.
Returns Nothing on overflow.
#subtract Source
subtract :: Duration -> ZonedDateTime -> Maybe ZonedDateTimeSubtract a duration. Same semantics as add.
#ZonedDateTimeDiffOptions Source
type ZonedDateTimeDiffOptions = { largestUnit :: DateTimeUnit, roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: DateTimeUnit }Options for since and until. Default: largest unit is Years,
smallest unit is Nanoseconds.
#since Source
since :: ZonedDateTimeDiffOptions -> ZonedDateTime -> ZonedDateTime -> Durationsince opts a b returns the duration from b to a
(i.e., a.since(b) in JS). The result is positive when a is after b.
#until Source
until :: ZonedDateTimeDiffOptions -> ZonedDateTime -> ZonedDateTime -> Durationuntil opts a b returns the duration from a to b
(i.e., a.until(b) in JS). The result is positive when b is after a.
#since' Source
since' :: ZonedDateTime -> ZonedDateTime -> Durationsince' a b — duration from b to a with default options.
#until' Source
until' :: ZonedDateTime -> ZonedDateTime -> Durationuntil' a b — duration from a to b with default options.
#ZonedDateTimeRoundOptions Source
type ZonedDateTimeRoundOptions = { roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: DateTimeUnit }Options for round.
#round Source
round :: ZonedDateTimeRoundOptions -> ZonedDateTime -> ZonedDateTimeRound the date-time to the given precision.
#startOfDay Source
startOfDay :: ZonedDateTime -> ZonedDateTimeThe first instant of the calendar day in this time zone. Usually midnight, but may be a later time in zones where DST transitions occur at midnight.
#getTimeZoneTransition Source
getTimeZoneTransition :: TransitionDirection -> ZonedDateTime -> Maybe InstantFind the next or previous UTC offset transition (DST change) from this
instant. Returns Nothing if there is no transition in the given
direction (e.g. for fixed-offset zones like UTC).
#toInstant Source
toInstant :: ZonedDateTime -> InstantExtract the exact instant, discarding timezone information.
#toPlainDateTime Source
toPlainDateTime :: ZonedDateTime -> PlainDateTimeExtract the wall-clock date and time, discarding timezone information.
#toPlainDate Source
toPlainDate :: ZonedDateTime -> PlainDateExtract the date component.
#toPlainTime Source
toPlainTime :: ZonedDateTime -> PlainTimeExtract the time component.
#toPlainYearMonth Source
toPlainYearMonth :: ZonedDateTime -> PlainYearMonthExtract the year and month.
#toPlainMonthDay Source
toPlainMonthDay :: ZonedDateTime -> PlainMonthDayExtract the month and day.
#toString Source
toString :: ZonedDateTime -> StringSerialize to an ISO 8601 string with offset and timezone annotation
(e.g. "2024-03-15T10:30:00-04:00[America/New_York]").
Re-exports from Temporal.Internal.Types
#ZonedDateTime Source
data ZonedDateTimeA date and time in a specific time zone, with full awareness of UTC offset and DST transitions (e.g. 2024-03-15T10:30:00-04:00[America/New_York]).
This is the richest Temporal type. Use it for scheduling future events
where wall-clock time should be preserved even if DST rules change.
For past events or timestamps, Instant is usually sufficient.
Instances
#PlainYearMonth Source
data PlainYearMonthA year and month without a day component (e.g. 2024-03).
Useful for representing months in a calendar UI or credit card expiry dates.
Instances
#PlainMonthDay Source
data PlainMonthDayA month and day without a year component (e.g. 12-25).
Useful for recurring annual dates like birthdays or holidays.
Instances
#PlainDateTime Source
data PlainDateTimeA calendar date and wall-clock time without a time zone (e.g. 2024-03-15T10:30:00).
Use PlainDateTime for events whose time zone is tracked separately,
or for wall-clock displays. For unambiguous moments in time, use Instant
or ZonedDateTime instead.
Instances
#Instant Source
data InstantAn exact moment on the UTC timeline with nanosecond precision, independent of any time zone or calendar.
Use Instant for timestamps, event logs, and any case where you need
an unambiguous point in time. Convert to ZonedDateTime when you need
wall-clock representation in a specific time zone.
Instances
#Duration Source
data DurationA length of time expressed as a combination of date and time components (years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds). All components must share the same sign.
Durations are unbalanced — { hours: 36 } is not automatically
converted to { days: 1, hours: 12 }. Use round to balance.
Eq compares component-by-component (not total elapsed time), so
{ hours: 1 } is not equal to { minutes: 60 }.