Temporal.PlainDateTime
- Package
- purescript-temporal
- Repository
- philippedev101/purescript-temporal
Construction, arithmetic, and inspection of PlainDateTime values.
A PlainDateTime represents a calendar date and wall-clock time without a
time zone (e.g. 2024-03-15T10:30:00). It combines the semantics of
PlainDate and PlainTime.
Use PlainDateTime when you need date+time but the time zone is tracked
separately or is irrelevant. For unambiguous moments in time, use Instant
or ZonedDateTime.
#defaultPlainDateTimeFields Source
defaultPlainDateTimeFields :: PlainDateTimeFieldsDefault fields: 0000-01-01T00:00:00.000000000. Use record update syntax:
plainDateTime (defaultPlainDateTimeFields { year = 2024, month = 3, day = 15, hour = 10 })
#plainDateTime Source
plainDateTime :: PlainDateTimeFields -> Maybe PlainDateTimeConstruct a PlainDateTime from fields. Returns Nothing for invalid values.
#fromString Source
fromString :: String -> Maybe PlainDateTimeParse an ISO 8601 date-time string (e.g. "2024-03-15T10:30:00").
Returns Nothing for invalid strings. Time zone information, if present,
is ignored.
#getYear Source
getYear :: PlainDateTime -> IntCalendar year.
#getMonth Source
getMonth :: PlainDateTime -> IntMonth of the year (1–12).
#getDay Source
getDay :: PlainDateTime -> IntDay of the month (1–31).
#getHour Source
getHour :: PlainDateTime -> IntHour of the day (0–23).
#getMinute Source
getMinute :: PlainDateTime -> IntMinute of the hour (0–59).
#getSecond Source
getSecond :: PlainDateTime -> IntSecond of the minute (0–59).
#getMillisecond Source
getMillisecond :: PlainDateTime -> IntMillisecond (0–999).
#getMicrosecond Source
getMicrosecond :: PlainDateTime -> IntMicrosecond (0–999).
#getNanosecond Source
getNanosecond :: PlainDateTime -> IntNanosecond (0–999).
#getDayOfWeek Source
getDayOfWeek :: PlainDateTime -> IntDay of the week (1 = Monday, 7 = Sunday), per ISO 8601.
#getDayOfYear Source
getDayOfYear :: PlainDateTime -> IntDay of the year (1–366).
#getWeekOfYear Source
getWeekOfYear :: PlainDateTime -> IntISO 8601 week number (1–53).
#getYearOfWeek Source
getYearOfWeek :: PlainDateTime -> IntThe year that corresponds to getWeekOfYear.
#getDaysInMonth Source
getDaysInMonth :: PlainDateTime -> IntNumber of days in this date-time's month (28–31).
#getDaysInWeek Source
getDaysInWeek :: PlainDateTime -> IntAlways 7.
#getDaysInYear Source
getDaysInYear :: PlainDateTime -> IntNumber of days in this date-time's year (365 or 366).
#getMonthsInYear Source
getMonthsInYear :: PlainDateTime -> IntAlways 12 for the ISO calendar.
#getInLeapYear Source
getInLeapYear :: PlainDateTime -> BooleanWhether this date-time's year is a leap year.
#with Source
with :: PlainDateTimeFields -> PlainDateTime -> Maybe PlainDateTimeCreate a modified copy with the given fields. Returns Nothing if the
resulting date-time would be invalid.
#withPlainTime Source
withPlainTime :: PlainTime -> PlainDateTime -> PlainDateTimeReplace the time component, keeping the date.
#add Source
add :: Duration -> PlainDateTime -> Maybe PlainDateTimeAdd a duration. Returns Nothing on overflow.
#subtract Source
subtract :: Duration -> PlainDateTime -> Maybe PlainDateTimeSubtract a duration. Returns Nothing on overflow.
#PlainDateTimeDiffOptions Source
type PlainDateTimeDiffOptions = { 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 :: PlainDateTimeDiffOptions -> PlainDateTime -> PlainDateTime -> 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 :: PlainDateTimeDiffOptions -> PlainDateTime -> PlainDateTime -> 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' :: PlainDateTime -> PlainDateTime -> Durationsince' a b — duration from b to a with default options.
#until' Source
until' :: PlainDateTime -> PlainDateTime -> Durationuntil' a b — duration from a to b with default options.
#PlainDateTimeRoundOptions Source
type PlainDateTimeRoundOptions = { roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: DateTimeUnit }Options for round.
#round Source
round :: PlainDateTimeRoundOptions -> PlainDateTime -> PlainDateTimeRound the date-time to the given precision.
#toPlainDate Source
toPlainDate :: PlainDateTime -> PlainDateExtract the date component.
#toPlainTime Source
toPlainTime :: PlainDateTime -> PlainTimeExtract the time component.
#toPlainYearMonth Source
toPlainYearMonth :: PlainDateTime -> PlainYearMonthExtract the year and month.
#toPlainMonthDay Source
toPlainMonthDay :: PlainDateTime -> PlainMonthDayExtract the month and day.
#toZonedDateTime Source
toZonedDateTime :: String -> Disambiguation -> PlainDateTime -> ZonedDateTimeConvert to a ZonedDateTime in the given IANA time zone.
The Disambiguation option controls how ambiguous or non-existent
wall-clock times (during DST transitions) are resolved:
Compatible(recommended default): acts likeLaterfor gaps (spring forward) andEarlierfor ambiguities (fall back)Earlier: pick the earlier of two possible instantsLater: pick the later of two possible instantsRejectDisambiguation: return the result but may be unpredictable
#toString Source
toString :: PlainDateTime -> StringSerialize to an ISO 8601 string (e.g. "2024-03-15T10:30:00").
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
#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 }.