refactor: use jiff instead of chrono

This commit is contained in:
Vukašin Vojinović 2026-03-14 20:53:50 +01:00 committed by Jacob Kauffmann
parent 4414d2f4b2
commit 3b1bc4430b
4 changed files with 38 additions and 48 deletions

View file

@ -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<R: io::Read + io::Seek, P: AsRef<Path>>(
}
fn zip_date_time_to_system_time(date_time: zip::DateTime) -> Option<SystemTime> {
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<zip::DateTime> {
let date_time: chrono::DateTime<chrono::Local> = system_time.into();
let date_time = Zoned::try_from(system_time).ok()?;
zip::DateTime::from_date_and_time(
date_time.year() as u16,

View file

@ -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::<chrono::Local>::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<Item> {
.into_iter()
.filter_map(|bookmark| {
let path = uri_to_path(bookmark.href)?;
let last_edit = bookmark.modified.parse::<chrono::DateTime<Utc>>().ok()?;
let last_visit = bookmark.visited.parse::<chrono::DateTime<Utc>>().ok()?;
let last_edit = bookmark.modified.parse::<jiff::Timestamp>().ok()?;
let last_visit = bookmark.visited.parse::<jiff::Timestamp>().ok()?;
if path.exists() {
let file_name = path.file_name()?;