mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Move all crates into a crates directory (#1940)
This commit is contained in:
34
crates/egui_extras/src/datepicker/mod.rs
Normal file
34
crates/egui_extras/src/datepicker/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
mod button;
|
||||
mod popup;
|
||||
|
||||
pub use button::DatePickerButton;
|
||||
use chrono::{Date, Datelike, Duration, NaiveDate, Utc, Weekday};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Week {
|
||||
number: u8,
|
||||
days: Vec<Date<Utc>>,
|
||||
}
|
||||
|
||||
fn month_data(year: i32, month: u32) -> Vec<Week> {
|
||||
let first = Date::from_utc(NaiveDate::from_ymd(year, month, 1), Utc);
|
||||
let mut start = first;
|
||||
while start.weekday() != Weekday::Mon {
|
||||
start = start.checked_sub_signed(Duration::days(1)).unwrap();
|
||||
}
|
||||
let mut weeks = vec![];
|
||||
let mut week = vec![];
|
||||
while start < first || start.month() == first.month() || start.weekday() != Weekday::Mon {
|
||||
week.push(start);
|
||||
|
||||
if start.weekday() == Weekday::Sun {
|
||||
weeks.push(Week {
|
||||
number: start.iso_week().week() as u8,
|
||||
days: week.drain(..).collect(),
|
||||
});
|
||||
}
|
||||
start = start.checked_add_signed(Duration::days(1)).unwrap();
|
||||
}
|
||||
|
||||
weeks
|
||||
}
|
||||
Reference in New Issue
Block a user