# Duration

`import { Duration } from "destack:time";`

Temporal duration.

```ds title="Duration"
export class Duration {
    static from(item: Duration | DurationLike | string): Duration;
    static compare(one: Duration | DurationLike | string, two: Duration | DurationLike | string, options?: DurationArithmeticOptions | undefined): -1 | 0 | 1;
    constructor(years?: float64 | undefined, months?: float64 | undefined, weeks?: float64 | undefined, days?: float64 | undefined, hours?: float64 | undefined, minutes?: float64 | undefined, seconds?: float64 | undefined, milliseconds?: float64 | undefined, microseconds?: float64 | undefined, nanoseconds?: float64 | undefined);
    get sign(): -1 | 0 | 1;
    get blank(): boolean;
    get years(): float64;
    get months(): float64;
    get weeks(): float64;
    get days(): float64;
    get hours(): float64;
    get minutes(): float64;
    get seconds(): float64;
    get milliseconds(): float64;
    get microseconds(): float64;
    get nanoseconds(): float64;
    negated(): Duration;
    abs(): Duration;
    with(durationLike: { years?: float64; months?: float64; weeks?: float64; days?: float64; hours?: float64; minutes?: float64; seconds?: float64; milliseconds?: float64; microseconds?: float64; nanoseconds?: float64 }): Duration;
    add(other: Duration | DurationLike | string): Duration;
    subtract(other: Duration | DurationLike | string): Duration;
    round(roundTo: SmallestUnit<DateTimeUnit> | ({ smallestUnit: SmallestUnit<DateTimeUnit>; largestUnit?: LargestUnit<DateTimeUnit> } | { smallestUnit?: SmallestUnit<DateTimeUnit>; largestUnit: LargestUnit<DateTimeUnit> }) & { roundingIncrement?: float64; roundingMode?: RoundingMode }): Duration;
    total(totalOf: TotalUnit<DateTimeUnit> | { unit: TotalUnit<DateTimeUnit>; relativeTo?: ZonedDateTime | PlainDateTime | ZonedDateTimeLike | PlainDateTimeLike | string }): float64;
    toLocaleString(locales?: LocalesArgument | undefined, options?: DurationFormatOptions | undefined): Cow<"frame", string>;
    toJSON(): Cow<"frame", string>;
    toString(options?: ToStringPrecisionOptions | undefined): Cow<"frame", string>;
    valueOf(): never;
}
```

[language/library/src/time/duration.ds:38:183](https://github.com/destack-sh/destack/blob/main/language/library/src/time/duration.ds#L38-L183)

## Members

### `static from(item: Duration | DurationLike | string): Duration`

Create a duration from another duration, a field bag, or a string.

### `static compare(one: Duration | DurationLike | string, two: Duration | DurationLike | string, options?: DurationArithmeticOptions | undefined): -1 | 0 | 1`

Compare two durations.

### `constructor(years?: float64 | undefined, months?: float64 | undefined, weeks?: float64 | undefined, days?: float64 | undefined, hours?: float64 | undefined, minutes?: float64 | undefined, seconds?: float64 | undefined, milliseconds?: float64 | undefined, microseconds?: float64 | undefined, nanoseconds?: float64 | undefined)`

Create a duration.

### `get sign(): -1 | 0 | 1`

The duration sign.

### `get blank(): boolean`

Whether every field is zero.

### `get years(): float64`

Year count.

### `get months(): float64`

Month count.

### `get weeks(): float64`

Week count.

### `get days(): float64`

Day count.

### `get hours(): float64`

Hour count.

### `get minutes(): float64`

Minute count.

### `get seconds(): float64`

Second count.

### `get milliseconds(): float64`

Millisecond count.

### `get microseconds(): float64`

Microsecond count.

### `get nanoseconds(): float64`

Nanosecond count.

### `negated(): Duration`

Return the negated duration.

### `abs(): Duration`

Return the absolute duration.

### `with(durationLike: { years?: float64; months?: float64; weeks?: float64; days?: float64; hours?: float64; minutes?: float64; seconds?: float64; milliseconds?: float64; microseconds?: float64; nanoseconds?: float64 }): Duration`

Return a duration with updated fields.

### `add(other: Duration | DurationLike | string): Duration`

Add another duration.

### `subtract(other: Duration | DurationLike | string): Duration`

Subtract another duration.

### `round(roundTo: SmallestUnit<DateTimeUnit> | ({ smallestUnit: SmallestUnit<DateTimeUnit>; largestUnit?: LargestUnit<DateTimeUnit> } | { smallestUnit?: SmallestUnit<DateTimeUnit>; largestUnit: LargestUnit<DateTimeUnit> }) & { roundingIncrement?: float64; roundingMode?: RoundingMode }): Duration`

Round this duration.

### `total(totalOf: TotalUnit<DateTimeUnit> | { unit: TotalUnit<DateTimeUnit>; relativeTo?: ZonedDateTime | PlainDateTime | ZonedDateTimeLike | PlainDateTimeLike | string }): float64`

Return this duration totalled in one unit.

### `toLocaleString(locales?: LocalesArgument | undefined, options?: DurationFormatOptions | undefined): Cow<"frame", string>`

Return a locale-aware string.

### `toJSON(): Cow<"frame", string>`

Return a JSON string.

### `toString(options?: ToStringPrecisionOptions | undefined): Cow<"frame", string>`

Return an ISO string.

### `valueOf(): never`

Reject numeric coercion.
