DayEx.Calendar (day_ex v1.10.115)

Copy Markdown View Source

Calendar-time formatting and predicates based on the difference in civil dates.

For two timezone-aware values, the reference instant is viewed in the target's time zone. If either value is naive, each retains its own wall date. The default reference is the current UTC instant.

Summary

Functions

Formats a date relative to a reference using the target's locale.

Whether the target falls on the reference date.

Whether the target falls on the day after the reference date.

Whether the target falls on the day before the reference date.

Types

category()

@type category() ::
  :last_week | :last_day | :same_day | :next_day | :next_week | :same_else

formats()

@type formats() :: %{
  optional(category()) => String.t() | (DayEx.t(), DayEx.t() -> String.t())
}

Functions

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

@spec calendar(DayEx.t(), DayEx.t() | nil, formats()) :: String.t()

Formats a date relative to a reference using the target's locale.

The date itself, yesterday and tomorrow have individual formats. Dates two through six days away use weekday formats. More distant dates use :same_else. Override individual categories with a DayEx format string or a function that receives the target and reference and returns the final text. A nil reference uses the current instant with the supplied formats.

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

@spec today?(DayEx.t(), DayEx.t()) :: boolean()

Whether the target falls on the reference date.

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

@spec tomorrow?(DayEx.t(), DayEx.t()) :: boolean()

Whether the target falls on the day after the reference date.

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

@spec yesterday?(DayEx.t(), DayEx.t()) :: boolean()

Whether the target falls on the day before the reference date.