• Overview

    A shorthand function-object for DataAPIDuration. May be used anywhere when creating new DataAPIDurations.

    See DataAPIDuration and its methods for information about input parameters, formats, functions, etc.

    Parameters

    • Rest ...params: [string] | [number, number, number | bigint]

    Returns DataAPIDuration

    Example

    // equiv. to `new DataAPIDuration('-2w')`
    duration('-2w')

    // equiv. to `new DataAPIDuration(2, 1, 0)`
    duration(12, 1, 0)

    // equiv. to `DataAPIDuration.builder().build()`
    duration.builder().build()

    See

    DataAPIDuration

Properties

Properties

builder: ((this, base?) => DataAPIDurationBuilder) = DataAPIDuration.builder

Type declaration

    • (this, base?): DataAPIDurationBuilder
    • Overview

      Helpful utility for manually creating new DataAPIDuration instances.

      Contains builder methods for incrementally adding duration components, and negating the final result.

      Usage

      You may call each .add*() method any number of times, in any order, before calling build.

      The .negate(sign?) method may be called at any time to negate the final result.

      • You may pass a boolean to .negate(sign?) to definitively set the sign
      • Otherwise, the sign will be toggled.

      A base duration may be provided to initialize the builder with its components and its sign.

      Parameters

      • this: void
      • Optional base: DataAPIDuration

        The base DataAPIDuration to initialize the builder with, if any

      Returns DataAPIDurationBuilder

      Example

      const base = duration('1y');

      // '-1y3d15h'
      const span = duration.builder(base)
      .addHours(10)
      .addDays(3)
      .addHours(5)
      .negate()
      .build();

      See

      DataAPIDurationBuilder