/// Given a list of events in arbitrary order, sort them in ascending order of start date, then group them by starting month.
Given a list of events in arbitrary order, sort them in ascending order of start date, then group them by starting month.
Given a list of events in arbitrary order sort them in ascending order of start date then group them by starting month .
fn sort_and_group_by_month(mut events: Vec<&Event>) -> Vec<Month> {
    events.sort_by_key(|event| event.start_time_sort_key());
    let mut months = vec![];
    let mut month = Month {
        start: naive::MIN_DATE,
        events: vec![],
    };
    for event in events {
        if event.start_year() == month.start.year() && event.start_month() == month.start.month() {
            month.events.push(event.to_owned());
        } else {
            if !month.events.is_empty() {
                months.push(month);
            }
            month = Month {
                start: NaiveDate::from_ymd(event.start_year(), event.start_month(), 1),
                events: vec![event.to_owned()],
            };
        }
    }
    if !month.events.is_empty() {
        months.push(month);
    }
    months
}
fn sort_and_group_by_month ( mut events : Vec < & Event > ) -> Vec < Month > { events . sort_by_key ( | event | event . start_time_sort_key ( ) ) ; let mut months = vec ! [ ] ; let mut month = Month { start : naive :: MIN_DATE , events : vec ! [ ] , } ; for event in events { if event . start_year ( ) == month . start . year ( ) && event . start_month ( ) == month . start . month ( ) { month . events . push ( event . to_owned ( ) ) ; } else { if ! month . events . is_empty ( ) { months . push ( month ) ; } month = Month { start : NaiveDate :: from_ymd ( event . start_year ( ) , event . start_month ( ) , 1 ) , events : vec ! [ event to_owned ( ) ] , } ; } } if ! month . events . is_empty ( ) { months . push ( month ) ; } months }
Given a list of events in arbitrary order, sort them in ascending order of start date, then group them by starting month.
Given a list of events in arbitrary order sort them in ascending order of start date then group them by starting month .
events
Vec<&Event>