From 6d9b268776bb87f9057139c4869b741a1a6999cd Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Mon, 16 May 2016 09:13:45 -0500 Subject: [PATCH] Add tests confirming DateTime works with " " seperator instead of "T" --- src/types/chrono.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/types/chrono.rs b/src/types/chrono.rs index dd63c40..39a7093 100644 --- a/src/types/chrono.rs +++ b/src/types/chrono.rs @@ -129,7 +129,7 @@ impl FromSql for DateTime { #[cfg(test)] mod test { use Connection; - use super::chrono::{DateTime, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, UTC}; + use super::chrono::{DateTime, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, UTC, Duration}; fn checked_memory_handle() -> Connection { let db = Connection::open_in_memory().unwrap(); @@ -192,8 +192,15 @@ mod test { let s: String = db.query_row("SELECT t FROM foo", &[], |r| r.get(0)).unwrap(); assert_eq!("2016-02-23T23:56:04.789+00:00", s); - let v: DateTime = db.query_row("SELECT t FROM foo", &[], |r| r.get(0)).unwrap(); - assert_eq!(utc, v); + + let v1: DateTime = db.query_row("SELECT t FROM foo", &[], |r| r.get(0)).unwrap(); + assert_eq!(utc, v1); + + let v2: DateTime = db.query_row("SELECT '2016-02-23 23:56:04.789'", &[], |r| r.get(0)).unwrap(); + assert_eq!(utc, v2); + + 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); } #[test]