From 3b1bc4430b460ebdee1a87b0afe657a6fa53353a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= <150025636+git-f0x@users.noreply.github.com> Date: Sat, 14 Mar 2026 20:53:50 +0100 Subject: [PATCH] refactor: use `jiff` instead of `chrono` --- Cargo.lock | 21 +++++++++++++-------- Cargo.toml | 3 ++- src/archive.rs | 33 ++++++++++++++++----------------- src/tab.rs | 29 +++++++---------------------- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b277508..a18409e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -953,7 +953,6 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", - "pure-rust-locales", "serde", "wasm-bindgen", "windows-link 0.2.1", @@ -1358,7 +1357,6 @@ version = "1.0.8" dependencies = [ "anyhow", "bzip2", - "chrono", "compio", "cosmic-client-toolkit", "cosmic-mime-apps", @@ -1376,6 +1374,8 @@ dependencies = [ "icu", "ignore", "image", + "jiff", + "jiff-icu", "jxl-oxide", "libc", "libcosmic", @@ -3893,6 +3893,17 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "jiff-icu" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e67c2beaae8b10a82d849b9aabb698a43a682f32b17bcdc035d5ecadb44d646" +dependencies = [ + "icu_calendar", + "icu_time", + "jiff", +] + [[package]] name = "jiff-static" version = "0.2.23" @@ -5691,12 +5702,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pure-rust-locales" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "869675ad2d7541aea90c6d88c81f46a7f4ea9af8cd0395d38f11a95126998a0d" - [[package]] name = "pxfm" version = "0.1.28" diff --git a/Cargo.toml b/Cargo.toml index c19f30d..174e04c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,8 @@ rust-version = "1.90" [dependencies] anyhow = "1" -chrono = { version = "0.4", features = ["unstable-locales"] } +jiff = "0.2" +jiff-icu = "0.2" icu = { version = "2.1.1", features = ["compiled_data"] } cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "160b086", optional = true } cosmic-mime-apps = { git = "https://github.com/pop-os/cosmic-mime-apps.git", optional = true } diff --git a/src/archive.rs b/src/archive.rs index 5786ff7..92024d8 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -2,9 +2,8 @@ use crate::{ mime_icon::mime_for_path, operation::{Controller, OpReader, OperationError, OperationErrorType, sync_to_disk}, }; -use chrono::TimeZone; -use chrono::{Datelike, Timelike}; use cosmic::iced::futures; +use jiff::{Zoned, civil::DateTime, tz::TimeZone}; use std::{ collections::HashSet, fs, @@ -285,25 +284,25 @@ fn zip_extract>( } fn zip_date_time_to_system_time(date_time: zip::DateTime) -> Option { - let date = chrono::NaiveDate::from_ymd_opt( - date_time.year() as i32, - date_time.month() as u32, - date_time.day() as u32, - )?; - let time = chrono::NaiveTime::from_hms_opt( - date_time.hour() as u32, - date_time.minute() as u32, - date_time.second() as u32, - )?; - let naive = chrono::NaiveDateTime::new(date, time); - chrono::Local - .from_local_datetime(&naive) - .latest() + let dt = DateTime::new( + date_time.year() as i16, + date_time.month() as i8, + date_time.day() as i8, + date_time.hour() as i8, + date_time.minute() as i8, + date_time.second() as i8, + 0, + ) + .ok()?; + TimeZone::system() + .to_ambiguous_zoned(dt) + .later() + .ok() .map(SystemTime::from) } pub fn system_time_to_zip_date_time(system_time: SystemTime) -> Option { - let date_time: chrono::DateTime = system_time.into(); + let date_time = Zoned::try_from(system_time).ok()?; zip::DateTime::from_date_and_time( date_time.year() as u16, diff --git a/src/tab.rs b/src/tab.rs index 6d5cd60..9f05c3f 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1,4 +1,3 @@ -use chrono::{Datelike, Timelike, Utc}; use cosmic::{ Apply, Element, cosmic_theme, desktop::fde::{DesktopEntry, get_languages_from_env}, @@ -40,6 +39,7 @@ use icu::{ locale::preferences::extensions::unicode::keywords::HourCycle, }; use image::{DynamicImage, ImageDecoder, ImageReader}; +use jiff_icu::ConvertFrom; use jxl_oxide::integration::JxlDecoder; use mime_guess::{Mime, mime}; use regex::Regex; @@ -444,25 +444,10 @@ impl<'a> FormatTime<'a> { impl Display for FormatTime<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let datetime = chrono::DateTime::::from(self.time); - let now = chrono::Local::now(); - let icu_datetime = DateTime { - date: Date::try_new_gregorian( - datetime.year(), - datetime.month() as u8, - datetime.day() as u8, - ) - .unwrap(), - time: Time::try_new( - datetime.hour() as u8, - datetime.minute() as u8, - datetime.second() as u8, - 0, - ) - .unwrap(), - }; - - if datetime.date_naive() == now.date_naive() { + let zoned = jiff::Zoned::try_from(self.time).unwrap(); + let now = jiff::Zoned::now(); + let icu_datetime = DateTime::convert_from(zoned.datetime()); + if zoned.date() == now.date() { f.write_str(fl!("today").as_str())?; f.write_str(", ")?; self.time_formatter.format(&icu_datetime).fmt(f) @@ -1340,8 +1325,8 @@ pub fn scan_recents(sizes: IconSizes) -> Vec { .into_iter() .filter_map(|bookmark| { let path = uri_to_path(bookmark.href)?; - let last_edit = bookmark.modified.parse::>().ok()?; - let last_visit = bookmark.visited.parse::>().ok()?; + let last_edit = bookmark.modified.parse::().ok()?; + let last_visit = bookmark.visited.parse::().ok()?; if path.exists() { let file_name = path.file_name()?;