Module

JS.Temporal.Duration

Package
purescript-js-temporal
Repository
pete-murphy/purescript-js-temporal

A duration representing the difference between two time points. Can be used in date/time arithmetic. Represented as years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds.

Calendar durations (years, months, weeks) require a reference date for arithmetic; use PlainDate/PlainDateTime.add/subtract for those. Non-calendar durations can be added/subtracted directly.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration

#new Source

new :: forall provided rest. Union provided rest DurationComponents => Record provided -> Effect Duration

Creates a Duration from component fields. At least one component must be provided. Mixed signs are invalid. Corresponds to Temporal.Duration().

#from Source

from :: String -> Effect Duration

Parses an ISO 8601 duration string (e.g. "PT1H30M"). Throws on invalid input. Corresponds to Temporal.Duration.from().

#milliseconds Source

#microseconds Source

#nanoseconds Source

#sign Source

sign :: Duration -> Int

Returns 1 if positive, -1 if negative, 0 if zero.

#blank Source

blank :: Duration -> Boolean

True if all components are zero.

#add Source

add :: Duration -> Duration -> Effect Duration

Adds two durations. Result is balanced to the largest unit of the inputs. Throws if either duration contains calendar units (years, months, weeks). Corresponds to Temporal.Duration.prototype.add().

#subtract Source

subtract :: Duration -> Duration -> Effect Duration

Subtracts the second duration from the first. Same balancing/constraints as add. Corresponds to Temporal.Duration.prototype.subtract().

#negated Source

negated :: Duration -> Duration

Reverses the sign of the duration. Pure, does not throw.

#abs Source

abs :: Duration -> Duration

Returns the duration with positive sign. Pure, does not throw.

#with Source

with :: forall provided rest. Union provided rest DurationComponents => Record provided -> Duration -> Effect Duration

Returns a new duration with specified fields replaced. Mixed signs invalid. Corresponds to Temporal.Duration.prototype.with().

#compare Source

compare :: Duration -> Duration -> Effect Ordering

Compares two durations. Returns LT if first is shorter, GT if longer, EQ if equal. Throws for calendar durations without relativeTo. Corresponds to Temporal.Duration.compare().

#round Source

round :: forall provided. ConvertOptionsWithDefaults ToDurationRoundOptions (Record DurationRoundOptions) (Record provided) (Record DurationRoundOptions) => Record provided -> Duration -> Effect Duration

Rounds the duration to the given smallest/largest units. Use relativeTo for calendar durations. Corresponds to Temporal.Duration.prototype.round().

#total Source

total :: forall provided. ConvertOptionsWithDefaults ToDurationTotalOptions (Record DurationTotalOptions) (Record provided) (Record DurationTotalOptions) => Record provided -> Duration -> Effect Number

Returns the total length of the duration in the given unit. Use relativeTo for calendar durations. Corresponds to Temporal.Duration.prototype.total().

#DurationRoundOptions Source

type DurationRoundOptions :: Row Typetype DurationRoundOptions = (largestUnit :: String, relativeTo :: Foreign, roundingIncrement :: Int, roundingMode :: String, smallestUnit :: String)

Options for round: largestUnit, smallestUnit, roundingIncrement, roundingMode, relativeTo (PlainDate/PlainDateTime/ZonedDateTime for calendar units).

#DurationTotalOptions Source

type DurationTotalOptions :: Row Typetype DurationTotalOptions = (relativeTo :: Foreign, unit :: String)

Options for total: unit (required), relativeTo for calendar units.

#DurationToStringOptions Source

type DurationToStringOptions :: Row Typetype DurationToStringOptions = (fractionalSecondDigits :: Foreign, smallestUnit :: String)

Options: fractionalSecondDigits, smallestUnit.

#toString Source

toString :: forall provided. ConvertOptionsWithDefaults ToDurationToStringOptions (Record DurationToStringOptions) (Record provided) (Record DurationToStringOptions) => Record provided -> Duration -> String

Serializes the duration to ISO 8601 format (e.g. "PT1H30M").

#toString_ Source

toString_ :: Duration -> String

Default ISO 8601 serialization (no options). Prefer over toString {}.

Re-exports from JS.Temporal.Duration.Internal

#Duration Source

data Duration

A Temporal duration (opaque type).

Instances