# Duration

Represents a length of time.

The amount can be specified either as a literal value (e.g: `10`) which
cannot be negative, or as an unresolved number token.

When the amount is passed as a token, unit conversion is not possible.

- Source: [`core/lib/duration.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/core/lib/duration.ts#L13)

## Example

```ts
import * as lambda from 'aws-cdk-lib/aws-lambda';

declare const fn: lambda.Function;
const fnUrl = fn.addFunctionUrl({ authType: lambda.FunctionUrlAuthType.NONE });

new cloudfront.Distribution(this, 'Distribution', {
  defaultBehavior: {
    origin: new origins.FunctionUrlOrigin(fnUrl, {
      readTimeout: Duration.seconds(30),
      responseCompletionTimeout: Duration.seconds(90),
      keepaliveTimeout: Duration.seconds(45),
    }),
  },
});
```

## Methods

- `days(amount: number): Duration // chainable` (static) — Create a Duration representing an amount of days.

  **Parameters**

  - `amount` — the amount of Days the `Duration` will represent.

  **Returns:** a new `Duration` representing `amount` Days.

- `formatTokenToNumber(): string` — Returns stringified number of duration.

- `hours(amount: number): Duration // chainable` (static) — Create a Duration representing an amount of hours.

  **Parameters**

  - `amount` — the amount of Hours the `Duration` will represent.

  **Returns:** a new `Duration` representing `amount` Hours.

- `isUnresolved(): boolean` — Checks if duration is a token or a resolvable object.

- `millis(amount: number): Duration // chainable` (static) — Create a Duration representing an amount of milliseconds.

  **Parameters**

  - `amount` — the amount of Milliseconds the `Duration` will represent.

  **Returns:** a new `Duration` representing `amount` ms.

- `minus(rhs: Duration): Duration // chainable` — Substract two Durations together.

- `minutes(amount: number): Duration // chainable` (static) — Create a Duration representing an amount of minutes.

  **Parameters**

  - `amount` — the amount of Minutes the `Duration` will represent.

  **Returns:** a new `Duration` representing `amount` Minutes.

- `parse(duration: string): Duration // chainable` (static) — Parse a period formatted according to the ISO 8601 standard.

  Days are the largest ISO duration supported, i.e.,
  weeks, months, and years are not supported.

  **Parameters**

  - `duration` — an ISO-formatted duration to be parsed.

  **Returns:** the parsed `Duration`.

  ```ts
  // This represents 1 day, 2 hours, 3 minutes, 4 seconds, and 567 milliseconds.
  'P1DT2H3M4.567S'
  ```

- `plus(rhs: Duration): Duration // chainable` — Add two Durations together.

- `seconds(amount: number): Duration // chainable` (static) — Create a Duration representing an amount of seconds.

  **Parameters**

  - `amount` — the amount of Seconds the `Duration` will represent.

  **Returns:** a new `Duration` representing `amount` Seconds.

- `toDays(opts?: TimeConversionOptions): number` — Return the total number of days in this Duration.

  **Returns:** the value of this `Duration` expressed in Days.

- `toHours(opts?: TimeConversionOptions): number` — Return the total number of hours in this Duration.

  **Returns:** the value of this `Duration` expressed in Hours.

- `toHumanString(): string` — Turn this duration into a human-readable string.

- `toIsoString(): string` — Return an ISO 8601 representation of this period.

  **Returns:** a string starting with 'P' describing the period

- `toMilliseconds(opts?: TimeConversionOptions): number` — Return the total number of milliseconds in this Duration.

  **Returns:** the value of this `Duration` expressed in Milliseconds.

- `toMinutes(opts?: TimeConversionOptions): number` — Return the total number of minutes in this Duration.

  **Returns:** the value of this `Duration` expressed in Minutes.

- `toSeconds(opts?: TimeConversionOptions): number` — Return the total number of seconds in this Duration.

  **Returns:** the value of this `Duration` expressed in Seconds.

- `toString(): string` — Returns a string representation of this `Duration`.

  This is never the right function to use when you want to use the `Duration`
  object in a template. Use `toSeconds()`, `toMinutes()`, `toDays()`, etc. instead.

- `unitLabel(): string` — Returns unit of the duration.
