diff --git a/Cargo.lock b/Cargo.lock index 424cda23..51b28ec9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -571,9 +571,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", "js-sys", diff --git a/crates/egui_demo_lib/src/demo/widget_gallery.rs b/crates/egui_demo_lib/src/demo/widget_gallery.rs index 308830d6..22d4ac06 100644 --- a/crates/egui_demo_lib/src/demo/widget_gallery.rs +++ b/crates/egui_demo_lib/src/demo/widget_gallery.rs @@ -20,7 +20,7 @@ pub struct WidgetGallery { #[cfg(feature = "chrono")] #[cfg_attr(feature = "serde", serde(skip))] - date: Option>, + date: Option, #[cfg_attr(feature = "serde", serde(skip))] texture: Option, @@ -218,7 +218,7 @@ impl WidgetGallery { #[cfg(feature = "chrono")] { - let date = date.get_or_insert_with(|| chrono::offset::Utc::now().date()); + let date = date.get_or_insert_with(|| chrono::offset::Utc::now().date_naive()); ui.add(doc_link_label("DatePickerButton", "DatePickerButton")); ui.add(egui_extras::DatePickerButton::new(date)); ui.end_row(); diff --git a/crates/egui_extras/src/datepicker/button.rs b/crates/egui_extras/src/datepicker/button.rs index d6dcbfe2..9c5cb111 100644 --- a/crates/egui_extras/src/datepicker/button.rs +++ b/crates/egui_extras/src/datepicker/button.rs @@ -1,5 +1,5 @@ use super::popup::DatePickerPopup; -use chrono::{Date, Utc}; +use chrono::NaiveDate; use egui::{Area, Button, Frame, InnerResponse, Key, Order, RichText, Ui, Widget}; #[derive(Default, Clone, serde::Deserialize, serde::Serialize)] @@ -8,7 +8,7 @@ pub(crate) struct DatePickerButtonState { } pub struct DatePickerButton<'a> { - selection: &'a mut Date, + selection: &'a mut NaiveDate, id_source: Option<&'a str>, combo_boxes: bool, arrows: bool, @@ -17,7 +17,7 @@ pub struct DatePickerButton<'a> { } impl<'a> DatePickerButton<'a> { - pub fn new(selection: &'a mut Date) -> Self { + pub fn new(selection: &'a mut NaiveDate) -> Self { Self { selection, id_source: None, diff --git a/crates/egui_extras/src/datepicker/mod.rs b/crates/egui_extras/src/datepicker/mod.rs index b163a3a7..d1e10f1c 100644 --- a/crates/egui_extras/src/datepicker/mod.rs +++ b/crates/egui_extras/src/datepicker/mod.rs @@ -2,16 +2,16 @@ mod button; mod popup; pub use button::DatePickerButton; -use chrono::{Date, Datelike, Duration, NaiveDate, Utc, Weekday}; +use chrono::{Datelike, Duration, NaiveDate, Weekday}; #[derive(Debug)] struct Week { number: u8, - days: Vec>, + days: Vec, } fn month_data(year: i32, month: u32) -> Vec { - let first = Date::from_utc(NaiveDate::from_ymd(year, month, 1), Utc); + let first = NaiveDate::from_ymd_opt(year, month, 1).expect("Could not create NaiveDate"); let mut start = first; while start.weekday() != Weekday::Mon { start = start.checked_sub_signed(Duration::days(1)).unwrap(); diff --git a/crates/egui_extras/src/datepicker/popup.rs b/crates/egui_extras/src/datepicker/popup.rs index 637dfccf..7851f240 100644 --- a/crates/egui_extras/src/datepicker/popup.rs +++ b/crates/egui_extras/src/datepicker/popup.rs @@ -1,4 +1,4 @@ -use chrono::{Date, Datelike, NaiveDate, Utc, Weekday}; +use chrono::{Datelike, NaiveDate, Weekday}; use egui::{Align, Button, Color32, ComboBox, Direction, Id, Layout, RichText, Ui, Vec2}; @@ -16,7 +16,8 @@ struct DatePickerPopupState { impl DatePickerPopupState { fn last_day_of_month(&self) -> u32 { - let date: Date = Date::from_utc(NaiveDate::from_ymd(self.year, self.month, 1), Utc); + let date: NaiveDate = + NaiveDate::from_ymd_opt(self.year, self.month, 1).expect("Could not create NaiveDate"); date.with_day(31) .map(|_| 31) .or_else(|| date.with_day(30).map(|_| 30)) @@ -26,7 +27,7 @@ impl DatePickerPopupState { } pub(crate) struct DatePickerPopup<'a> { - pub selection: &'a mut Date, + pub selection: &'a mut NaiveDate, pub button_id: Id, pub combo_boxes: bool, pub arrows: bool, @@ -38,7 +39,7 @@ impl<'a> DatePickerPopup<'a> { /// Returns `true` if user pressed `Save` button. pub fn draw(&mut self, ui: &mut Ui) -> bool { let id = ui.make_persistent_id("date_picker"); - let today = chrono::offset::Utc::now().date(); + let today = chrono::offset::Utc::now().date_naive(); let mut popup_state = ui .memory() .data @@ -369,14 +370,12 @@ impl<'a> DatePickerPopup<'a> { strip.cell(|ui| { ui.with_layout(Layout::top_down_justified(Align::Center), |ui| { if ui.button("Save").clicked() { - *self.selection = Date::from_utc( - NaiveDate::from_ymd( - popup_state.year, - popup_state.month, - popup_state.day, - ), - Utc, - ); + *self.selection = NaiveDate::from_ymd_opt( + popup_state.year, + popup_state.month, + popup_state.day, + ) + .expect("Could not create NaiveDate"); saved = true; close = true; }