From 6a4abff462ff8442a682400831ffa6654a6208d9 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Mon, 16 May 2016 09:27:50 -0500 Subject: [PATCH] Restore support for full RFC3339 timestamps with a space seperator --- src/types/chrono.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/types/chrono.rs b/src/types/chrono.rs index 39a7093..4aaa63d 100644 --- a/src/types/chrono.rs +++ b/src/types/chrono.rs @@ -102,7 +102,16 @@ impl ToSql for DateTime { /// RFC3339 ("YYYY-MM-DDTHH:MM:SS.SSS[+-]HH:MM") into DateTime. impl FromSql for DateTime { unsafe fn column_result(stmt: *mut sqlite3_stmt, col: c_int) -> Result> { - let s = try!(String::column_result(stmt, col)); + let s = { + let mut s = try!(String::column_result(stmt, col)); + if s.len() >= 11 { + let sbytes = s.as_mut_vec(); + if sbytes[10] == b' ' { + sbytes[10] = b'T'; + } + } + s + }; match DateTime::parse_from_rfc3339(&s) { Ok(dt) => Ok(dt.with_timezone(&UTC)), Err(_) => NaiveDateTime::column_result(stmt, col).map(|dt| UTC.from_utc_datetime(&dt)), @@ -201,6 +210,9 @@ mod test { let v3: DateTime = db.query_row("SELECT '2016-02-23 23:56:04'", &[], |r| r.get(0)).unwrap(); assert_eq!(utc - Duration::milliseconds(789), v3); + + let v4: DateTime = db.query_row("SELECT '2016-02-23 23:56:04.789+00:00'", &[], |r| r.get(0)).unwrap(); + assert_eq!(utc, v4); } #[test]