Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #871 +/- ##
==========================================
- Coverage 92.27% 92.24% -0.04%
==========================================
Files 35 35
Lines 7576 7595 +19
Branches 393 397 +4
==========================================
+ Hits 6991 7006 +15
- Misses 443 445 +2
- Partials 142 144 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| writeln!(out, "Database was last modified at {}", time)?; | ||
| if let Ok(ts) = jiff::Timestamp::try_from(time) { | ||
| let time = ts.to_zoned(jiff::tz::TimeZone::system()); | ||
| writeln!(out, "Database was last modified at {}", time)?; |
There was a problem hiding this comment.
this changes the output: chrono printed 2025-01-15 09:30:21.123 +01:00, jiff's Display prints 2025-01-15T09:30:21.123+01:00[Europe/Paris].
is that intended? if not, please use an explicit strftime.
| format!("{} {}", now.strftime("%b"), now.strftime("%d")), | ||
| |m| m.as_str().to_string(), | ||
| ); | ||
| let mut month_chars = month_day.chars(); |
There was a problem hiding this comment.
why is this needed? jiff's %b parsing is already case-insensitive, so this could be removed, no?
| .to_string() | ||
| zoned.strftime(CTIME_FORMAT).to_string() | ||
| } | ||
| Self::Strftime(format) => zoned.strftime(format).to_string(), |
There was a problem hiding this comment.
strftime(..).to_string() panics if formatting fails.
apply already returns a Result, could you please use jiff::fmt::strtime::format and ? here?
| Err(format!("Invalid time specifier: %{first}{c}").into()) | ||
| } | ||
| Some(_item) => Ok(TimeFormat::Strftime(format)), | ||
| let dummy = jiff::Zoned::now(); |
There was a problem hiding this comment.
do we need Zoned::now() for every specifier? a fixed timestamp would do.
| .start_of_day() | ||
| .unwrap(); | ||
| let ts = midnight.timestamp(); | ||
| UNIX_EPOCH + Duration::from_secs(ts.as_second() as u64) |
There was a problem hiding this comment.
SystemTime::from(midnight.timestamp()) would avoid the as u64 cast, no?
|
|
||
| #[test] | ||
| #[cfg(target_pointer_width = "64")] | ||
| fn db_too_old_ignores_max_age_beyond_chrono_range() { |
There was a problem hiding this comment.
the name still says chrono, please rename it (or drop it if it no longer tests anything specific)
| if let Ok(datetime) = jiff::civil::DateTime::strptime("%Y-%m-%d %H:%M:%S", date_str) { | ||
| return Some( | ||
| datetime | ||
| .to_zoned(jiff::tz::TimeZone::UTC) |
There was a problem hiding this comment.
.to_zoned(TimeZone::UTC).ok()?.timestamp().as_millisecond() appears 3 times, could be dedup, no?
TimeZone::UTC.to_timestamp(dt) is shorter too.
|
|
||
| impl TimeFormat { | ||
| fn apply(&self, time: SystemTime) -> Result<Cow<'static, str>, Box<dyn Error>> { | ||
| let zoned = jiff::Timestamp::try_from(time)?.to_zoned(jiff::tz::TimeZone::system()); |
There was a problem hiding this comment.
this is now computed for SinceEpoch too, where it isn't used, and it can make %A@ fail for times outside jiff's range.
could you please move it into the branches that need it?
b015f8a to
277c26b
Compare
| #[cfg(target_pointer_width = "64")] | ||
| fn db_too_old_ignores_max_age_beyond_chrono_range() { | ||
| assert!(!is_db_too_old(TimeDelta::days(1), 1_000_000_000_000)); | ||
| fn db_too_old_ignores_max_age_beyond_range() { |
There was a problem hiding this comment.
with checked_mul, 1e12 days no longer overflows, so this test is now the same as db_too_old_compares_ordinary_ages.
could you please drop it, or use a value that really overflows?
| let system_time = metadata.modified().unwrap(); | ||
| let now_utc: DateTime<chrono::Utc> = system_time.into(); | ||
| now_utc.format("%b %e %H:%M") | ||
| let ts = jiff::Timestamp::try_from(system_time).unwrap(); |
There was a problem hiding this comment.
could we avoid the unwrap() here? a file with an mtime outside jiff's range would make -ls panic
| let year = match captures.get(2) { | ||
| Some(m) => m.as_str().parse().ok()?, | ||
| None => now.year(), | ||
| None => now.year() as i32, |
There was a problem hiding this comment.
i32::from(now.year()) instead of as, no?
| let now_but_zero_hour_min_sec = Utc::now() | ||
| .date_naive() | ||
| .and_hms_opt(0, 0, 0) | ||
| let now_but_zero_hour_min_sec = jiff::Timestamp::now() |
There was a problem hiding this comment.
TimeZone::UTC.to_timestamp(..) would be shorter here too, like in the function
277c26b to
0892f09
Compare
0892f09 to
4c0e5e6
Compare
4c0e5e6 to
6574658
Compare
6574658 to
ff99276
Compare
|
Commit ff99276 has test result changes: bfs testsuite: |
Replace
chronowithjiffacrossfindandlocate.