Skip to content

Commit

Permalink
issue #1: support time like 6:15pm
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedonovan committed Sep 15, 2018
1 parent 20289e7 commit 6d2bd19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ mod tests {
assert_eq!(display(parse_date_string("2017-06-30 08:20:30",base,Dialect::Uk)),"2017-06-30T08:20:30+00:00");
assert_eq!(display(parse_date_string("2017-06-30 8.20",base,Dialect::Uk)),"2017-06-30T08:20:00+00:00");
assert_eq!(display(parse_date_string("2017-06-30 8.30pm",base,Dialect::Uk)),"2017-06-30T20:30:00+00:00");
assert_eq!(display(parse_date_string("2017-06-30 8:30pm",base,Dialect::Uk)),"2017-06-30T20:30:00+00:00");
assert_eq!(display(parse_date_string("2017-06-30 2am",base,Dialect::Uk)),"2017-06-30T02:00:00+00:00");
assert_eq!(display(parse_date_string("30 June 2018",base,Dialect::Uk)),"2018-06-30T00:00:00+00:00");
assert_eq!(display(parse_date_string("June 30, 2018",base,Dialect::Uk)),"2018-06-30T00:00:00+00:00");
Expand Down
25 changes: 21 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,32 @@ impl <'a> DateParser<'a> {

fn formal_time(&mut self, hour: u32) -> DateResult<TimeSpec> {
let min = self.s.get_int::<u32>()?;
// minute may be followed by [:secs][am|pm]
let mut tnext = None;
let sec = if let Some(t) = self.s.next() {
let ch = t.to_char_result()?;
if ch != ':' {
return date_result("expecting ':'");
if let Some(ch) = t.as_char() {
if ch != ':' {
return date_result("expecting ':'");
}
self.s.get_int::<u32>()?
} else {
tnext = Some(t);
0
}
self.s.get_int::<u32>()?
} else {
0
};
// we found seconds, look ahead
if tnext.is_none() {
tnext = self.s.next();
}
// can only be am/pm
let hour = if let Some(t) = tnext {
let name = t.to_iden_result()?;
DateParser::am_pm(&name,hour)?
} else {
hour
};
Ok(TimeSpec::new(hour,min,sec))
}

Expand Down

0 comments on commit 6d2bd19

Please sign in to comment.