Skip to content

Commit

Permalink
parse datetime with space between date and time
Browse files Browse the repository at this point in the history
  • Loading branch information
rethab committed Jun 17, 2020
1 parent 06a9800 commit e9c3405
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn parse_date(string: &str) -> Option<DateTime<FixedOffset>> {
None.or_else(|| rfc3339(trimmed))
.or_else(|| cut(trimmed, 20).and_then(rfc3339))
.or_else(|| cut(trimmed, 19).map(|s| suffix(s, "Z")).and_then(rfc3339))
.or_else(|| DateTime::parse_from_str(trimmed, "%Y-%m-%d %H:%M:%S%.3f %z").ok())
.or_else(|| {
cut(trimmed, 16)
.map(|s| suffix(s, ":00Z"))
Expand Down Expand Up @@ -175,6 +176,11 @@ mod test {
Some(Utc.ymd(2014, 1, 11).and_hms(0, 0, 0).into())
);

assert_eq!(
parse_date("2014-01-11 01:18:21 +0000"),
Some(Utc.ymd(2014, 01, 11).and_hms(1, 18, 21).into())
);

assert_eq!(
parse_date("Fri, 12 Feb 2016 14:08:24 +0000"),
Some(Utc.ymd(2016, 2, 12).and_hms(14, 8, 24).into())
Expand Down

0 comments on commit e9c3405

Please sign in to comment.