Skip to content

Duration

52 exports Added in v2.0.0 Source

Constructors

days

Added in v2.0.0 Source

Signature

declare function days(days: number): Duration;

hours

Added in v2.0.0 Source

Signature

declare function hours(hours: number): Duration;

infinity

Added in v2.0.0 Source

Signature

declare const infinity: Duration;

micros

Added in v2.0.0 Source

Signature

declare function micros(micros: bigint): Duration;

millis

Added in v2.0.0 Source

Signature

declare function millis(millis: number): Duration;

minutes

Added in v2.0.0 Source

Signature

declare function minutes(minutes: number): Duration;

nanos

Added in v2.0.0 Source

Signature

declare function nanos(nanos: bigint): Duration;

seconds

Added in v2.0.0 Source

Signature

declare function seconds(seconds: number): Duration;

weeks

Added in v2.0.0 Source

Signature

declare function weeks(weeks: number): Duration;

zero

Added in v2.0.0 Source

Signature

declare const zero: Duration;

Conversions

format

Added in v2.0.0 Source

Converts a Duration to a human readable string.

Signature

declare function format(self: DurationInput): string;

formatIso

Added in v3.13.0 Source

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>;

fromIso

Added in v3.13.0 Source

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>;

parts

Added in v3.8.0 Source

Converts a Duration to its parts.

Signature

declare function parts(self: DurationInput): {
  days: number;
  hours: number;
  millis: number;
  minutes: number;
  nanos: number;
  seconds: number;
};

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): string;

Getters

toDays

Added in v3.8.0 Source

Signature

declare function toDays(self: DurationInput): number;

toHours

Added in v3.8.0 Source

Signature

declare function toHours(self: DurationInput): number;

toHrTime

Added in v2.0.0 Source

Signature

declare function toHrTime(self: DurationInput): [seconds: number, nanos: number];

toMillis

Added in v2.0.0 Source

Signature

declare function toMillis(self: DurationInput): number;

toMinutes

Added in v3.8.0 Source

Signature

declare function toMinutes(self: DurationInput): number;

toNanos

Added in v2.0.0 Source

Get the duration in nanoseconds as a bigint.

If the duration is infinite, returns Option.none()

Signature

declare function toNanos(self: DurationInput): Option<bigint>;

toSeconds

Added in v2.0.0 Source

Signature

declare function toSeconds(self: DurationInput): number;

toWeeks

Added in v3.8.0 Source

Signature

declare function toWeeks(self: DurationInput): number;

Get the duration in nanoseconds as a bigint.

If the duration is infinite, it throws an error.

Signature

declare function unsafeToNanos(self: DurationInput): bigint;

Guards

isDuration

Added in v2.0.0 Source

Signature

declare function isDuration(u: unknown): u is Duration;

isFinite

Added in v2.0.0 Source

Signature

declare function isFinite(self: Duration): boolean;

isZero

Added in v3.5.0 Source

Signature

declare function isZero(self: Duration): boolean;

Instances

Equivalence

Added in v2.0.0 Source

Signature

declare const Equivalence: equivalence.Equivalence<Duration>;

Order

Added in v2.0.0 Source

Signature

declare const Order: order.Order<Duration>;

Math

divide

Added in v2.4.19 Source

Signature

declare const divide: {
  (by: number): (self: DurationInput) => Option<Duration>;
  (self: DurationInput, by: number): Option<Duration>;
};

subtract

Added in v2.0.0 Source

Signature

declare const subtract: {
  (that: DurationInput): (self: DurationInput) => Duration;
  (self: DurationInput, that: DurationInput): Duration;
};

sum

Added in v2.0.0 Source

Signature

declare const sum: {
  (that: DurationInput): (self: DurationInput) => Duration;
  (self: DurationInput, that: DurationInput): Duration;
};

times

Added in v2.0.0 Source

Signature

declare const times: {
  (times: number): (self: DurationInput) => Duration;
  (self: DurationInput, times: number): Duration;
};

unsafeDivide

Added in v2.4.19 Source

Signature

declare const unsafeDivide: {
  (by: number): (self: DurationInput) => Duration;
  (self: DurationInput, by: number): Duration;
};

Models

Duration interface

Added in v2.0.0 Source

Signature

interface Duration extends Equal, Pipeable, Inspectable {
  readonly [TypeId]: typeof TypeId;
  readonly value: DurationValue;
}

DurationInput type

Added in v2.0.0 Source

Signature

type DurationInput =
  | Duration
  | number
  | bigint
  | readonly [seconds: number, nanos: number]
  | `${number} ${Unit}`;

DurationValue type

Added in v2.0.0 Source

Signature

type DurationValue =
  | {
      readonly _tag: "Millis";
      readonly millis: number;
    }
  | {
      readonly _tag: "Nanos";
      readonly nanos: bigint;
    }
  | {
      readonly _tag: "Infinity";
    };

Unit type

Added in v2.0.0 Source

Signature

type Unit =
  | "nano"
  | "nanos"
  | "micro"
  | "micros"
  | "milli"
  | "millis"
  | "second"
  | "seconds"
  | "minute"
  | "minutes"
  | "hour"
  | "hours"
  | "day"
  | "days"
  | "week"
  | "weeks";

Order

clamp

Added in v2.0.0 Source

Signature

declare const clamp: {
  (options: { maximum: DurationInput; minimum: DurationInput }): (self: DurationInput) => Duration;
  (
    self: DurationInput,
    options: {
      maximum: DurationInput;
      minimum: DurationInput;
    },
  ): Duration;
};

max

Added in v2.0.0 Source

Signature

declare const max: {
  (that: DurationInput): (self: DurationInput) => Duration;
  (self: DurationInput, that: DurationInput): Duration;
};

Other

decode

Added in v2.0.0 Source

Signature

declare function decode(input: DurationInput): Duration;

Signature

declare const decodeUnknown: (u: unknown) => Option.Option<Duration>;

min

Added in v2.0.0 Source

Signature

declare const min: {
  (that: DurationInput): (self: DurationInput) => Duration;
  (self: DurationInput, that: DurationInput): Duration;
};

Pattern Matching

match

Added in v2.0.0 Source

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;
};

matchWith

Added in v2.0.0 Source

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

between

Added in v2.0.0 Source

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;
};

equals

Added in v2.0.0 Source

Signature

declare const equals: {
  (that: DurationInput): (self: DurationInput) => boolean;
  (self: DurationInput, that: DurationInput): boolean;
};

greaterThan

Added in v2.0.0 Source

Signature

declare const greaterThan: {
  (that: DurationInput): (self: DurationInput) => boolean;
  (self: DurationInput, that: DurationInput): boolean;
};

Signature

declare const greaterThanOrEqualTo: {
  (that: DurationInput): (self: DurationInput) => boolean;
  (self: DurationInput, that: DurationInput): boolean;
};

lessThan

Added in v2.0.0 Source

Signature

declare const lessThan: {
  (that: DurationInput): (self: DurationInput) => boolean;
  (self: DurationInput, that: DurationInput): boolean;
};

Signature

declare const lessThanOrEqualTo: {
  (that: DurationInput): (self: DurationInput) => boolean;
  (self: DurationInput, that: DurationInput): boolean;
};

Symbol

TypeId type

Added in v2.0.0 Source

Signature

type TypeId = typeof TypeId;