Compute ISO 8601 week number (1–53). Week 01 is the week containing the year's first Thursday. Days before Week 01 belong to the last week of the previous year; days after the last week belong to Week 01 of the next year.
(year: i32, month: u8, day: u8)
| 186 | /// Days before Week 01 belong to the last week of the previous year; |
| 187 | /// days after the last week belong to Week 01 of the next year. |
| 188 | fn iso_week_number(year: i32, month: u8, day: u8) -> u8 { |
| 189 | let doy = day_of_year(year, month, day) as i32; |
| 190 | let dow = day_of_week_iso(year, month, day) as i32; // 1=Mon..7=Sun |
| 191 | |
| 192 | // ISO week: (ordinal - weekday + 10) / 7 |
| 193 | let w = (doy - dow + 10) / 7; |
| 194 | |
| 195 | if w < 1 { |
| 196 | // Belongs to the last week of the previous year. |
| 197 | iso_weeks_in_year(year - 1) |
| 198 | } else if w > iso_weeks_in_year(year) as i32 { |
| 199 | // Belongs to week 1 of the next year. |
| 200 | 1 |
| 201 | } else { |
| 202 | w as u8 |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /// Day of year (1-based ordinal). |
| 207 | fn day_of_year(year: i32, month: u8, day: u8) -> u16 { |
no test coverage detected