Module

Temporal.PlainTime

Package
purescript-temporal
Repository
philippedev101/purescript-temporal

Construction, arithmetic, and inspection of PlainTime values.

A PlainTime represents 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.

Key things to know:

  • Wraps at midnight: add and subtract silently wrap past midnight. Adding 2 hours to 23:30 gives 01:30 with no overflow indication.
  • Date units ignored: if the duration passed to add/subtract contains years, months, weeks, or days, those fields are silently ignored — no error is raised.

#PlainTimeFields Source

type PlainTimeFields = { hour :: Int, microsecond :: Int, millisecond :: Int, minute :: Int, nanosecond :: Int, second :: Int }

Fields for constructing a PlainTime. All fields default to 0.

#defaultPlainTimeFields Source

defaultPlainTimeFields :: PlainTimeFields

All fields set to 0. Use record update syntax:

plainTime (defaultPlainTimeFields { hour = 14, minute = 30 })

#plainTime Source

plainTime :: PlainTimeFields -> Maybe PlainTime

Construct a PlainTime from fields. Returns Nothing if any field is out of range (hour: 0-23, minute/second: 0-59, sub-second: 0-999).

#fromString Source

fromString :: String -> Maybe PlainTime

Parse an ISO 8601 time string (e.g. "10:30:00", "14:00"). Returns Nothing for invalid strings.

#getHour Source

getHour :: PlainTime -> Int

Hour of the day (0–23).

#getMinute Source

getMinute :: PlainTime -> Int

Minute of the hour (0–59).

#getSecond Source

getSecond :: PlainTime -> Int

Second of the minute (0–59).

#getMillisecond Source

getMillisecond :: PlainTime -> Int

Millisecond (0–999).

#getMicrosecond Source

getMicrosecond :: PlainTime -> Int

Microsecond (0–999).

#getNanosecond Source

getNanosecond :: PlainTime -> Int

Nanosecond (0–999).

#with Source

with :: PlainTimeFields -> PlainTime -> Maybe PlainTime

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

#add Source

add :: Duration -> PlainTime -> PlainTime

Add a duration, wrapping at midnight. Date components (years, months, weeks, days) in the duration are silently ignored.

#subtract Source

subtract :: Duration -> PlainTime -> PlainTime

Subtract a duration, wrapping at midnight. Date components (years, months, weeks, days) in the duration are silently ignored.

#PlainTimeDiffOptions Source

type PlainTimeDiffOptions = { largestUnit :: TimeUnit, roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: TimeUnit }

Options for since and until. Default: largest unit is Hours, smallest unit is Nanoseconds.

#since Source

since :: PlainTimeDiffOptions -> PlainTime -> PlainTime -> 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 :: PlainTimeDiffOptions -> PlainTime -> PlainTime -> 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.

until opts a b == negated (since opts a b) for all a, b.

#since' Source

since' :: PlainTime -> PlainTime -> Duration

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

#until' Source

until' :: PlainTime -> PlainTime -> Duration

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

#PlainTimeRoundOptions Source

type PlainTimeRoundOptions = { roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: TimeUnit }

Options for round.

#round Source

round :: PlainTimeRoundOptions -> PlainTime -> PlainTime

Round the time to the given precision.

#toPlainDateTime Source

toPlainDateTime :: PlainDate -> PlainTime -> PlainDateTime

Combine this time with a date to produce a PlainDateTime.

#toString Source

toString :: PlainTime -> String

Serialize to an ISO 8601 time string (e.g. "10:30:00"). Trailing zero components are omitted.

Re-exports from Temporal.Internal.Types

#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

#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