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

Chinese lunisolar dates, with numbered months and an explicit leap-month flag.

`from_date/1` and `to_date/1` convert the civil dates in `supported_range/0`.
An aware datetime is an instant and uses the date at UTC+08:00 (Beijing
standard time). A naive datetime already supplies a civil date. Conversion
uses the month starts and lengths shipped with DayEx.

# `error`

```elixir
@type error() :: :out_of_range | :invalid_lunar_date
```

# `t`

```elixir
@type t() :: %DayEx.Lunar{
  day: 1..30,
  leap_month: boolean(),
  month: 1..12,
  year: integer()
}
```

# `format`

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

Formats a lunar date in simplified Chinese, for example `甲辰年正月初一`.

# `from_date`

```elixir
@spec from_date(Date.t() | NaiveDateTime.t() | DateTime.t()) ::
  {:ok, t()} | {:error, :out_of_range}
```

Converts a Gregorian date or datetime to a Chinese lunar date.

# `sexagenary_year`

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

Returns the lunar year's stem and branch (干支), changing on Chinese New Year.

# `supported_range`

```elixir
@spec supported_range() :: Date.Range.t()
```

Returns the inclusive range of supported Gregorian civil dates.

# `to_date`

```elixir
@spec to_date(t()) :: {:ok, Date.t()} | {:error, error()}
```

Converts a lunar date to a native Gregorian date.

Returns `{:error, :invalid_lunar_date}` for impossible fields, such as the
30th of a short month or a leap month that does not exist in the given year.
Dates outside the published interval return `{:error, :out_of_range}`.

# `zodiac`

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

Returns the lunar year's Chinese zodiac animal in simplified Chinese.

---

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