natural_parser returns a valid UNIX timestamp now

This commit is contained in:
Sean McNamara 2022-12-01 07:22:40 -05:00
parent c5c64d6772
commit a3aa234b2e
2 changed files with 24 additions and 4 deletions

View File

@ -76,7 +76,7 @@ impl Display for Ended {
impl StdError for Ended {} impl StdError for Ended {}
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn StdError + Send + Sync>> { async fn main() -> anyhow::Result<(), Box<dyn StdError + Send + Sync>> {
let (tx, mut rx) = broadcast::channel(16); let (tx, mut rx) = broadcast::channel(16);
tokio::select! { tokio::select! {
@ -85,7 +85,7 @@ async fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
} }
} }
async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> { async fn _main(tx: Sender<()>) -> anyhow::Result<(), Box<dyn StdError + Send + Sync>> {
env_logger::init(); env_logger::init();
dotenv()?; dotenv()?;

View File

@ -200,8 +200,28 @@ impl TimeParser {
} }
pub async fn natural_parser(time: &str, _timezone: &str) -> Option<i64> { pub async fn natural_parser(time: &str, _timezone: &str) -> Option<i64> {
match to_event(time).get_timestamp() { println!("natural_parser of {}", time);
let evt = to_event(time);
println!("to_event: {}", evt.to_string());
let ts = evt.get_start();
let ts2 = match ts {
None => None, None => None,
Some(x) => Some(x.timestamp()) Some(x) => match x {
DatePerhapsTime::DateTime(y) => match y {
CalendarDateTime::Floating(z) => Some(z.timestamp()),
CalendarDateTime::Utc(z) => Some(z.timestamp()),
CalendarDateTime::WithTimezone { date_time, tzid } => Some(date_time.timestamp()),
},
DatePerhapsTime::Date(y) => Some(y.and_hms_opt(0,0,0).unwrap().timestamp()),
} }
};
if ts2.is_none() {
println!("No timestamp for {}", time);
}
else {
println!("Timestamp for {} = {}", time, ts2.unwrap());
}
return ts2;
} }