diff options
author | cos <cos> | 2021-07-03 17:09:24 +0200 |
---|---|---|
committer | cos <cos> | 2021-07-03 21:32:49 +0200 |
commit | 9849bfe7bf44c6f5cac34fad24fa351c4e3998c7 (patch) | |
tree | bfdeb857928d86245855ab3247b576dc525c444a /src/lib.rs | |
parent | 520ad1478675288d2ebd1bbfc1fdbe66c41e2b55 (diff) | |
download | two-timer-fix/correct_24h_time.zip |
Correct 24h timefix/correct_24h_time
While respecting that there is one culture which has colonized this planet, as
well as managed to make its language the lingua franca of the contemporary
world, its typical use of 12h time can not excuse going as wild with "parsing
English time expressions" as this crate does prior to this commit.
One might consult https://en.wikipedia.org/wiki/24-hour_clock to learn about
reasonable expectations.
Specifically, this fixes the bugs:
* No times during the interval 00:00-00:59 were allowed.
* The time 24:00 was considered 00:00, of the wrong (preceeding) day.
* Bogus times in the interval 24:00-24:59 were allowed.
After this commit 24:00 becomes an invalid time. Correctly rewriting it to
00:00, with overflow to the next day, is left as an excercise to whoever feels
strongly enough for that edge functionality.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 9 |
1 files changed, 2 insertions, 7 deletions
@@ -354,7 +354,7 @@ lazy_static! { end => ("end") from_now_or_ago => [["from now", "ago"]] h12 => (?-B) [(1..=12).into_iter().collect::<Vec<_>>()] - h24 => [(1..=24).into_iter().flat_map(|i| vec![format!("{}", i), format!("{:02}", i)]).collect::<Vec<_>>()] + h24 => [(0..24).into_iter().flat_map(|i| vec![format!("{}", i), format!("{:02}", i)]).collect::<Vec<_>>()] minute => (?-B) [ (0..60).into_iter().map(|i| format!("{:02}", i)).collect::<Vec<_>>() ] modifier => [["the", "this", "last", "next"]] named_time => [["noon", "midnight"]] @@ -1518,12 +1518,7 @@ fn time(m: &Match) -> (u32, u32, u32, bool) { }; } let hour = if let Some(hour_24) = m.name("hour_24") { - let hour = s_to_n(hour_24.name("h24").unwrap().as_str()); - if hour == 24 { - 0 - } else { - hour - } + s_to_n(hour_24.name("h24").unwrap().as_str()) } else if let Some(hour_12) = m.name("hour_12") { let mut hour = s_to_n(hour_12.name("h12").unwrap().as_str()); hour = if let Some(am_pm) = m.name("am_pm") { |