Calendrical. Calendar. Weeks
(Calendrical v2.2.0)
Copy Markdown
Makes a calendar of whole weeks: a year of 52 or 53 weeks that begins or ends on a weekday near a day of the Gregorian year, cut into twelve months of four or five weeks by a pattern, as retail and other fiscal calendars count them and as the ISO week year does.
A date of the calendar is a month of the pattern and a day of it, so a month of four weeks has days 1 to 28 and one of five weeks days 1 to 35; a long year's last month holds the fifty-third week.
Options
:patternis the weeks in the three months of a quarter, one of[4, 4, 5],[4, 5, 4]and[5, 4, 4]. The default is[4, 5, 4].:year_beginsis the rule the year begins by:{weekday, :on_or_before, {month, day}}, the weekday on or before a day of a Gregorian month, the day being 1 to 7, so the year's first week holds that day, or{weekday, :nearest, {month, 4}}, the weekday nearest the fourth, which is the same rule. The ISO week year begins{:monday, :on_or_before, {1, 4}}. The default is{:monday, :on_or_before, {1, 1}}.:year_endsis the rule the year ends by, instead of:year_begins:{weekday, :on_or_after, {month, day}}, the weekday on or after a day within the last seven days of a Gregorian month, so the year's last week holds that day, or{weekday, :nearest, {month, last_day}}, the weekday nearest the month's last day. The NRF 4-5-4 year ends{:saturday, :nearest, {1, 31}}.:year_numberis the Gregorian year the year takes its number from::beginning, the one it begins in,:ending, the one it ends in, or:majority, the one most of it falls in, which is the default.:cldr_calendar_typeis the CLDR calendar whose data names the months and days,:gregorianby default.
Examples
defmodule Retail do
use Calendrical.Calendar.Weeks,
pattern: [4, 5, 4],
year_ends: {:saturday, :nearest, {1, 31}}
end
defmodule WeekYear do
use Calendrical.Calendar.Weeks, year_begins: {:monday, :on_or_before, {1, 4}}
endThe calendar is its options: the first day of a year is found from the rule, a month is the weeks of the pattern before it, and every other answer follows from those two.