summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2019-01-20 13:47:09 -0500
committerdfhoughton <dfhoughton@gmail.com>2019-01-20 13:47:09 -0500
commit63cffe10d36371298486dfe611b003153c6bf561 (patch)
treea4e6926f93fc442e0c5ba733bb65a125513af0e2
parentd3fa93c177c650edd01c0e729f2f9da86c355ee5 (diff)
downloadtwo-timer-63cffe10d36371298486dfe611b003153c6bf561.zip
fixed regression
-rw-r--r--CHANGES.md4
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs9
-rw-r--r--tests/tests.rs32
5 files changed, 34 insertions, 15 deletions
diff --git a/CHANGES.md b/CHANGES.md
index ae699d6..8247ba7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,4 +7,6 @@
## 1.0.1
* removing some documentation
## 1.0.2
-* added `msg` method to `TimeError` \ No newline at end of file
+* added `msg` method to `TimeError`
+## 1.0.3
+* fixed "12 pm" bug \ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 9dadea0..a54b044 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -108,7 +108,7 @@ dependencies = [
[[package]]
name = "two_timer"
-version = "1.0.2"
+version = "1.0.3"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 55f896a..e796b51 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "two_timer"
-version = "1.0.2"
+version = "1.0.3"
authors = ["dfhoughton <dfhoughton@gmail.com>"]
description="parser for English time expressions"
homepage="https://github.com/dfhoughton/two-timer"
diff --git a/src/lib.rs b/src/lib.rs
index 3b345e7..c540152 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -972,14 +972,19 @@ fn time(m: &Match) -> (u32, Option<u32>, Option<u32>) {
let hour = if let Some(hour_24) = m.name("hour_24") {
s_to_n(hour_24.name("h24").unwrap().as_str())
} else if let Some(hour_12) = m.name("hour_12") {
- let hour = s_to_n(hour_12.name("h12").unwrap().as_str());
- if let Some(am_pm) = m.name("am_pm") {
+ let mut hour = s_to_n(hour_12.name("h12").unwrap().as_str());
+ hour = if let Some(am_pm) = m.name("am_pm") {
match am_pm.as_str().chars().nth(0).expect("empty string") {
'a' | 'A' => hour,
_ => hour + 12,
}
} else {
hour
+ };
+ if hour == 24 {
+ 0
+ } else {
+ hour
}
} else {
unreachable!()
diff --git a/tests/tests.rs b/tests/tests.rs
index c77eb1a..87d348b 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -17,7 +17,7 @@ fn always() {
"from beginning to end",
"from the beginning to the end",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(alpha, start);
@@ -74,7 +74,7 @@ fn day_5_6_69_at_3_30_pm() {
"at 15:30 on 5-6-69",
"15:30 on 5-6-69",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -91,7 +91,7 @@ fn day_5_6_69_at_3_pm() {
"at 15 on 5-6-69",
"15 on 5-6-69",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -108,7 +108,7 @@ fn day_5_6_69_at_3_30_00_pm() {
"at 15:30:00 on 5-6-69",
"15:30:00 on 5-6-69",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -125,7 +125,7 @@ fn day_5_6_69_at_3_30_01_pm() {
"at 15:30:01 on 5-6-69",
"15:30:01 on 5-6-69",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -142,7 +142,7 @@ fn day_5_6_69_at_3_30_01_am() {
"at 3:30:01 on 5-6-69",
"3:30:01 on 5-6-69",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -229,7 +229,7 @@ fn alphabetic_5_6_69() {
"T, May 6, '69",
"T, May 6, 69",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -314,7 +314,7 @@ fn ymd_5_31_69() {
"'69/31/05",
"'69.31.05",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -667,7 +667,7 @@ fn dawn_of_time() {
"the big bang",
"the birth of the universe",
]
- .iter()
+ .iter()
{
let (start, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, start);
@@ -698,7 +698,7 @@ fn the_crack_of_doom() {
"ever after",
"the last syllable of recorded time",
]
- .iter()
+ .iter()
{
let (_, end, _) = parse(phrase, None).unwrap();
assert_eq!(then, end);
@@ -1042,3 +1042,15 @@ fn next_weekend_on_saturday_when_sunday_starts_week() {
assert_eq!(d1, start);
assert_eq!(d2, end);
}
+
+#[test]
+fn regression_12pm() {
+ let d1 = NaiveDate::from_ymd(2018, 5, 21).and_hms(0, 0, 0);
+ let d2 = NaiveDate::from_ymd(2018, 5, 21).and_hms(1, 0, 0);
+ if let Ok((start, end, _)) = parse("12 pm on May 21, 2018", None) {
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+ } else {
+ assert!(false);
+ }
+}