Cldr Dates & Times v1.2.0 Cldr.Calendar.ISOWeek View Source

Link to this section Summary

Functions

Returns the date of the first day of the first week of the year that includes the provided date

The last week of the ISO week-numbering year, i.e. the 52nd or 53rd one, is the week before week 01. This week’s properties are

Returns the week of the year for the given date

Returns the number of weeks in a year

Link to this section Functions

Link to this function first_week_of_year(date) View Source

Returns the date of the first day of the first week of the year that includes the provided date.

This conforms with the ISO standard definition of when the first week of the year begins:

  • If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01.

  • If 1 January is on a Friday, it is part of week 53 of the previous year;

  • If on a Saturday, it is part of week 52 (or 53 if the previous Gregorian year was a leap year)

  • If on a Sunday, it is part of week 52 of the previous year.

IF a date if provided (as apposed to just a year) then we also need to make sure that the first week starts before the supplied date.

Link to this function first_week_of_year(year, calendar \\ Calendar.ISO) View Source

The last week of the ISO week-numbering year, i.e. the 52nd or 53rd one, is the week before week 01. This week’s properties are:

  • It has the year’s last Thursday in it.

  • It is the last week with a majority (4 or more) of its days in December.

  • Its middle day, Thursday, falls in the ending year.

  • Its last day is the Sunday nearest to 31 December.

  • It has 28 December in it. Hence the earliest possible last week extends from Monday 22 December to Sunday 28 December, the latest possible last week extends from Monday 28 December to Sunday 3 January (next gregorian year).

  • If 31 December is on a Monday, Tuesday or Wednesday, it is in week 01 of the next year. If it is on a Thursday, it is in week 53 of the year just ending; if on a Friday it is in week 52 (or 53 if the year just ending is a leap year); if on a Saturday or Sunday, it is in week 52 of the year just ending.

IF a date if provided (as apposed to just a year) then we also need to make sure that the last week accommodates the supplied date.

Link to this function last_week_of_year(year, calendar \\ Calendar.ISO) View Source

Returns the week of the year for the given date.

Note that for some calendars (like Calendar.ISO), the first week of the year may not be the week that includes January 1st therefore for some dates near the start or end of the year, the week number may refer to a date in the following or previous Gregorian year.

Examples

Returns the number of weeks in a year

Examples

iex> Cldr.Calendar.weeks_in_year 2008
52
iex> Cldr.Calendar.weeks_in_year 2009
53
iex> Cldr.Calendar.weeks_in_year 2017
52
Link to this function weeks_in_year(year, calendar \\ Calendar.ISO) View Source