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:
addandsubtractsilently 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/subtractcontains years, months, weeks, or days, those fields are silently ignored — no error is raised.
#defaultPlainTimeFields Source
defaultPlainTimeFields :: PlainTimeFieldsAll fields set to 0. Use record update syntax:
plainTime (defaultPlainTimeFields { hour = 14, minute = 30 })
#plainTime Source
plainTime :: PlainTimeFields -> Maybe PlainTimeConstruct 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 PlainTimeParse an ISO 8601 time string (e.g. "10:30:00", "14:00").
Returns Nothing for invalid strings.
#getMillisecond Source
getMillisecond :: PlainTime -> IntMillisecond (0–999).
#getMicrosecond Source
getMicrosecond :: PlainTime -> IntMicrosecond (0–999).
#getNanosecond Source
getNanosecond :: PlainTime -> IntNanosecond (0–999).
#with Source
with :: PlainTimeFields -> PlainTime -> Maybe PlainTimeCreate a modified copy with the given fields. Returns Nothing if the
resulting time would be invalid.
#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 -> 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 :: PlainTimeDiffOptions -> PlainTime -> PlainTime -> 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.
until opts a b == negated (since opts a b) for all a, b.
#PlainTimeRoundOptions Source
type PlainTimeRoundOptions = { roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: TimeUnit }Options for round.
#round Source
round :: PlainTimeRoundOptions -> PlainTime -> PlainTimeRound the time to the given precision.
#toPlainDateTime Source
toPlainDateTime :: PlainDate -> PlainTime -> PlainDateTimeCombine this time with a date to produce a PlainDateTime.
Re-exports from Temporal.Internal.Types
#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 }.