Packages
ex_cldr_calendars
0.7.0
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.1
2.3.0
2.2.0
2.1.1
2.1.0
2.0.0
1.26.4
1.26.3
1.26.2
1.26.1
1.26.0
1.25.2
1.25.1
1.25.0
1.24.2
1.24.1
1.24.0
retired
1.23.1
1.23.0
1.22.1
1.22.0
1.21.0
1.20.0
1.19.0
1.18.1
1.18.0
1.17.3
1.17.2
1.17.1
1.17.0
1.17.0-rc.3
1.17.0-rc.2
1.17.0-rc.1
1.17.0-rc.0
1.16.0
1.15.3
1.15.2
1.15.1
1.15.0
1.14.1
1.14.0
1.13.0
1.13.0-rc.1
1.13.0-rc.0
1.12.1
1.12.0
1.11.0
1.11.0-rc.0
1.10.1
1.10.0
1.9.0
1.8.1
1.8.0
1.8.0-rc.0
1.7.1
1.7.0
1.6.0
1.5.1
1.5.0
retired
1.4.0
retired
1.3.0
retired
1.2.0
retired
1.1.0
retired
1.0.0
retired
0.9.0
retired
0.8.0
retired
0.7.0
retired
0.6.0
retired
0.5.0
retired
0.4.1
0.4.0
retired
0.3.0
retired
0.2.0
retired
0.1.0
retired
Localized month- and week-based calendars and calendar functions based upon CLDR data.
Retired package: Deprecated - Deprecated
Current section
Files
Jump to
Current section
Files
lib/cldr/calendar/backend/month_compiler.ex
defmodule Cldr.Calendar.Compiler.Month do
@moduledoc false
defmacro __before_compile__(env) do
config =
Module.get_attribute(env.module, :options)
|> Keyword.put(:calendar, env.module)
|> Cldr.Calendar.extract_options()
|> Cldr.Calendar.validate_config!(:month)
Module.put_attribute(env.module, :calendar_config, config)
quote location: :keep do
@moduledoc false
@behaviour Calendar
@behaviour Cldr.Calendar
@type year :: -9999..9999
@type month :: 1..12
@type day :: 1..31
alias Cldr.Calendar.Base.Month
@doc false
def __config__ do
@calendar_config
end
@doc """
Identifies that the calendar is month based.
"""
@impl true
def calendar_base do
:month
end
@doc """
Defines the CLDR calendar type for this calendar.
This type is used in support of `Cldr.Calendar.localize/3`.
Currently only `:gregorian` is supported.
"""
@impl true
def cldr_calendar_type do
:gregorian
end
@doc """
Determines if the date given is valid according to this calendar.
"""
@impl true
def valid_date?(year, month, day) do
Month.valid_date?(year, month, day, __config__())
end
@doc """
Calculates the year and era from the given `year`.
The ISO calendar has two eras: the current era which
starts in year 1 and is defined as era "1". And a
second era for those years less than 1 defined as
era "0".
"""
@spec year_of_era(year) :: {year, era :: 0..1}
@impl true
def year_of_era(year) do
Month.year_of_era(year, __config__())
end
@doc """
Calculates the quarter of the year from the given `year`, `month`, and `day`.
It is an integer from 1 to 4.
"""
@spec quarter_of_year(year, month, day) :: 1..4
@impl true
def quarter_of_year(year, month, day) do
Month.quarter_of_year(year, month, day, __config__())
end
@doc """
Calculates the month of the year from the given `year`, `month`, and `day`.
It is an integer from 1 to 12.
"""
@spec month_of_year(year, month, day) :: month
@impl true
def month_of_year(year, month, day) do
Month.month_of_year(year, month, day, __config__())
end
@doc """
Calculates the week of the year from the given `year`, `month`, and `day`.
It is an integer from 1 to 53.
"""
@spec week_of_year(year, month, day) :: {year, Cldr.Calendar.week()}
@impl true
def week_of_year(year, month, day) do
Month.week_of_year(year, month, day, __config__())
end
@doc """
Calculates the ISO week of the year from the given `year`, `month`, and `day`.
It is an integer from 1 to 53.
"""
@spec iso_week_of_year(year, month, day) :: {year, Cldr.Calendar.week()}
@impl true
def iso_week_of_year(year, month, day) do
Month.iso_week_of_year(year, month, day)
end
@doc """
Calculates the day and era from the given `year`, `month`, and `day`.
"""
@spec day_of_era(year, month, day) :: {day :: pos_integer(), era :: 0..1}
@impl true
def day_of_era(year, month, day) do
Month.day_of_era(year, month, day, __config__())
end
@doc """
Calculates the day of the year from the given `year`, `month`, and `day`.
"""
@spec day_of_year(year, month, day) :: 1..366
@impl true
def day_of_year(year, month, day) do
Month.day_of_year(year, month, day, __config__())
end
@doc """
Calculates the day of the week from the given `year`, `month`, and `day`.
It is an integer from 1 to 7, where 1 is Monday and 7 is Sunday.
"""
@spec day_of_week(year, month, day) :: 1..7
@impl true
def day_of_week(year, month, day) do
Month.day_of_week(year, month, day, __config__())
end
@doc """
Calculates the number of period in a given `year`. A period
corresponds to a month in month-based calendars and
a week in week-based calendars..
"""
def periods_in_year(year) do
months_in_year(year)
end
@doc """
Returns the number days in a given year.
"""
@impl true
def days_in_year(year) do
Month.days_in_year(year, __config__())
end
@doc """
Returns how many days there are in the given year-month.
"""
@spec days_in_month(year, month) :: 28..31
@impl true
def days_in_month(year, month) do
Month.days_in_month(year, month, __config__())
end
@doc """
Returns the number days in a a week.
"""
def days_in_week do
Month.days_in_week()
end
@doc """
Returns a `Date.Range.t` representing
a given year.
"""
@impl true
def year(year) do
Month.year(year, __config__())
end
@doc """
Returns a `Date.Range.t` representing
a given quarter of a year.
"""
@impl true
def quarter(year, quarter) do
Month.quarter(year, quarter, __config__())
end
@doc """
Returns a `Date.Range.t` representing
a given month of a year.
"""
@impl true
def month(year, month) do
Month.month(year, month, __config__())
end
@doc """
Returns a `Date.Range.t` representing
a given week of a year.
"""
@impl true
def week(year, week) do
Month.week(year, week, __config__())
end
@doc """
Adds an `increment` number of `date_part`s
to a `year-month-day`.
`date_part` can be `:quarters`
or`:months`.
"""
@impl true
def plus(year, month, day, date_part, increment, options \\ [])
def plus(year, month, day, :quarters, quarters, options) do
Month.plus(year, month, day, __config__(), :quarters, quarters, options)
end
def plus(year, month, day, :months, months, options) do
Month.plus(year, month, day, __config__(), :months, months, options)
end
@doc """
Returns if the given year is a leap year.
"""
@spec leap_year?(year) :: boolean()
@impl true
def leap_year?(year) do
Month.leap_year?(year, __config__())
end
@doc """
Returns the number of days since the calendar
epoch for a given `year-month-day`
"""
def date_to_iso_days(year, month, day) do
Month.date_to_iso_days(year, month, day, __config__())
end
@doc """
Returns `{year, month, day}` calculated from
the number of `iso_days`.
"""
def date_from_iso_days(iso_days) do
Month.date_from_iso_days(iso_days, __config__())
end
@doc """
Returns the number of `iso_days` that is
the first day of the given
year for this calendar.
"""
def first_gregorian_day_of_year(year) do
Month.first_gregorian_day_of_year(year, __config__())
end
@doc """
Returns the number of `iso_days` that is
the last day of the given
year for this calendar.
"""
def last_gregorian_day_of_year(year) do
Month.last_gregorian_day_of_year(year, __config__())
end
@doc """
Returns the `t:Calendar.iso_days/0` format of the specified date.
"""
@impl true
@spec naive_datetime_to_iso_days(
Calendar.year(),
Calendar.month(),
Calendar.day(),
Calendar.hour(),
Calendar.minute(),
Calendar.second(),
Calendar.microsecond()
) :: Calendar.iso_days()
def naive_datetime_to_iso_days(year, month, day, hour, minute, second, microsecond) do
Month.naive_datetime_to_iso_days(
year,
month,
day,
hour,
minute,
second,
microsecond,
__config__()
)
end
@doc """
Converts the `t:Calendar.iso_days/0` format to the datetime format specified by this calendar.
"""
@spec naive_datetime_from_iso_days(Calendar.iso_days()) :: {
Calendar.year(),
Calendar.month(),
Calendar.day(),
Calendar.hour(),
Calendar.minute(),
Calendar.second(),
Calendar.microsecond()
}
@impl true
def naive_datetime_from_iso_days({days, day_fraction}) do
Month.naive_datetime_from_iso_days({days, day_fraction}, __config__())
end
@doc false
defdelegate date_to_string(year, month, day), to: Calendar.ISO
@doc false
defdelegate datetime_to_string(
year,
month,
day,
hour,
minute,
second,
microsecond,
time_zone,
zone_abbr,
utc_offset,
std_offset
),
to: Calendar.ISO
@doc false
defdelegate naive_datetime_to_string(year, month, day, hour, minute, second, microsecond),
to: Calendar.ISO
@doc false
defdelegate day_rollover_relative_to_midnight_utc, to: Calendar.ISO
@doc false
defdelegate months_in_year(year), to: Calendar.ISO
@doc false
defdelegate time_from_day_fraction(day_fraction), to: Calendar.ISO
@doc false
defdelegate time_to_day_fraction(hour, minute, second, microsecond), to: Calendar.ISO
@doc false
defdelegate time_to_string(hour, minute, second, microsecond), to: Calendar.ISO
@doc false
defdelegate valid_time?(hour, minute, second, microsecond), to: Calendar.ISO
end
end
end