WeekYearRule class abstract

A rule determining how 'week years' are arranged, including the weeks within the week year. Implementations provided by Time Machine itself can be obtained via the WeekYearRules class.

Dates are usually identified within a calendar system by a calendar year, a month within that calendar year, and a day within that month. For example, the date of birth of Ada Lovelace can be identified within the Gregorian calendar system as the year 1815, the month December (12), and the day 10. However, dates can also be identified (again within a calendar system) by week-year, week and day-of-week. How that identification occurs depends on which rule you use - but again as an example, within the Gregorian calendar system, using the ISO-8601 week year rule, the date of Ada Lovelace's birth is week-year 1815, week 49, day-of-week Sunday.

The calendar year of a date and the week-year of a date are the same in most rules for most dates, but aren't always. When they differ, it is usually because a day near the start of the calendar year is deemed to belong to the last week of the previous week-year - or conversely because a day near the end of the calendar year is deemed to belong to the first week of the following week-year. Some rules may be more radical - a UK tax year rule could number weeks from April 6th onwards, such that any date earlier than that in the calendar year would belong to the previous week-year.

The mapping of dates into week-year, week and day-of-week is always relative to a specific calendar system. For example, years in the Hebrew calendar system vary very significantly in length due to leap months, and this is reflected in the number of weeks within the week-years - as low as 50, and as high as 55.

This class allows conversions between the two schemes of identifying dates: GetWeekYear(LocalDate) and GetWeekOfWeekYear(LocalDate) allow the week-year and week to be obtained for a date, and GetLocalDate(int, int, IsoDayOfWeek, CalendarSystem) allows the reverse mapping. Note that the calendar system does not need to be specified in the former methods as a LocalDate already contains calendar information, and there is no method to obtain the day-of-week as that is not affected by the week year rule being used.

All implementations within Time Machine are immutable, and it is advised that any external implementations should be immutable too.

Annotations
  • @interface

Constructors

WeekYearRule()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getLocalDate(int weekYear, int weekOfWeekYear, DayOfWeek dayOfWeek, CalendarSystem calendar) LocalDate
Creates a LocalDate from a given week-year, week within that week-year, and day-of-week, for the specified calendar system.
getWeekOfWeekYear(LocalDate date) int
Calculates the week of the week-year in which the given date occurs, according to this rule.
getWeeksInWeekYear(int weekYear, CalendarSystem calendar) int
Returns the number of weeks in the given week-year, within the specified calendar system.
getWeekYear(LocalDate date) int
Calculates the week-year in which the given date occurs, according to this rule.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited