Chrono update (#2397)
* limit day to last day of month if the month or year is changed * update chrono to 0.4.23, switch to NaiveDate and remove use of deprecated functions.
This commit is contained in:
parent
9e3da91a59
commit
c3932f7f7f
5 changed files with 21 additions and 22 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct WidgetGallery {
|
|||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
date: Option<chrono::Date<chrono::Utc>>,
|
||||
date: Option<chrono::NaiveDate>,
|
||||
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
texture: Option<egui::TextureHandle>,
|
||||
|
@ -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();
|
||||
|
|
|
@ -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<Utc>,
|
||||
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<Utc>) -> Self {
|
||||
pub fn new(selection: &'a mut NaiveDate) -> Self {
|
||||
Self {
|
||||
selection,
|
||||
id_source: None,
|
||||
|
|
|
@ -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<Date<Utc>>,
|
||||
days: Vec<NaiveDate>,
|
||||
}
|
||||
|
||||
fn month_data(year: i32, month: u32) -> Vec<Week> {
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue