parse durations and timestamps
This commit is contained in:
committed by
Dustin J. Mitchell
parent
288f29d9d5
commit
0259a5e2e2
@@ -1,4 +1,4 @@
|
||||
use super::any;
|
||||
use super::{any, timestamp};
|
||||
use crate::argparse::NOW;
|
||||
use chrono::prelude::*;
|
||||
use nom::bytes::complete::tag as nomtag;
|
||||
@@ -31,16 +31,6 @@ pub(crate) fn status_colon(input: &str) -> IResult<&str, Status> {
|
||||
map_res(colon_prefixed("status"), to_status)(input)
|
||||
}
|
||||
|
||||
/// Recognizes timestamps
|
||||
pub(crate) fn timestamp(input: &str) -> IResult<&str, DateTime<Utc>> {
|
||||
// TODO: full relative date language supported by TW
|
||||
fn nn_d_to_timestamp(input: &str) -> Result<DateTime<Utc>, ()> {
|
||||
// TODO: don't unwrap
|
||||
Ok(*NOW + chrono::Duration::days(input.parse().unwrap()))
|
||||
}
|
||||
map_res(terminated(digit1, char('d')), nn_d_to_timestamp)(input)
|
||||
}
|
||||
|
||||
/// Recognizes `wait:` to None and `wait:<ts>` to `Some(ts)`
|
||||
pub(crate) fn wait_colon(input: &str) -> IResult<&str, Option<DateTime<Utc>>> {
|
||||
fn to_wait(input: DateTime<Utc>) -> Result<Option<DateTime<Utc>>, ()> {
|
||||
@@ -51,7 +41,10 @@ pub(crate) fn wait_colon(input: &str) -> IResult<&str, Option<DateTime<Utc>>> {
|
||||
}
|
||||
preceded(
|
||||
nomtag("wait:"),
|
||||
alt((map_res(timestamp, to_wait), map_res(nomtag(""), to_none))),
|
||||
alt((
|
||||
map_res(timestamp(*NOW, Local), to_wait),
|
||||
map_res(nomtag(""), to_none),
|
||||
)),
|
||||
)(input)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user