summaryrefslogtreecommitdiff
path: root/crates/egui_extras/src/datepicker/popup.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/egui_extras/src/datepicker/popup.rs')
-rw-r--r--crates/egui_extras/src/datepicker/popup.rs23
1 files changed, 11 insertions, 12 deletions
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<Utc> = 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<Utc>,
+ 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;
}