MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / iso_week_number

Function iso_week_number

nodedb/src/control/sequence/format.rs:188–204  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
188fn 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).
207fn day_of_year(year: i32, month: u8, day: u8) -> u16 {

Callers 1

nowMethod · 0.85

Calls 3

day_of_yearFunction · 0.85
day_of_week_isoFunction · 0.85
iso_weeks_in_yearFunction · 0.85

Tested by

no test coverage detected