Skip to content
Myr

Fix deprecation warning from chrono

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Also change logic to use the latest time if the local time is ambiguous (for example due to daylight savings)

authored by Thayne McCombs · committed by David Peter · parent e6aa8e8 · Browse files · 2 files+16 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−8 removed

  • other:+16 added−8 removed

2 files+16 added−8 removed

modified:src/filter/time.rs+15 added-7 removed
1use chrono::{offset::TimeZone, DateTime, Local, NaiveDate};1use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};23use std::time::SystemTime;45/// Filter based on time ranges.
13 unmodified lines
19 .map(|dt| dt.into())20 .ok()21 .or_else(|| {22 NaiveDate::parse_from_str(s, "%F")23 .ok()24 .and_then(|nd| nd.and_hms_opt(0, 0, 0))25 .and_then(|ndt| Local.from_local_datetime(&ndt).single())23 .ok()?24 .and_hms_opt(0, 0, 0)?25 .and_local_timezone(Local)26 .latest()27 })27 .or_else(|| Local.datetime_from_str(s, "%F %T").ok())28 .or_else(|| {29 NaiveDateTime::parse_from_str(s, "%F %T")30 .ok()?31 .and_local_timezone(Local)32 .latest()33 })34 .map(|dt| dt.into())35 })36 }37
19 unmodified lines
57 use std::time::Duration;5859 #[test]60 fn is_time_filter_applicable() {55 let ref_time = Local56 .datetime_from_str("2010-10-10 10:10:10", "%F %T")61 let ref_time = NaiveDateTime::parse_from_str("2010-10-10 10:10:10", "%F %T")62 .unwrap()63 .and_local_timezone(Local)64 .latest()65 .unwrap()66 .into();6768 assert!(TimeFilter::after(&ref_time, "1min")69 .unwrap()
70 unmodified lines
modified:Cargo.toml+1 added-1 removed