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

Function day_of_year

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

Day of year (1-based ordinal).

(year: i32, month: u8, day: u8)

Source from the content-addressed store, hash-verified

205
206/// Day of year (1-based ordinal).
207fn day_of_year(year: i32, month: u8, day: u8) -> u16 {
208 let days_in_months: [u16; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
209 let is_leap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
210 let mut doy: u16 = day as u16;
211 for (m, &dim) in days_in_months.iter().enumerate().take(month as usize - 1) {
212 doy += dim;
213 if m == 1 && is_leap {
214 doy += 1;
215 }
216 }
217 doy
218}
219
220/// ISO day of week: 1=Monday .. 7=Sunday (Tomohiko Sakamoto's algorithm).
221fn day_of_week_iso(year: i32, month: u8, day: u8) -> u8 {

Callers 1

iso_week_numberFunction · 0.85

Calls 2

takeMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected