natural_parser returns a valid UNIX timestamp now
This commit is contained in:
parent
c5c64d6772
commit
a3aa234b2e
@ -76,7 +76,7 @@ impl Display for Ended {
|
||||
impl StdError for Ended {}
|
||||
|
||||
#[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);
|
||||
|
||||
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();
|
||||
|
||||
dotenv()?;
|
||||
|
@ -200,8 +200,28 @@ impl TimeParser {
|
||||
}
|
||||
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user