From 1263e39fb3537163b43498ca5184d619a68602a5 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 26 Aug 2024 22:37:29 +0300 Subject: [PATCH] fix: parse date without numbers as day start --- src/helpers.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 394f9e2..40a3fb2 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,6 +1,6 @@ use std::ops::Sub; -use chrono::{DateTime, Local, TimeDelta, TimeZone, Utc}; +use chrono::{DateTime, Local, NaiveTime, TimeDelta, TimeZone, Utc}; use chrono::LocalResult::Single; use log::{debug, error, info, trace, warn}; use nostr_sdk::Timestamp; @@ -40,7 +40,15 @@ pub fn parse_date(str: &str) -> Option> { } } } - } + }.map(|time| { + // TODO properly map date without time to day start, also support intervals + if str.chars().any(|c| c.is_numeric()) { + time + } else { + #[allow(deprecated)] + time.date().and_time(NaiveTime::default()).unwrap() + } + }) } /// Turn a human-readable relative timestamp into a nostr Timestamp.