diff --git a/src/main.rs b/src/main.rs index 011692e..737c063 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ impl Display for Ended { impl StdError for Ended {} #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> anyhow::Result<(), Box> { let (tx, mut rx) = broadcast::channel(16); tokio::select! { @@ -85,7 +85,7 @@ async fn main() -> Result<(), Box> { } } -async fn _main(tx: Sender<()>) -> Result<(), Box> { +async fn _main(tx: Sender<()>) -> anyhow::Result<(), Box> { env_logger::init(); dotenv()?; diff --git a/src/time_parser.rs b/src/time_parser.rs index 3dedd87..ad04b85 100644 --- a/src/time_parser.rs +++ b/src/time_parser.rs @@ -200,8 +200,28 @@ impl TimeParser { } pub async fn natural_parser(time: &str, _timezone: &str) -> Option { - 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, - 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; }