Class Duration

Hierarchy

  • Duration

Constructors

Properties

values: TDuration

Accessors

Methods

  • Return the absolute values of this Duration.

    Example

    new Duration({ hours: 1, seconds: -30 }).abs().toObject()
    // { hours: 1, seconds: 30 }

    Returns

    Returns Duration

  • Get the value of unit.

    Example

    Duration.fromObject({years: 2, days: 3}).get('years') // 2
    

    Example

    Duration.fromObject({years: 2, days: 3}).get('months') // 0
    

    Example

    Duration.fromObject({years: 2, days: 3}).get('days') // 3
    

    Returns

    Parameters

    • unit: any

      a unit such as 'minute' or 'day'

    Returns any

  • Return the negative of this Duration.

    Example

    new Duration({ hours: 1, seconds: 30 }).negated().toObject()
    // { hours: -1, seconds: -30 }

    Returns

    Returns Duration

  • Make this Duration shorter by the specified amount. Return a newly-constructed Duration.

    Returns

    Parameters

    • duration: any

      The amount to subtract.

    Returns Duration

  • Returns an ISO 8601-compliant string representation of this Duration.

    See

    https://en.wikipedia.org/wiki/ISO_8601#Durations

    Example

    Duration.fromObject({ years: 3, seconds: 45 }).toString() // 'P3YT45S'
    

    Example

    Duration.fromObject({ months: 4, seconds: 45 }).toString() // 'P4MT45S'
    

    Example

    Duration.fromObject({ months: 5 }).toString() // 'P5M'
    

    Example

    Duration.fromObject({ minutes: 5 }).toString() // 'PT5M'
    

    Example

    Duration.fromObject({ milliseconds: 6 }).toString() // 'PT0.006S'
    

    Returns

    Returns string

  • Returns {
        days?: number;
        hours?: number;
        milliseconds?: number;
        minutes?: number;
        months?: number;
        seconds?: number;
        weeks?: number;
        years?: number;
    }

    • Optional days?: number
    • Optional hours?: number
    • Optional milliseconds?: number
    • Optional minutes?: number
    • Optional months?: number
    • Optional seconds?: number
    • Optional weeks?: number
    • Optional years?: number
  • Create a Duration from an ISO 8601 duration string.

    Example

    Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject()
    // { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 }
    Duration.fromISO('PT23H').toObject()
    // { hours: 23 }
    Duration.fromISO('P5Y3M').toObject()
    // { years: 5, months: 3 }

    Returns

    Parameters

    • text: string

    Returns Duration

Generated using TypeDoc