# `DayEx.Duration`
[🔗](https://github.com/gsmlg-opt/backplane/blob/v1.10.115/apps/day_ex/lib/day_ex/duration.ex#L1)

Represents a duration of time with decomposed fields.

Supports construction from milliseconds, maps, or ISO 8601 duration strings.

# `t`

```elixir
@type t() :: %DayEx.Duration{
  days: integer(),
  hours: integer(),
  milliseconds: integer(),
  minutes: integer(),
  months: integer(),
  seconds: integer(),
  years: integer()
}
```

# `add`

```elixir
@spec add(t(), t()) :: t()
```

Adds two durations field-wise.

# `as_days`

```elixir
@spec as_days(t()) :: float()
```

Returns total duration in days.

# `as_hours`

```elixir
@spec as_hours(t()) :: float()
```

Returns total duration in hours.

# `as_milliseconds`

```elixir
@spec as_milliseconds(t()) :: number()
```

Returns total duration in milliseconds.

# `as_minutes`

```elixir
@spec as_minutes(t()) :: float()
```

Returns total duration in minutes.

# `as_months`

```elixir
@spec as_months(t()) :: float()
```

Returns total duration in months.

# `as_seconds`

```elixir
@spec as_seconds(t()) :: float()
```

Returns total duration in seconds.

# `as_weeks`

```elixir
@spec as_weeks(t()) :: float()
```

Returns total duration in weeks.

# `as_years`

```elixir
@spec as_years(t()) :: float()
```

Returns total duration in years.

# `days`

```elixir
@spec days(t()) :: integer()
```

# `hours`

```elixir
@spec hours(t()) :: integer()
```

# `humanize`

```elixir
@spec humanize(t(), boolean()) :: String.t()
```

Returns a human-readable string for the duration.

When `with_suffix` is true, prefixes positive durations with "in ".

# `milliseconds`

```elixir
@spec milliseconds(t()) :: integer()
```

# `minutes`

```elixir
@spec minutes(t()) :: integer()
```

# `months`

```elixir
@spec months(t()) :: integer()
```

# `new`

```elixir
@spec new(integer() | map() | String.t()) :: t()
```

Create a Duration from milliseconds (integer), a map of fields, or an ISO 8601 duration string.

From milliseconds: decomposes into hours/minutes/seconds/milliseconds only (no calendar days).
From map: direct field assignment with defaults of 0.
From ISO string: parses "P[nY][nM][nD][T[nH][nM][nS]]".

# `seconds`

```elixir
@spec seconds(t()) :: integer()
```

# `subtract`

```elixir
@spec subtract(t(), t()) :: t()
```

Subtracts two durations field-wise.

# `to_iso_string`

```elixir
@spec to_iso_string(t()) :: String.t()
```

Returns the duration as an ISO 8601 duration string.

Zero duration returns "P0D".

# `valid?`

```elixir
@spec valid?(term()) :: boolean()
```

# `years`

```elixir
@spec years(t()) :: integer()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
