mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Replace chrono with jiff (#8008)
`jiff` is more modern, and seem to be where the ecosystem is heading.
This commit is contained in:
@@ -26,7 +26,7 @@ rustdoc-args = ["--generate-link-to-definition"]
|
||||
[features]
|
||||
default = []
|
||||
|
||||
chrono = ["egui_extras/datepicker", "dep:chrono"]
|
||||
jiff = ["egui_extras/datepicker", "dep:jiff"]
|
||||
|
||||
## Allow serialization using [`serde`](https://docs.rs/serde).
|
||||
serde = ["egui/serde", "dep:serde", "egui_extras/serde"]
|
||||
@@ -42,7 +42,7 @@ egui_extras = { workspace = true, features = ["image", "svg"] }
|
||||
unicode_names2.workspace = true # this old version has fewer dependencies
|
||||
|
||||
#! ### Optional dependencies
|
||||
chrono = { workspace = true, optional = true, features = ["js-sys", "wasmbind"] }
|
||||
jiff = { workspace = true, optional = true, features = ["std", "js"] }
|
||||
## Enable this when generating docs.
|
||||
document-features = { workspace = true, optional = true }
|
||||
serde = { workspace = true, optional = true }
|
||||
|
||||
@@ -19,11 +19,11 @@ pub struct WidgetGallery {
|
||||
color: egui::Color32,
|
||||
animate_progress_bar: bool,
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
date: Option<chrono::NaiveDate>,
|
||||
date: Option<jiff::civil::Date>,
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
with_date_button: bool,
|
||||
}
|
||||
|
||||
@@ -39,19 +39,19 @@ impl Default for WidgetGallery {
|
||||
string: Default::default(),
|
||||
color: egui::Color32::LIGHT_BLUE.linear_multiply(0.5),
|
||||
animate_progress_bar: false,
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
date: None,
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
with_date_button: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetGallery {
|
||||
#[allow(clippy::allow_attributes, unused_mut)] // if not chrono
|
||||
#[allow(clippy::allow_attributes, unused_mut)] // if not jiff
|
||||
#[inline]
|
||||
pub fn with_date_button(mut self, _with_date_button: bool) -> Self {
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
{
|
||||
self.with_date_button = _with_date_button;
|
||||
}
|
||||
@@ -140,9 +140,9 @@ impl WidgetGallery {
|
||||
string,
|
||||
color,
|
||||
animate_progress_bar,
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
date,
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
with_date_button,
|
||||
} = self;
|
||||
|
||||
@@ -242,9 +242,9 @@ impl WidgetGallery {
|
||||
}
|
||||
ui.end_row();
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
if *with_date_button {
|
||||
let date = date.get_or_insert_with(|| chrono::offset::Utc::now().date_naive());
|
||||
let date = date.get_or_insert_with(|| jiff::Zoned::now().date());
|
||||
ui.add(doc_link_label_with_crate(
|
||||
"egui_extras",
|
||||
"DatePickerButton",
|
||||
@@ -302,7 +302,7 @@ fn doc_link_label_with_crate<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "chrono")]
|
||||
#[cfg(feature = "jiff")]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -314,7 +314,7 @@ mod tests {
|
||||
pub fn should_match_screenshot() {
|
||||
let mut demo = WidgetGallery {
|
||||
// If we don't set a fixed date, the snapshot test will fail.
|
||||
date: Some(chrono::NaiveDate::from_ymd_opt(2024, 1, 1).unwrap()),
|
||||
date: Some(jiff::civil::date(2024, 1, 1)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user