Duration
Constructors
Signature
declare function days(days: number): DurationSignature
declare function hours(hours: number): DurationSignature
declare const infinity: DurationSignature
declare function micros(micros: bigint): DurationSignature
declare function millis(millis: number): DurationSignature
declare function minutes(minutes: number): DurationSignature
declare function nanos(nanos: bigint): DurationSignature
declare function seconds(seconds: number): DurationSignature
declare function weeks(weeks: number): DurationSignature
declare const zero: DurationConversions
Converts a Duration to a human readable string.
Signature
declare function format(self: DurationInput): stringExample
import { Duration } from "effect"
Duration.format(Duration.millis(1000)) // "1s"Duration.format(Duration.millis(1001)) // "1s 1ms"Formats a Duration into an ISO8601 duration string.
Months are assumed to be 30 days and years are assumed to be 365 days.
Returns Option.none() if the duration is infinite.
Signature
declare function formatIso(self: DurationInput): Option<string>Example
import { Duration, Option } from "effect"
Duration.formatIso(Duration.days(1)) // => Option.some("P1D")Duration.formatIso(Duration.minutes(90)) // => Option.some("PT1H30M")Duration.formatIso(Duration.millis(1500)) // => Option.some("PT1.5S")Duration.formatIso(Duration.infinity) // => Option.none()Parses an ISO8601 duration string into a Duration.
Months are assumed to be 30 days and years are assumed to be 365 days.
Signature
declare function fromIso(iso: string): Option<Duration>Example
import { Duration, Option } from "effect"
Duration.fromIso("P1D") // => Option.some(Duration.days(1))Duration.fromIso("PT1H") // => Option.some(Duration.hours(1))Duration.fromIso("PT1M") // => Option.some(Duration.minutes(1))Duration.fromIso("PT1.5S") // => Option.some(Duration.seconds(1.5))Converts a Duration to its parts.
Signature
declare function parts(self: DurationInput): { days: number; hours: number; millis: number; minutes: number; nanos: number; seconds: number;}unsafeFormatIso
Formats a Duration into an ISO8601 duration string.
Months are assumed to be 30 days and years are assumed to be 365 days.
Milliseconds and nanoseconds are expressed as fractional seconds.
Signature
declare function unsafeFormatIso(self: DurationInput): stringExample
import { Duration } from "effect"
Duration.unsafeFormatIso(Duration.days(1)) // => "P1D"Duration.unsafeFormatIso(Duration.minutes(90)) // => "PT1H30M"Duration.unsafeFormatIso(Duration.millis(1500)) // => "PT1.5S"Getters
Signature
declare function toDays(self: DurationInput): numberSignature
declare function toHours(self: DurationInput): numberSignature
declare function toHrTime(self: DurationInput): [seconds: number, nanos: number]Signature
declare function toMillis(self: DurationInput): numberSignature
declare function toMinutes(self: DurationInput): numberGet the duration in nanoseconds as a bigint.
If the duration is infinite, returns Option.none()
Signature
declare function toNanos(self: DurationInput): Option<bigint>Signature
declare function toSeconds(self: DurationInput): numberSignature
declare function toWeeks(self: DurationInput): numberunsafeToNanos
Get the duration in nanoseconds as a bigint.
If the duration is infinite, it throws an error.
Signature
declare function unsafeToNanos(self: DurationInput): bigintGuards
Instances
Equivalence
Signature
declare const Equivalence: equivalence.Equivalence<Duration>Signature
declare const Order: order.Order<Duration>Math
Signature
declare const divide: { (by: number): (self: DurationInput) => Option<Duration>; (self: DurationInput, by: number): Option<Duration>;}Signature
declare const subtract: { (that: DurationInput): (self: DurationInput) => Duration; (self: DurationInput, that: DurationInput): Duration;}Signature
declare const sum: { (that: DurationInput): (self: DurationInput) => Duration; (self: DurationInput, that: DurationInput): Duration;}Signature
declare const times: { (times: number): (self: DurationInput) => Duration; (self: DurationInput, times: number): Duration;}unsafeDivide
Signature
declare const unsafeDivide: { (by: number): (self: DurationInput) => Duration; (self: DurationInput, by: number): Duration;}Models
Signature
interface Duration extends Equal, Pipeable, Inspectable { readonly [TypeId]: typeof TypeId; readonly value: DurationValue;}DurationInput type
Signature
type DurationInput = Duration | number | bigint | readonly [seconds: number, nanos: number] | `${number} ${Unit}`DurationValue type
Signature
type DurationValue = { readonly _tag: "Millis"; readonly millis: number;} | { readonly _tag: "Nanos"; readonly nanos: bigint;} | { readonly _tag: "Infinity";}Signature
type Unit = "nano" | "nanos" | "micro" | "micros" | "milli" | "millis" | "second" | "seconds" | "minute" | "minutes" | "hour" | "hours" | "day" | "days" | "week" | "weeks"Order
Signature
declare const clamp: { (options: { maximum: DurationInput; minimum: DurationInput; }): (self: DurationInput) => Duration; (self: DurationInput, options: { maximum: DurationInput; minimum: DurationInput; }): Duration;}Signature
declare const max: { (that: DurationInput): (self: DurationInput) => Duration; (self: DurationInput, that: DurationInput): Duration;}Other
Signature
declare function decode(input: DurationInput): DurationdecodeUnknown
Signature
declare const decodeUnknown: (u: unknown) => Option.Option<Duration>Signature
declare const min: { (that: DurationInput): (self: DurationInput) => Duration; (self: DurationInput, that: DurationInput): Duration;}Pattern Matching
Signature
declare const match: { <A, B>(options: { readonly onMillis: (millis: number) => A; readonly onNanos: (nanos: bigint) => B; }): (self: DurationInput) => A | B; <A, B>(self: DurationInput, options: { readonly onMillis: (millis: number) => A; readonly onNanos: (nanos: bigint) => B; }): A | B;}Signature
declare const matchWith: { <A, B>(that: DurationInput, options: { readonly onMillis: (self: number, that: number) => A; readonly onNanos: (self: bigint, that: bigint) => B; }): (self: DurationInput) => A | B; <A, B>(self: DurationInput, that: DurationInput, options: { readonly onMillis: (self: number, that: number) => A; readonly onNanos: (self: bigint, that: bigint) => B; }): A | B;}Predicates
Checks if a Duration is between a minimum and maximum value.
Signature
declare const between: { (options: { maximum: DurationInput; minimum: DurationInput; }): (self: DurationInput) => boolean; (self: DurationInput, options: { maximum: DurationInput; minimum: DurationInput; }): boolean;}Signature
declare const equals: { (that: DurationInput): (self: DurationInput) => boolean; (self: DurationInput, that: DurationInput): boolean;}greaterThan
Signature
declare const greaterThan: { (that: DurationInput): (self: DurationInput) => boolean; (self: DurationInput, that: DurationInput): boolean;}greaterThanOrEqualTo
Signature
declare const greaterThanOrEqualTo: { (that: DurationInput): (self: DurationInput) => boolean; (self: DurationInput, that: DurationInput): boolean;}Signature
declare const lessThan: { (that: DurationInput): (self: DurationInput) => boolean; (self: DurationInput, that: DurationInput): boolean;}lessThanOrEqualTo
Signature
declare const lessThanOrEqualTo: { (that: DurationInput): (self: DurationInput) => boolean; (self: DurationInput, that: DurationInput): boolean;}