Skip to content

Commit bbac767

Browse files
committed
chore(deps): Replace chrono with jiff
1 parent 7d57f61 commit bbac767

File tree

4 files changed

+35
-178
lines changed

4 files changed

+35
-178
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## Changes
1212

13-
- Replace `humantime` crate with `jiff` crate, see #1690 (@sorairolake)
13+
- Replace `humantime` crate and `chrono` crate with `jiff` crate, see #1690 (@sorairolake)
1414

1515
## Other
1616

Cargo.lock

Lines changed: 12 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,12 @@ normpath = "1.1.1"
4848
crossbeam-channel = "0.5.14"
4949
clap_complete = {version = "4.5.44", optional = true}
5050
faccess = "0.2.4"
51-
jiff = { version = "0.2.4", default-features = false, features = ["std"] }
51+
jiff = "0.2.4"
5252

5353
[dependencies.clap]
5454
version = "4.5.31"
5555
features = ["suggestions", "color", "wrap_help", "cargo", "derive"]
5656

57-
[dependencies.chrono]
58-
version = "0.4.39"
59-
default-features = false
60-
features = ["std", "clock"]
61-
6257
[dependencies.lscolors]
6358
version = "0.20"
6459
default-features = false

src/filter/time.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};
2-
use jiff::{Span, Zoned};
1+
use jiff::{civil::DateTime, tz::TimeZone, Span, Timestamp, Zoned};
32

43
use std::time::SystemTime;
54

@@ -14,33 +13,28 @@ impl TimeFilter {
1413
fn from_str(ref_time: &SystemTime, s: &str) -> Option<SystemTime> {
1514
s.parse::<Span>()
1615
.and_then(|duration| {
17-
Zoned::try_from(*ref_time).and_then(|zoned| zoned.checked_sub(duration))
16+
Zoned::try_from(*ref_time).and_then(|zdt| zdt.checked_sub(duration))
1817
})
19-
.map(SystemTime::from)
2018
.ok()
2119
.or_else(|| {
22-
DateTime::parse_from_rfc3339(s)
23-
.map(|dt| dt.into())
20+
let local_tz = TimeZone::system();
21+
s.parse::<Timestamp>()
22+
.map(|ts| ts.to_zoned(TimeZone::UTC))
2423
.ok()
2524
.or_else(|| {
26-
NaiveDate::parse_from_str(s, "%F")
27-
.ok()?
28-
.and_hms_opt(0, 0, 0)?
29-
.and_local_timezone(Local)
30-
.latest()
31-
})
32-
.or_else(|| {
33-
NaiveDateTime::parse_from_str(s, "%F %T")
34-
.ok()?
35-
.and_local_timezone(Local)
36-
.latest()
25+
s.parse::<DateTime>()
26+
.map(|dt| local_tz.to_ambiguous_zoned(dt))
27+
.and_then(|zdt| zdt.later())
28+
.ok()
3729
})
3830
.or_else(|| {
3931
let timestamp_secs = s.strip_prefix('@')?.parse().ok()?;
40-
DateTime::from_timestamp(timestamp_secs, 0).map(Into::into)
32+
Timestamp::from_second(timestamp_secs)
33+
.map(|ts| ts.to_zoned(TimeZone::UTC))
34+
.ok()
4135
})
42-
.map(|dt| dt.into())
4336
})
37+
.map(SystemTime::from)
4438
}
4539

4640
pub fn before(ref_time: &SystemTime, s: &str) -> Option<TimeFilter> {
@@ -66,10 +60,10 @@ mod tests {
6660

6761
#[test]
6862
fn is_time_filter_applicable() {
69-
let ref_time = NaiveDateTime::parse_from_str("2010-10-10 10:10:10", "%F %T")
70-
.unwrap()
71-
.and_local_timezone(Local)
72-
.latest()
63+
let local_tz = TimeZone::system();
64+
let ref_time = local_tz
65+
.to_ambiguous_zoned("2010-10-10 10:10:10".parse::<DateTime>().unwrap())
66+
.later()
7367
.unwrap()
7468
.into();
7569

@@ -125,7 +119,8 @@ mod tests {
125119
.unwrap()
126120
.applies_to(&t1m_ago));
127121

128-
let ref_time = DateTime::parse_from_rfc3339("2010-10-10T10:10:10+00:00")
122+
let ref_time = "2010-10-10T10:10:10+00:00"
123+
.parse::<Timestamp>()
129124
.unwrap()
130125
.into();
131126
let t1m_ago = ref_time - Duration::from_secs(60);
@@ -145,7 +140,8 @@ mod tests {
145140
.applies_to(&t1m_ago));
146141

147142
let ref_timestamp = 1707723412u64; // Mon Feb 12 07:36:52 UTC 2024
148-
let ref_time = DateTime::parse_from_rfc3339("2024-02-12T07:36:52+00:00")
143+
let ref_time = "2024-02-12T07:36:52+00:00"
144+
.parse::<Timestamp>()
149145
.unwrap()
150146
.into();
151147
let t1m_ago = ref_time - Duration::from_secs(60);

0 commit comments

Comments
 (0)