Skip to content

Cldr Calendars Persian version 0.1.0

Choose a tag to compare

@kipcole9 kipcole9 released this 09 Dec 09:23
· 18 commits to master since this release

This library implements the Solar Hijri calendar that is used in Iran and Afghanistan.

From wikipedia:

The Solar Hijri calendar (Persian: گاه‌شماری هجری خورشیدی‎, romanized: gāh-shomāri-ye hejri-ye khorshidi; Pashto: لمريز لېږدیز کلیز‎), also called the Solar Hejri calendar or Shamsi Hijri calendar, and abbreviated as SH, is the official calendar of Iran and Afghanistan. It begins on the March equinox (Nowruz) as determined by astronomical calculation for the Iran Standard Time meridian (52.5°E, UTC+03:30) and has years of 365 or 366 days.

Usage

ex_cldr_calendars_persian conforms to both the Calendar and Cldr.Calendar behaviours and therefore the functions in the Date, DateTime, NaiveDateTime, Time and Calendar functions are supported.

For Elixir versions up to and including 1.9, a date can be created by:

iex> {:ok, date} = Date.new(1354, 1, 1, Cldr.Calendar.Persian)
{:ok, ~D[1354-01-01 Cldr.Calendar.Persian]}

For Elixir version 1.10 and later Sigil_D supports user-defined calendars:

iex> ~D[1354-01-01 Cldr.Calendar.Persian]
~D[1354-01-01 Cldr.Calendar.Persian]

Localization

ex_cldr_calendars_persian depends on ex_cldr_calendars which supports calendar localization. For full date and time formatting see ex_cldr_dates_times.

Basic localization is executed by the Cldr.Calendar.localize/3. For example:

iex> Cldr.Calendar.localize(date, :month, locale: "en")
"Farvardin"

iex> Cldr.Calendar.localize(date, :month, locale: "fa")
"فروردین"

iex> Cldr.Calendar.localize(date, :day_of_week, locale: "fa")
"جمعه"

iex> Cldr.Calendar.localize(date, :day_of_week, locale: "en")
"Fri"