Module

JS.Temporal.PlainTime

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

A wall-clock time (hour, minute, second, etc.) without date or time zone. Use for recurring times (e.g. "3:30 PM") or when combining with PlainDate.

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

#new Source

new :: forall provided rest. Union provided rest PlainTimeComponents => Record provided -> Effect PlainTime

Creates a PlainTime from component fields.

locale <- JS.Intl.Locale.new_ "en-US"
time <- PlainTime.new
  { hour: 9
  , minute: 30
  , second: 0
  }
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter time)
9:30:00 AM

#from Source

from :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> String -> Effect PlainTime

Parses a time string (e.g. "15:30:00"). Options: overflow. Throws on invalid input.

locale <- JS.Intl.Locale.new_ "en-US"
time <- PlainTime.from { overflow: Overflow.Constrain } "15:30:00"
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter time)
3:30:00 PM

#from_ Source

from_ :: String -> Effect PlainTime

Same as from with default options.

#hour Source

hour :: PlainTime -> Int

Hour component.

#minute Source

minute :: PlainTime -> Int

Minute component.

#second Source

second :: PlainTime -> Int

Second component.

#millisecond Source

millisecond :: PlainTime -> Int

Millisecond component.

#microsecond Source

microsecond :: PlainTime -> Int

Microsecond component.

#nanosecond Source

nanosecond :: PlainTime -> Int

Nanosecond component.

#add Source

add :: Duration -> PlainTime -> Effect PlainTime

Adds a duration. Wraps at 24 hours. Throws for calendar durations.

locale <- JS.Intl.Locale.new_ "en-US"
time <- PlainTime.from_ "14:30:00"
twoHours <- Duration.new { hours: 2 }
later <- PlainTime.add twoHours time
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter later)
4:30:00 PM

#subtract Source

subtract :: Duration -> PlainTime -> Effect PlainTime

Subtracts a duration. Arg order: subtract duration subject. Wraps at 24 hours.

locale <- JS.Intl.Locale.new_ "en-US"
time <- PlainTime.from_ "14:30:00"
twoHours <- Duration.new { hours: 2 }
earlier <- PlainTime.subtract twoHours time
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter earlier)
12:30:00 PM

#with Source

with :: forall optsProvided fields rest. Union fields rest WithFields => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record fields -> PlainTime -> Effect PlainTime

Returns a new PlainTime with specified fields replaced. Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
time <- PlainTime.from_ "15:30:45"
noon <- PlainTime.with { overflow: Overflow.Constrain } { hour: 12, minute: 0, second: 0 } time
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter noon)
12:00:00 PM

#with_ Source

with_ :: forall fields rest. Union fields rest WithFields => Record fields -> PlainTime -> Effect PlainTime

Same as with with default options.

#until Source

until :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainTime -> PlainTime -> Effect Duration

Duration from subject (last arg) until other (second arg). Arg order: until options other subject.

locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainTime.from_ "09:00:00"
end <- PlainTime.from_ "17:30:00"
duration <- PlainTime.until { largestUnit: TemporalUnit.Hour } end start
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log (JS.Intl.DurationFormat.format formatter duration)
8 hours, 30 minutes

#until_ Source

until_ :: PlainTime -> PlainTime -> Effect Duration

Same as until with default options.

#since Source

since :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainTime -> PlainTime -> Effect Duration

Duration from other to subject (inverse of until). Arg order: since options other subject.

locale <- JS.Intl.Locale.new_ "en-US"
earlier <- PlainTime.from_ "08:00:00"
later <- PlainTime.from_ "12:30:00"
duration <- PlainTime.since { largestUnit: TemporalUnit.Hour } earlier later
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log (JS.Intl.DurationFormat.format formatter duration)
4 hours, 30 minutes

#since_ Source

since_ :: PlainTime -> PlainTime -> Effect Duration

Same as since with default options.

#round Source

round :: forall provided. ConvertOptionsWithDefaults ToRoundOptions (Record RoundOptions) (Record provided) (Record RoundOptions) => Record provided -> PlainTime -> Effect PlainTime

Rounds the time to the given smallest unit.

locale <- JS.Intl.Locale.new_ "en-US"
time <- PlainTime.from_ "09:30:45.123"
rounded <- PlainTime.round { smallestUnit: TemporalUnit.Minute } time
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter rounded)
9:31:00 AM

#fromTime Source

fromTime :: Time -> Effect PlainTime

Converts a purescript-datetime Time to a PlainTime. Microsecond and nanosecond components are set to zero.

#toTime Source

toTime :: PlainTime -> Time

Converts a PlainTime to a purescript-datetime Time. Microsecond and nanosecond are dropped (treated as zero).

#toString Source

toString :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainTime -> String

Serializes to ISO 8601 time format. Options: fractionalSecondDigits, smallestUnit, roundingMode.

time <- PlainTime.from_ "14:30:45.123"
Console.log (PlainTime.toString { smallestUnit: TemporalUnit.Millisecond } time)
14:30:45.123

#toString_ Source

toString_ :: PlainTime -> String

Same as toString with default options.

Re-exports from JS.Temporal.PlainTime.Internal