Options
All
• Public
• Public/Protected
• All

A simple representation for time durations, based on TimeUnit.

• Duration

duration: number

unit: TimeUnit

## Methods

### convertTo

• Returns a new `Duration` value that represents `this` converted to use the given `unit`.

Note that this may be a lossy conversion, e.g. when converting 27 hours to 1 day, there's a loss of fidelity.

• inheritdoc

### hashCode

• hashCode(): number
• inheritdoc

### isFinite

• isFinite(): boolean
• This method returns `true` if this duration is finite, or `false otherwise.

### minus

• Subtracts the `other` duration from `this`.

Note that the `unit` used for the result will be the more finer grained one out of the two:

``````// Result will be 21 hours
Duration.days(1).minus(Duration.hours(3))
``````

### negate

• Negates `this` duration, by changing the sign.

### plus

• Return the sum of `this` duration and `other`.

Note that the `unit` used for the result will be the more finer grained one out of the two.

``````// Result will be 27 hours
Duration.days(1).plus(Duration.hours(3))
``````

### toDays

• toDays(): number
• Calculates the days described by the source Duration.

### toHours

• toHours(): number
• Calculates the hours described by the source Duration.

### toMicros

• toMicros(): number
• Calculates the microseconds described by the source Duration.

### toMillis

• toMillis(): number
• Calculates the milliseconds described by the source Duration.

### toMinutes

• toMinutes(): number
• Calculates the minutes described by the source Duration.

### toNanos

• toNanos(): number
• Calculates the nanoseconds described by the source Duration.

### toSeconds

• toSeconds(): number
• Calculates the seconds described by the source Duration.

### toString

• toString(): string

### Static days

• Constructs a `Duration` instance out of a value representing days.

### Static hours

• Constructs a `Duration` instance out of a value representing hours.

### Static inf

• Returns a Duration representing positive infinite.

### Static micros

• Constructs a `Duration` instance out of a value representing microseconds.

### Static millis

• Constructs a `Duration` instance out of a value representing milliseconds.

### Static minutes

• Constructs a `Duration` instance out of a value representing minutes.

### Static nanos

• Constructs a `Duration` instance out of a value representing nanoseconds.

### Static negInf

• Returns a Duration representing negative infinite.

### Static of

• Wraps the argument in a `Duration.millis` reference, in case it's a number, otherwise returns the argument as is.

In Javascript code it is customary to express durations with numbers representing milliseconds and in functions it's good to still allow developers to do that because it's the standard convention.

Thus one can work with a union type like `number | Duration`. And in case a `number` is given, then it is interpreted as milliseconds.

Usage:

``````function delay(d: number | Duration, r: () => {}) {
const millis = Duration.of(d).toMillis()
return setTimeout(r, millis)
}
``````

### Static seconds

• Constructs a `Duration` instance out of a value representing seconds.

### Static zero

• Returns a zero length duration.

## Legend

• Module
• Object literal
• Variable
• Function
• Function with type parameter
• Index signature
• Type alias
• Enumeration
• Enumeration member
• Property
• Method
• Interface
• Interface with type parameter
• Constructor
• Property
• Method
• Index signature
• Class
• Class with type parameter
• Constructor
• Property
• Method
• Accessor
• Index signature
• Inherited constructor
• Inherited property
• Inherited method
• Inherited accessor
• Protected property
• Protected method
• Protected accessor
• Private property
• Private method
• Private accessor
• Static property
• Static method

Generated using TypeDoc