Date_Time_Formatter.from_iso_week_date_pattern
Documentation
Creates a formatter from a pattern for the ISO 8601 leap week calendar. The ISO 8601 leap week calendar is a variation of the ISO 8601 calendar that defines a leap week as the week that contains the 29th of February. This calendar is used by some European and Middle Eastern countries. The pattern is a sequence of letters and symbols that are interpreted as follows: - Y: The week based year. - In case the year is parsed in two digit mode (YY
), the default range is 1950-2049, but this can be changed by including the end year in braces e.g. YY{2099}
- w: Week of year. - d: Day of week. - d: Numeric day of week (1-7). 1 is Monday. - dd: Numeric day of week with zero padding (01-07). - ddd: Short name of the day of week (Mon-Sun). - dddd: Full name of the day of week (Monday-Sunday). The weekday names depend on the selected locale. - e: An alternative notation: single e
maps to ddd
and ee
or more map to dddd
meaning name of day of week. Moreover, all time and timezone pattern characters like in Simple
case are supported too - in case you need to parse a date time value with the date part in ISO week date format. The same as in the Simple
pattern, the single quotes can be used to escape letter literals and square brackets can be used to indicate optional sections.
Examples
Parsing a date in the ISO week date format
Date.parse "1976-W53-6" (Date_Time_Formatter.from_iso_week_date_pattern "YYYY-'W'WW-d") == (Date.new 1977 01 01)
Date.parse "1978-W01, Mon" (Date_Time_Formatter.from_iso_week_date_pattern "YYYY-'W'WW, eee") == (Date.new 1978 01 02)
Date_Time.parse "1978-W01-4 12:34:56" (Date_Time_Formatter.from_iso_week_date_pattern "YYYY-'W'WW-d HH:mm:ss") == (Date_Time.new 1978 01 05 12 34 56)
Omitting the day of the week will result in the first day of that week.
Date.parse (Date_Time_Formatter.from_iso_week_date_pattern "YYYY-'W'WW") "1978-W01" == (Date.new 1978 01 02)