Module

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.
  • startOfDay may 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 rules
  • overflow: how to handle out-of-range field values

#fromEpochNanoseconds Source

fromEpochNanoseconds :: BigInt -> String -> Maybe ZonedDateTime

Construct 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 ZonedDateTime

Parse 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 ZonedDateTime

Parse with explicit disambiguation options. See ZonedDateTimeFromOptions.

#getYear Source

getYear :: ZonedDateTime -> Int

Calendar year.

#getMonth Source

getMonth :: ZonedDateTime -> Int

Month of the year (1–12).

#getDay Source

getDay :: ZonedDateTime -> Int

Day of the month (1–31).

#getHour Source

getHour :: ZonedDateTime -> Int

Hour of the day (0–23).

#getMinute Source

getMinute :: ZonedDateTime -> Int

Minute of the hour (0–59).

#getSecond Source

getSecond :: ZonedDateTime -> Int

Second of the minute (0–59).

#getMillisecond Source

getMillisecond :: ZonedDateTime -> Int

Millisecond (0–999).

#getMicrosecond Source

getMicrosecond :: ZonedDateTime -> Int

Microsecond (0–999).

#getNanosecond Source

getNanosecond :: ZonedDateTime -> Int

Nanosecond (0–999).

#getDayOfWeek Source

getDayOfWeek :: ZonedDateTime -> Int

Day of the week (1 = Monday, 7 = Sunday), per ISO 8601.

#getDayOfYear Source

getDayOfYear :: ZonedDateTime -> Int

Day of the year (1–366).

#getWeekOfYear Source

getWeekOfYear :: ZonedDateTime -> Int

ISO 8601 week number (1–53).

#getYearOfWeek Source

getYearOfWeek :: ZonedDateTime -> Int

The year that corresponds to getWeekOfYear.

#getDaysInMonth Source

getDaysInMonth :: ZonedDateTime -> Int

Number of days in this month (28–31).

#getDaysInWeek Source

#getDaysInYear Source

getDaysInYear :: ZonedDateTime -> Int

Number of days in this year (365 or 366).

#getMonthsInYear Source

getMonthsInYear :: ZonedDateTime -> Int

Always 12 for the ISO calendar.

#getInLeapYear Source

getInLeapYear :: ZonedDateTime -> Boolean

Whether this year is a leap year.

#getTimeZoneId Source

getTimeZoneId :: ZonedDateTime -> String

The IANA time zone identifier (e.g. "America/New_York", "UTC").

#getOffset Source

getOffset :: ZonedDateTime -> String

The UTC offset as a string (e.g. "+00:00", "-05:00").

#getOffsetNanoseconds Source

getOffsetNanoseconds :: ZonedDateTime -> Int

The UTC offset in nanoseconds.

#getEpochMilliseconds Source

getEpochMilliseconds :: ZonedDateTime -> Number

Milliseconds since the Unix epoch. May lose sub-millisecond precision.

#getEpochNanoseconds Source

getEpochNanoseconds :: ZonedDateTime -> BigInt

Nanoseconds since the Unix epoch (full precision).

#getHoursInDay Source

getHoursInDay :: ZonedDateTime -> Number

The 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 ZonedDateTime

Create a modified copy with the given fields and disambiguation options. Returns Nothing if the result would be invalid.

#withPlainTime Source

withPlainTime :: PlainTime -> ZonedDateTime -> ZonedDateTime

Replace the time component, keeping date and timezone.

#withTimeZone Source

withTimeZone :: String -> ZonedDateTime -> ZonedDateTime

Change the time zone, preserving the exact instant. The wall-clock time will change to reflect the new timezone.

#add Source

add :: Duration -> ZonedDateTime -> Maybe ZonedDateTime

Add 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 ZonedDateTime

Subtract 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 -> Duration

since 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 -> Duration

until 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 -> Duration

since' a b — duration from b to a with default options.

#until' Source

until' :: ZonedDateTime -> ZonedDateTime -> Duration

until' 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 -> ZonedDateTime

Round the date-time to the given precision.

#startOfDay Source

startOfDay :: ZonedDateTime -> ZonedDateTime

The 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 Instant

Find 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 -> Instant

Extract the exact instant, discarding timezone information.

#toPlainDateTime Source

toPlainDateTime :: ZonedDateTime -> PlainDateTime

Extract the wall-clock date and time, discarding timezone information.

#toPlainDate Source

toPlainDate :: ZonedDateTime -> PlainDate

Extract the date component.

#toPlainTime Source

toPlainTime :: ZonedDateTime -> PlainTime

Extract the time component.

#toPlainYearMonth Source

toPlainYearMonth :: ZonedDateTime -> PlainYearMonth

Extract the year and month.

#toPlainMonthDay Source

toPlainMonthDay :: ZonedDateTime -> PlainMonthDay

Extract the month and day.

#toString Source

toString :: ZonedDateTime -> String

Serialize 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 ZonedDateTime

A 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 PlainYearMonth

A 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

#PlainTime Source

data PlainTime

A wall-clock time without a date or time zone (e.g. 10:30:00). Range: 00:00:00.000000000 to 23:59:59.999999999.

Arithmetic wraps at midnight with no overflow indication.

Instances

#PlainMonthDay Source

data PlainMonthDay

A month and day without a year component (e.g. 12-25).

Useful for recurring annual dates like birthdays or holidays.

Instances

#PlainDateTime Source

data PlainDateTime

A 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

#PlainDate Source

data PlainDate

A calendar date without a time component or time zone (e.g. 2024-03-15).

Use PlainDate for birthdays, holidays, and other dates where time of day is irrelevant. Do not use for scheduling events — use ZonedDateTime instead.

Instances

#Instant Source

data Instant

An 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 Duration

A 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 }.

Instances