use time::Date; use time::Month; use time::Duration; fn main() { let d_begin = Date::from_calendar_date(1901, Month::January, 1).unwrap(); let d_end = Date::from_calendar_date(2000, Month::December, 31).unwrap(); let dt = Duration::DAY; let mut day_count = 0u32; let mut sundays_count = 0u32; let mut di = d_begin.clone(); while di != d_end { if di.weekday() == time::Weekday::Sunday { if di.day() == 1 { sundays_count += 1; } } //println!("{}", di.weekday()); di = di.checked_add(dt).unwrap(); day_count += 1; } println!("day_count: {}", day_count); println!("sundays count: {}", sundays_count); }