Time duration which is represented as an amount and a unit e.g. '1 Month' or '166 Seconds'. The unit is preserved through calculations.

It has two sets of getter functions:

  • second(), minute(), hour() etc, singular form: these can be used to create string representations. These return a part of your string representation. E.g. for 2500 milliseconds, the millisecond() part would be 500
  • seconds(), minutes(), hours() etc, plural form: these return the total amount represented in the corresponding unit.

Constructors

  • Construct a time duration of 0 milliseconds

    Returns Duration

    Throws

    nothing

  • Construct a time duration from a string in one of two formats:

    1. [-]hhhh[:mm[:ss[.nnn]]] e.g. '-01:00:30.501'
    2. amount and unit e.g. '-1 days' or '1 year'. The unit may be in singular or plural form and is case-insensitive

    Parameters

    • s: string

    Returns Duration

    Throws

    timezonecomplete.Argument.S for invalid string

  • Construct a duration from an amount and a time unit.

    Parameters

    • amount: number

      Number of units

    • Optional unit: TimeUnit

      A time unit i.e. TimeUnit.Second, TimeUnit.Hour etc. Default Millisecond.

    Returns Duration

    Throws

    timezonecomplete.Argument.Amount if amount is not a finite number

    Throws

    timezonecomplete.Argument.Unit for invalid unit

Properties

kind: string = "Duration"

Allow not using instanceof

