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 PlainTimeCreates 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 PlainTimeParses 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
#millisecond Source
millisecond :: PlainTime -> IntMillisecond component.
#microsecond Source
microsecond :: PlainTime -> IntMicrosecond component.
#nanosecond Source
nanosecond :: PlainTime -> IntNanosecond component.
#add Source
add :: Duration -> PlainTime -> Effect PlainTimeAdds 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 PlainTimeSubtracts 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 PlainTimeReturns 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
#until Source
until :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainTime -> PlainTime -> Effect DurationDuration 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
#since Source
since :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainTime -> PlainTime -> Effect DurationDuration 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
#round Source
round :: forall provided. ConvertOptionsWithDefaults ToRoundOptions (Record RoundOptions) (Record provided) (Record RoundOptions) => Record provided -> PlainTime -> Effect PlainTimeRounds 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
#toString Source
toString :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainTime -> StringSerializes 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
#ToOverflowOptions Source
data ToOverflowOptionsInstances
ConvertOption ToOverflowOptions "overflow" Overflow StringConvertOption ToOverflowOptions "overflow" String String
#ToDifferenceOptions Source
data ToDifferenceOptionsInstances
ConvertOption ToDifferenceOptions "largestUnit" TemporalUnit StringConvertOption ToDifferenceOptions "largestUnit" String StringConvertOption ToDifferenceOptions "smallestUnit" TemporalUnit StringConvertOption ToDifferenceOptions "smallestUnit" String StringConvertOption ToDifferenceOptions "roundingIncrement" Int IntConvertOption ToDifferenceOptions "roundingMode" RoundingMode StringConvertOption ToDifferenceOptions "roundingMode" String String
#ToRoundOptions Source
data ToRoundOptionsInstances
ConvertOption ToRoundOptions "smallestUnit" TemporalUnit StringConvertOption ToRoundOptions "smallestUnit" String StringConvertOption ToRoundOptions "roundingIncrement" Int IntConvertOption ToRoundOptions "roundingMode" RoundingMode StringConvertOption ToRoundOptions "roundingMode" String String
#ToToStringOptions Source
data ToToStringOptionsInstances
ConvertOption ToToStringOptions "fractionalSecondDigits" Int ForeignConvertOption ToToStringOptions "fractionalSecondDigits" String ForeignConvertOption ToToStringOptions "smallestUnit" TemporalUnit StringConvertOption ToToStringOptions "smallestUnit" String StringConvertOption ToToStringOptions "roundingMode" RoundingMode StringConvertOption ToToStringOptions "roundingMode" String String
Re-exports from JS.Temporal.PlainTime.Internal
- Modules
- JS.
Temporal. Duration - JS.
Temporal. Duration. Internal - JS.
Temporal. Instant - JS.
Temporal. Instant. Internal - JS.
Temporal. Internal - JS.
Temporal. Now - JS.
Temporal. Options. CalendarName - JS.
Temporal. Options. Disambiguation - JS.
Temporal. Options. OffsetDisambiguation - JS.
Temporal. Options. Overflow - JS.
Temporal. Options. RoundingMode - JS.
Temporal. Options. TemporalUnit - JS.
Temporal. PlainDate - JS.
Temporal. PlainDate. Internal - JS.
Temporal. PlainDateTime - JS.
Temporal. PlainDateTime. Internal - JS.
Temporal. PlainMonthDay - JS.
Temporal. PlainMonthDay. Internal - JS.
Temporal. PlainTime - JS.
Temporal. PlainTime. Internal - JS.
Temporal. PlainYearMonth - JS.
Temporal. PlainYearMonth. Internal - JS.
Temporal. ZonedDateTime - JS.
Temporal. ZonedDateTime. Internal