Module

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 31 silently produces February 29 (clamped), not Nothing. Use plainDateWith Reject for 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.

#PlainDateFields Source

type PlainDateFields = { day :: Int, month :: Int, year :: Int }

#plainDate Source

plainDate :: Int -> Int -> Int -> Maybe PlainDate

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

#plainDateWith Source

plainDateWith :: Overflow -> Int -> Int -> Int -> Maybe PlainDate

Construct a PlainDate with explicit overflow handling.

  • Constrain: clamp out-of-range values (default Temporal behavior)
  • Reject: return Nothing for any out-of-range value

#fromString Source

fromString :: String -> Maybe PlainDate

Parse an ISO 8601 date string (e.g. "2024-03-15"). Returns Nothing for invalid strings.

#getYear Source

getYear :: PlainDate -> Int

Calendar year (e.g. 2024). Can be negative for BCE dates.

#getMonth Source

getMonth :: PlainDate -> Int

Month of the year (1–12).

#getDay Source

getDay :: PlainDate -> Int

Day of the month (1–31).

#getDayOfWeek Source

getDayOfWeek :: PlainDate -> Int

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

#getDayOfYear Source

getDayOfYear :: PlainDate -> Int

Day of the year (1–366).

#getWeekOfYear Source

getWeekOfYear :: PlainDate -> Int

ISO 8601 week number (1–53).

#getYearOfWeek Source

getYearOfWeek :: PlainDate -> Int

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

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

#getDaysInWeek Source

getDaysInWeek :: PlainDate -> Int

Always 7.

#getDaysInYear Source

getDaysInYear :: PlainDate -> Int

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

#getMonthsInYear Source

getMonthsInYear :: PlainDate -> Int

Always 12 for the ISO calendar.

#getInLeapYear Source

getInLeapYear :: PlainDate -> Boolean

Whether this date's year is a leap year.

#with Source

with :: Overflow -> PlainDateFields -> PlainDate -> Maybe PlainDate

Create a modified copy with the given fields. The Overflow option controls how out-of-range values are handled.

#add Source

add :: Duration -> PlainDate -> Maybe PlainDate

Add a duration to this date. Returns Nothing on overflow. Time components of the duration are ignored.

#subtract Source

subtract :: Duration -> PlainDate -> Maybe PlainDate

Subtract a duration from this date. Returns Nothing on overflow. Time components of the duration are ignored.

#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 -> 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 :: PlainDateDiffOptions -> PlainDate -> PlainDate -> 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' :: PlainDate -> PlainDate -> Duration

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

#until' Source

until' :: PlainDate -> PlainDate -> Duration

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

#toPlainDateTime Source

toPlainDateTime :: PlainTime -> PlainDate -> PlainDateTime

Combine this date with a time to produce a PlainDateTime.

#toPlainYearMonth Source

toPlainYearMonth :: PlainDate -> PlainYearMonth

Drop the day component, keeping year and month.

#toPlainMonthDay Source

toPlainMonthDay :: PlainDate -> PlainMonthDay

Drop the year component, keeping month and day.

#toZonedDateTime Source

toZonedDateTime :: String -> PlainTime -> PlainDate -> ZonedDateTime

Combine this date with a time and IANA time zone to produce a ZonedDateTime. DST disambiguation uses the default "compatible" mode.

#toString Source

toString :: PlainDate -> String

Serialize to an ISO 8601 date string (e.g. "2024-03-15").

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

#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