DayEx.Lunar (day_ex v1.10.115)

Copy Markdown View Source

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.

Summary

Functions

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

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

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

Returns the inclusive range of supported Gregorian civil dates.

Converts a lunar date to a native Gregorian date.

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

Types

error()

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

t()

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

Functions

format(lunar)

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

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

from_date(date)

@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(lunar)

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

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

supported_range()

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

Returns the inclusive range of supported Gregorian civil dates.

to_date(lunar)

@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(lunar)

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

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