diff --git a/cli/src/argparse/args/time.rs b/cli/src/argparse/args/time.rs index 4581d0a41..47a82e1fc 100644 --- a/cli/src/argparse/args/time.rs +++ b/cli/src/argparse/args/time.rs @@ -154,11 +154,18 @@ fn named_date( move |input: &str| { let local_today = now.with_timezone(&local).date(); let remaining = &input[input.len()..]; + let day_index = local_today.weekday().num_days_from_monday(); match input { "yesterday" => Ok((remaining, local_today - Duration::days(1))), "today" => Ok((remaining, local_today)), "tomorrow" => Ok((remaining, local_today + Duration::days(1))), // TODO: lots more! + "eod" => Ok((remaining,local_today + Duration::days(1))), + "sod" => Ok((remaining,local_today)), + "eow" => Ok((remaining,local_today + Duration::days((6-day_index).into()))), + "eoww" => Ok((remaining,local_today + Duration::days((5-day_index).into()))), + "sow" => Ok((remaining,local_today + Duration::days((6-day_index).into()))), + "soww" => Ok((remaining,local_today + Duration::days((7-day_index).into()))), _ => Err(Err::Error(Error::new(input, ErrorKind::Tag))), } .map(|(rem, dt)| (rem, dt.and_hms(0, 0, 0).with_timezone(&Utc))) @@ -301,6 +308,12 @@ mod test { #[case::today_from_evening(ldt(2021, 3, 1, 21, 30, 30), "today", ld(2021, 3, 1))] #[case::tomorrow(ld(2021, 3, 1), "tomorrow", ld(2021, 3, 2))] #[case::tomorow_from_evening(ldt(2021, 3, 1, 21, 30, 30), "tomorrow", ld(2021, 3, 2))] + #[case::end_of_week(ld(2021,8,25,), "eow", ld(2021,8,29))] + #[case::end_of_work_week(ld(2021,8,25), "eoww", ld(2021,8,28))] + #[case::start_of_week(ld(2021,8,25), "sow", ld(2021,8,29))] + #[case::start_of_work_week(ld(2021,8,25), "soww", ld(2021,8,30))] + #[case::end_of_today(ld(2021,8,25), "eod", ld(2021,8,26))] + #[case::start_of_today(ld(2021,8,25), "sod", ld(2021,8,25))] fn test_local_timestamp( #[case] now: Box DateTime>, #[values(*IST, *UTC_FO, *HST)] tz: FixedOffset, diff --git a/docs/src/images/name_timestamp.png b/docs/src/images/name_timestamp.png new file mode 100644 index 000000000..d829039b7 Binary files /dev/null and b/docs/src/images/name_timestamp.png differ diff --git a/docs/src/time.md b/docs/src/time.md index b82e1b2e1..4053aea29 100644 --- a/docs/src/time.md +++ b/docs/src/time.md @@ -28,3 +28,21 @@ Some of the units allow an adjectival form, such as `daily` or `annually`; this [ISO 8601 standard durations](https://en.wikipedia.org/wiki/ISO_8601#Durations) are also allowed. While the standard does not specify the length of "P1Y" or "P1M", Taskchampion treats those as 365 and 30 days, respectively. + + +## Named Timestamps + +Some commonly used named timestamps + + * `today` Start of today + * `yesterday` Start of yesterday + * `tomorrow` Start of tomorrow + * `sod` Start of today + * `eod` End of today + * `sow` Start of the next week + * `eow` End of the week + * `eoww` End of work week + * `soww` Start of the next work week + + +![named timestamp](images/name_timestamp.png)