DayEx (day_ex v1.10.115)

Copy Markdown View Source

Lightweight Elixir port of dayjs.

Pipe-friendly date/time parsing, formatting, manipulation, and querying. All functions accept %DayEx{} as the first argument.

Months are 1-indexed (differs from dayjs 0-indexed).

Summary

Functions

Formats a calendar label relative to the reference date. See DayEx.Calendar.calendar/3.

Returns the number of days in the value's Gregorian calendar month.

Converts a Chinese lunar date to a DayEx value at Gregorian civil midnight.

Constructs a DayEx value from numbered lunar fields. Pass leap_month: true to select the second occurrence of a repeated month.

Converts a DayEx value or native date/time to a Chinese lunar date.

Tests whether the value falls on the reference day, defaulting to today.

Tests whether the value falls on the civil day after the reference.

Tests whether the value falls on the civil day before the reference.

Types

t()

@type t() :: %DayEx{datetime: DateTime.t() | NaiveDateTime.t(), locale: atom()}

Functions

add(d, n, unit)

after?(a, b)

after?(a, b, unit)

before?(a, b)

before?(a, b, unit)

between?(d, a, b)

between?(d, a, b, unit)

between?(d, a, b, unit, inclusivity)

calendar(value, reference \\ DayEx.now(), formats \\ %{})

Formats a calendar label relative to the reference date. See DayEx.Calendar.calendar/3.

compare(day_ex1, day_ex2)

date(day_ex)

date(d, value)

day(day_ex)

day_of_year(day_ex)

day_of_year(d, n)

days_in_month(d)

@spec days_in_month(t()) :: 28..31

Returns the number of days in the value's Gregorian calendar month.

diff(a, b)

diff(a, b, unit)

diff(a, b, unit, opts)

end_of(d, unit)

format(d)

format(d, template)

from(d, ref)

from(d, ref, without_suffix)

from_lunar(lunar)

@spec from_lunar(DayEx.Lunar.t()) :: {:ok, t()} | {:error, DayEx.Lunar.error()}

Converts a Chinese lunar date to a DayEx value at Gregorian civil midnight.

from_lunar(year, month, day, opts \\ [])

@spec from_lunar(integer(), integer(), integer(), [{:leap_month, boolean()}]) ::
  {:ok, t()} | {:error, DayEx.Lunar.error()}

Constructs a DayEx value from numbered lunar fields. Pass leap_month: true to select the second occurrence of a repeated month.

from_now(d)

from_now(d, without_suffix)

hour(day_ex)

hour(d, value)

iso_week(day_ex)

iso_week(d, n)

iso_week_year(day_ex)

leap_year?(d)

local(d)

locale(d, loc)

max(list)

millisecond(day_ex)

millisecond(d, value)

min(list)

minute(day_ex)

minute(d, value)

month(day_ex)

month(d, value)

now()

now(locale)

parse(d)

parse(input, format)

parse(input, format, locale)

parse!(input)

parse!(input, format)

quarter(d)

quarter(d, q)

same?(a, b)

same?(a, b, unit)

same_or_after?(a, b)

same_or_after?(a, b, unit)

same_or_before?(a, b)

same_or_before?(a, b, unit)

second(day_ex)

second(d, value)

set(d, unit, value)

start_of(d, unit)

subtract(d, n, unit)

to(d, target)

to(d, target, without_suffix)

to_date(day_ex)

to_datetime(day_ex)

to_iso_string(day_ex)

to_json(d)

to_list(d)

to_lunar(date)

@spec to_lunar(t() | Date.t() | NaiveDateTime.t() | DateTime.t()) ::
  {:ok, DayEx.Lunar.t()} | {:error, :out_of_range}

Converts a DayEx value or native date/time to a Chinese lunar date.

Instants use Beijing standard time (UTC+08:00). Dates and naive datetimes supply the civil date directly. See DayEx.Lunar.supported_range/0.

to_map(d)

to_naive_datetime(day_ex)

to_now(d)

to_now(d, without_suffix)

to_unix(day_ex)

to_unix_millisecond(d)

today?(value, reference \\ DayEx.now())

Tests whether the value falls on the reference day, defaulting to today.

tomorrow?(value, reference \\ DayEx.now())

Tests whether the value falls on the civil day after the reference.

tz(input, timezone)

tz_name(day_ex)

unix(ts)

utc()

utc(input)

utc?(day_ex)

utc_offset(day_ex)

valid?(arg1)

week(d)

week(d, n)

week_year(d)

weekday(d)

weekday(d, n)

weeks_in_year(d)

year(day_ex)

year(d, value)

yesterday?(value, reference \\ DayEx.now())

Tests whether the value falls on the civil day before the reference.