forked from janek/mostr
1
0
Fork 0

fix: parse date without numbers as day start

This commit is contained in:
xeruf 2024-08-26 22:37:29 +03:00
parent 714d4a4d5b
commit 1263e39fb3
1 changed files with 10 additions and 2 deletions

View File

@ -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<DateTime<Utc>> {
}
}
}
}
}.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.