summaryrefslogtreecommitdiffstats
path: root/src/filter/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/filter/time.rs')
-rw-r--r--src/filter/time.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/filter/time.rs b/src/filter/time.rs
index 0070e5e..4777f0f 100644
--- a/src/filter/time.rs
+++ b/src/filter/time.rs
@@ -1,4 +1,4 @@
-use chrono::{DateTime, Local, NaiveDate, NaiveDateTime};
+use chrono::{DateTime, Local, NaiveDate, NaiveDateTime, Utc};
use std::time::SystemTime;
@@ -31,6 +31,13 @@ impl TimeFilter {
.and_local_timezone(Local)
.latest()
})
+ .or_else(|| {
+ let timestamp_secs = s.strip_prefix('@')?.parse().ok()?;
+ NaiveDateTime::from_timestamp_opt(timestamp_secs, 0)?
+ .and_local_timezone(Utc)
+ .latest()
+ .map(Into::into)
+ })
.map(|dt| dt.into())
})
}
@@ -135,5 +142,32 @@ mod tests {
assert!(!TimeFilter::after(&ref_time, t10s_before)
.unwrap()
.applies_to(&t1m_ago));
+
+ let ref_timestamp = 1707723412u64; // Mon Feb 12 07:36:52 UTC 2024
+ let ref_time = DateTime::parse_from_rfc3339("2024-02-12T07:36:52+00:00")
+ .unwrap()
+ .into();
+ let t1m_ago = ref_time - Duration::from_secs(60);
+ let t1s_later = ref_time + Duration::from_secs(1);
+ // Timestamp only supported via '@' prefix
+ assert!(TimeFilter::before(&ref_time, &ref_timestamp.to_string()).is_none());
+ assert!(
+ TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))
+ .unwrap()
+ .applies_to(&t1m_ago)
+ );
+ assert!(
+ !TimeFilter::before(&ref_time, &format!("@{}", ref_timestamp))
+ .unwrap()
+ .applies_to(&t1s_later)
+ );
+ assert!(
+ !TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))
+ .unwrap()
+ .applies_to(&t1m_ago)
+ );
+ assert!(TimeFilter::after(&ref_time, &format!("@{}", ref_timestamp))
+ .unwrap()
+ .applies_to(&t1s_later));
}
}