refactor: use jiff instead of chrono
This commit is contained in:
parent
4414d2f4b2
commit
3b1bc4430b
4 changed files with 38 additions and 48 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
29
src/tab.rs
29
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::<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()?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue