Temporal.PlainDate
- Package
- purescript-temporal
- Repository
- philippedev101/purescript-temporal
Construction, arithmetic, and inspection of PlainDate values.
A PlainDate represents a calendar date without a time component or time
zone (e.g. 2024-03-15).
Key things to know:
- Default overflow is constrain:
plainDate 2024 2 31silently produces February 29 (clamped), notNothing. UseplainDateWith Rejectfor strict validation. - Arithmetic order matters: when adding a multi-component duration,
fields are applied in order (years, then months, then weeks+days) with
clamping after each step.
add { months: 1, days: 31 }on Jan 31 gives Mar 31 (Jan 31 + 1 month = Feb 28, + 31 days = Mar 31), which differs from adding months and days in separate steps.
#plainDate Source
plainDate :: Int -> Int -> Int -> Maybe PlainDateConstruct a PlainDate from year, month, and day. Out-of-range days are
constrained (clamped) to the nearest valid value. For example,
plainDate 2024 2 31 yields February 29 (2024 is a leap year).
Returns Nothing only for truly invalid values (e.g. month 13).
Use plainDateWith Reject if you want strict validation.
#fromString Source
fromString :: String -> Maybe PlainDateParse an ISO 8601 date string (e.g. "2024-03-15").
Returns Nothing for invalid strings.
#getDayOfWeek Source
getDayOfWeek :: PlainDate -> IntDay of the week (1 = Monday, 7 = Sunday), per ISO 8601.
#getDayOfYear Source
getDayOfYear :: PlainDate -> IntDay of the year (1–366).
#getWeekOfYear Source
getWeekOfYear :: PlainDate -> IntISO 8601 week number (1–53).
#getYearOfWeek Source
getYearOfWeek :: PlainDate -> IntThe year that corresponds to getWeekOfYear. May differ from getYear
at year boundaries (e.g. Dec 31 may be in week 1 of the next year).
#getDaysInMonth Source
getDaysInMonth :: PlainDate -> IntNumber of days in this date's month (28–31).
#getDaysInWeek Source
getDaysInWeek :: PlainDate -> IntAlways 7.
#getDaysInYear Source
getDaysInYear :: PlainDate -> IntNumber of days in this date's year (365 or 366).
#getMonthsInYear Source
getMonthsInYear :: PlainDate -> IntAlways 12 for the ISO calendar.
#getInLeapYear Source
getInLeapYear :: PlainDate -> BooleanWhether this date's year is a leap year.
#PlainDateDiffOptions Source
type PlainDateDiffOptions = { largestUnit :: DateTimeUnit, roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: DateTimeUnit }Options for since and until. Default: largest unit is Years,
smallest unit is Days.
#since Source
since :: PlainDateDiffOptions -> PlainDate -> PlainDate -> 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 :: PlainDateDiffOptions -> PlainDate -> PlainDate -> 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.
#toPlainDateTime Source
toPlainDateTime :: PlainTime -> PlainDate -> PlainDateTimeCombine this date with a time to produce a PlainDateTime.
#toPlainYearMonth Source
toPlainYearMonth :: PlainDate -> PlainYearMonthDrop the day component, keeping year and month.
#toPlainMonthDay Source
toPlainMonthDay :: PlainDate -> PlainMonthDayDrop the year component, keeping month and day.
#toZonedDateTime Source
toZonedDateTime :: String -> PlainTime -> PlainDate -> ZonedDateTimeCombine this date with a time and IANA time zone to produce a
ZonedDateTime. DST disambiguation uses the default "compatible" mode.
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 }.