Methods

  • Amount of units (positive or negative, fractional)

    Returns number

    Throws

    nothing

  • Returns this duration expressed in different unit (positive or negative, fractional). This is precise for Year <-> Month and for time-to-time conversion (i.e. Hour-or-less to Hour-or-less). It is approximate for any other conversion

    Parameters

    Returns number

    Throws

    nothing

  • Convert this duration to a Duration in another unit. You always get a clone even if you specify the same unit. This is precise for Year <-> Month and for time-to-time conversion (i.e. Hour-or-less to Hour-or-less). It is approximate for any other conversion

    Parameters

    Returns Duration

    Throws

    nothing

  • The day part of a duration. This assumes that a month has 30 days.

    Returns number

    Throws

    nothing

  • The entire duration in days (negative or positive, fractional) This is approximate if this duration is not in days!

    Returns number

    Throws

    nothing

  • Divide by a unitless number. The result is a Duration, e.g. 1 year / 2 = 0.5 year The result is approximate if this duration as a unit that cannot be converted to a number (e.g. 1 month has variable length)

    Parameters

    • value: number

    Returns Duration

    a new Duration of (this / value)

    Throws

    timezonecomplete.Argument.Value if value is 0 or non-finite

  • Divide this Duration by a Duration. The result is a unitless number e.g. 1 year / 1 month = 12 The result is approximate if this duration as a unit that cannot be converted to a number (e.g. 1 month has variable length)

    Parameters

    Returns number

    a new Duration of (this / value)

    Throws

    timezonecomplete.Argument.Value if the duration is 0

  • Similar but not identical Approximate if the durations have units that cannot be converted

    Parameters

    Returns boolean

    True iff this and other represent the same time duration

    Throws

    nothing

  • Similar but not identical Returns false if we cannot determine whether they are equal in all time zones so e.g. 60 minutes equals 1 hour, but 24 hours do NOT equal 1 day

    Parameters

    Returns boolean

    True iff this and other represent the same time duration

    Throws

    nothing

  • Approximate if the durations have units that cannot be converted

    Parameters

    Returns boolean

    True iff this >= other

    Throws

    nothing

  • Approximate if the durations have units that cannot be converted

    Parameters

    Returns boolean

    True iff this > other

    Throws

    nothing

  • The hour part of a duration. This assumes that a day has 24 hours (which is not the case during DST changes).

    Returns number

    Throws

    nothing

  • The entire duration in hours (negative or positive, fractional) For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 1.5 for a 5400000 milliseconds duration

    Throws

    nothing

  • Same unit and same amount

    Parameters

    Returns boolean

    Throws

    nothing

  • Approximate if the durations have units that cannot be converted

    Parameters

    Returns boolean

    True iff (this <= other)

    Throws

    nothing

  • Approximate if the durations have units that cannot be converted

    Parameters

    Returns boolean

    True iff (this < other)

    Throws

    nothing

  • Approximate if the durations have units that cannot be converted

    Parameters

    Returns Duration

    The maximum (most positive) of this and other

    Throws

    nothing

  • The millisecond part of the duration (always positive) For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 400 for a -01:02:03.400 duration

    Throws

    nothing

  • The entire duration in milliseconds (negative or positive) For Day/Month/Year durations, this is approximate!

    Returns number

    Throws

    nothing

  • Approximate if the durations have units that cannot be converted

    Parameters

    Returns Duration

    The minimum (most negative) of this and other

    Throws

    nothing

  • The minute part of the duration (always positive) For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 2 for a -01:02:03.400 duration

    Throws

    nothing

  • The entire duration in minutes (negative or positive, fractional) For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 1.5 for a 90000 milliseconds duration

    Throws

    nothing

  • The month part of a duration.

    Returns number

    Throws

    nothing

  • The entire duration in days (negative or positive, fractional) This is approximate if this duration is not in Months or Years!

    Returns number

    Throws

    nothing

  • Multiply with a fixed number. Approximate if the durations have units that cannot be converted

    Parameters

    • value: number

    Returns Duration

    a new Duration of (this * value)

    Throws

    nothing

  • Returns true if this is a non-zero length duration

    Returns boolean

  • The second part of the duration (always positive) For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 3 for a -01:02:03.400 duration

    Throws

    nothing

  • The entire duration in seconds (negative or positive, fractional) For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 1.5 for a 1500 milliseconds duration

    Throws

    nothing

  • Sign

    Returns string

    "-" if the duration is negative

    Throws

    nothing

  • String in [-]hhhh:mm:ss.nnn notation. All fields are always present except the sign.

    Returns string

    Throws

    nothing

  • String in [-]hhhh:mm[:ss[.nnn]] notation.

    Parameters

    • full: boolean = false

      If true, then all fields are always present except the sign. Otherwise, seconds and milliseconds are chopped off if zero

    Returns string

    Throws

    nothing

  • String in ISO 8601 notation e.g. 'P1M' for one month or 'PT1M' for one minute

    Returns string

    Throws

    nothing

  • String representation with amount and unit e.g. '1.5 years' or '-1 day'

    Returns string

    Throws

    nothing

  • The valueOf() method returns the primitive value of the specified object.

    Returns number

    Throws

    nothing

  • The hour part of the duration (always positive). Note that this part can exceed 23 hours, because for now, we do not have a days() function For Day/Month/Year durations, this is approximate!

    Returns number

    e.g. 25 for a -25:02:03.400 duration

    Throws

    nothing

  • Non-fractional positive years

    Returns number

    Throws

    nothing

  • The entire duration in years (negative or positive, fractional) This is approximate if this duration is not in Months or Years!

    Returns number

    Throws

    nothing

  • Returns true if this is a zero-length duration

    Returns boolean

  • Construct a time duration

    Parameters

    • amount: number

      Number of days (may be fractional or negative)

    Returns Duration

    A duration of n days

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

  • Construct a time duration

    Parameters

    • amount: number

      Number of hours (may be fractional or negative)

    Returns Duration

    A duration of n hours

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

  • Construct a time duration

    Parameters

    • amount: number

      Number of milliseconds (may be fractional or negative)

    Returns Duration

    A duration of n milliseconds

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

  • Construct a time duration

    Parameters

    • amount: number

      Number of minutes (may be fractional or negative)

    Returns Duration

    A duration of n minutes

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

  • Construct a time duration

    Parameters

    • amount: number

      Number of months (may be fractional or negative)

    Returns Duration

    A duration of n months

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

  • Construct a time duration

    Parameters

    • amount: number

      Number of seconds (may be fractional or negative)

    Returns Duration

    A duration of n seconds

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

  • Construct a time duration

    Parameters

    • amount: number

      Number of years (may be fractional or negative)

    Returns Duration

    A duration of n years

    Throws

    timezonecomplete.Argument.Amount if n is not a finite number

Generated using TypeDoc