summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorcos <cos>2021-07-03 17:09:24 +0200
committercos <cos>2021-07-03 21:32:49 +0200
commit9849bfe7bf44c6f5cac34fad24fa351c4e3998c7 (patch)
treebfdeb857928d86245855ab3247b576dc525c444a /tests
parent520ad1478675288d2ebd1bbfc1fdbe66c41e2b55 (diff)
downloadtwo-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 'tests')
-rw-r--r--tests/tests.rs38
1 files changed, 30 insertions, 8 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index a2852d8..1c593be 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1587,18 +1587,40 @@ fn simple_noon_past_and_future() {
fn midnight() {
let d1 = NaiveDate::from_ymd(1969, 5, 7).and_hms(0, 0, 0);
let d2 = d1 + Duration::seconds(1);
- match parse("midnight on May 6, 1969", None) {
- Ok((start, end, _)) => {
- assert_eq!(d1, start);
- assert_eq!(d2, end);
- }
- Err(e) => {
- println!("{:?}", e);
- assert!(false, "didn't match");
+ for phrase in [
+ "midnight on May 6, 1969",
+ // TODO Add 12h representation, whichever is considered midnight?!
+ // Possible am/pm might differ between GB and some colonial time
+ // representations, just as an imperial gallon is roughly 4.5
+ // litres while a US gallon is not even 3.8 liters.
+ "00:00 on May 7, 1969", ].iter()
+ {
+ match parse(phrase, None) {
+ Ok((start, end, _)) => {
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+ }
+ Err(e) => {
+ println!("{:?}", e);
+ assert!(false, "didn't match");
+ }
}
}
}
+#[test]
+fn invalid_24_00() {
+ // While 24:00 might arguably be an ok time, is not implemented in this crate.
+ let phrase = "24:00";
+ assert!(parse(phrase, None).is_err());
+}
+
+#[test]
+fn super_invalid_24_30() {
+ let phrase = "24:30";
+ assert!(parse(phrase, None).is_err());
+}
+
#[derive(Debug)]
enum Period {
Week,