From 9f14a0f3f97792c186d5930af541a4ace2966354 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 22 Aug 2024 11:13:35 +0300 Subject: [PATCH] feat: parse plain hour when adjusting tracking --- src/helpers.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 3657d1d..6e5b997 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -41,14 +41,22 @@ pub fn parse_date(str: &str) -> Option> { } } +/// Turn a human-readable relative timestamp into a nostr Timestamp. +/// - Plain number as hour, 18 hours back or 6 hours forward +/// - Number with prefix as minute offset +/// - Otherwise try to parse a relative date pub fn parse_tracking_stamp(str: &str) -> Option { + if let Some(num) = parse_hour(str, 6) { + return Some(Timestamp::from(num.to_utc().timestamp() as u64)); + } let stripped = str.trim().trim_start_matches('+').trim_start_matches("in "); if let Ok(num) = stripped.parse::() { return Some(Timestamp::from(Timestamp::now().as_u64().saturating_add_signed(num * 60))); } parse_date(str).and_then(|time| { - if time.timestamp() > 0 { - Some(Timestamp::from(time.timestamp() as u64)) + let stamp = time.to_utc().timestamp(); + if stamp > 0 { + Some(Timestamp::from(stamp as u64)) } else { warn!("Can only track times after 1970!"); None