expression
Chrono ISO week-year
ISO week numbering can assign early January days to the previous week-year. Group weekly reports by both ISO week-year and week number. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2020-W53 Common mistake: Grouping ISO weeks by the calendar year instead of the week-year.
Formal Syntax & Structure
rust syntaxrust
date.iso_week().year(); date.iso_week().week()Working Example
Example Snippetrust
fn main() { use chrono::{Datelike, NaiveDate}; let d = NaiveDate::from_ymd_opt(2021, 1, 1).unwrap(); let w = d.iso_week(); println!("{}-W{:02}", w.year(), w.week());}