Module

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.

#PlainDateTimeFields Source

type PlainDateTimeFields = { day :: Int, hour :: Int, microsecond :: Int, millisecond :: Int, minute :: Int, month :: Int, nanosecond :: Int, second :: Int, year :: Int }

All fields of a PlainDateTime. Date fields default to year 0, month 1, day 1. Time fields default to 0.

#defaultPlainDateTimeFields Source

defaultPlainDateTimeFields :: PlainDateTimeFields

Default 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 PlainDateTime

Construct a PlainDateTime from fields. Returns Nothing for invalid values.

#fromString Source

fromString :: String -> Maybe PlainDateTime

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

Calendar year.

#getMonth Source

getMonth :: PlainDateTime -> Int

Month of the year (1–12).

#getDay Source

getDay :: PlainDateTime -> Int

Day of the month (1–31).

#getHour Source

getHour :: PlainDateTime -> Int

Hour of the day (0–23).

#getMinute Source

getMinute :: PlainDateTime -> Int

Minute of the hour (0–59).

#getSecond Source

getSecond :: PlainDateTime -> Int

Second of the minute (0–59).

#getMillisecond Source

getMillisecond :: PlainDateTime -> Int

Millisecond (0–999).

#getMicrosecond Source

getMicrosecond :: PlainDateTime -> Int

Microsecond (0–999).

#getNanosecond Source

getNanosecond :: PlainDateTime -> Int

Nanosecond (0–999).

#getDayOfWeek Source

getDayOfWeek :: PlainDateTime -> Int

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

#getDayOfYear Source

getDayOfYear :: PlainDateTime -> Int

Day of the year (1–366).

#getWeekOfYear Source

getWeekOfYear :: PlainDateTime -> Int

ISO 8601 week number (1–53).

#getYearOfWeek Source

getYearOfWeek :: PlainDateTime -> Int

The year that corresponds to getWeekOfYear.

#getDaysInMonth Source

getDaysInMonth :: PlainDateTime -> Int

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

#getDaysInWeek Source

#getDaysInYear Source

getDaysInYear :: PlainDateTime -> Int

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

#getMonthsInYear Source

getMonthsInYear :: PlainDateTime -> Int

Always 12 for the ISO calendar.

#getInLeapYear Source

getInLeapYear :: PlainDateTime -> Boolean

Whether this date-time's year is a leap year.

#with Source

with :: PlainDateTimeFields -> PlainDateTime -> Maybe PlainDateTime

Create a modified copy with the given fields. Returns Nothing if the resulting date-time would be invalid.

#withPlainTime Source

withPlainTime :: PlainTime -> PlainDateTime -> PlainDateTime

Replace the time component, keeping the date.

#add Source

add :: Duration -> PlainDateTime -> Maybe PlainDateTime

Add a duration. Returns Nothing on overflow.

#subtract Source

subtract :: Duration -> PlainDateTime -> Maybe PlainDateTime

Subtract 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 -> 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 :: PlainDateTimeDiffOptions -> PlainDateTime -> PlainDateTime -> 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' :: PlainDateTime -> PlainDateTime -> Duration

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

#until' Source

until' :: PlainDateTime -> PlainDateTime -> Duration

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

Round the date-time to the given precision.

#toPlainDate Source

toPlainDate :: PlainDateTime -> PlainDate

Extract the date component.

#toPlainTime Source

toPlainTime :: PlainDateTime -> PlainTime

Extract the time component.

#toPlainYearMonth Source

toPlainYearMonth :: PlainDateTime -> PlainYearMonth

Extract the year and month.

#toPlainMonthDay Source

toPlainMonthDay :: PlainDateTime -> PlainMonthDay

Extract the month and day.

#toZonedDateTime Source

toZonedDateTime :: String -> Disambiguation -> PlainDateTime -> ZonedDateTime

Convert 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 like Later for gaps (spring forward) and Earlier for ambiguities (fall back)
  • Earlier: pick the earlier of two possible instants
  • Later: pick the later of two possible instants
  • RejectDisambiguation: return the result but may be unpredictable

#toString Source

toString :: PlainDateTime -> String

Serialize to an ISO 8601 string (e.g. "2024-03-15T10:30:00").

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