From 0d001583b24432d4e679ced6c381d3c3d39f24fa Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 11 Jul 2017 17:01:25 +0200 Subject: [PATCH 1/5] Fixed loss of time information during string conversion --- src/types/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/time.rs b/src/types/time.rs index 7f74b65..42e088d 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -3,7 +3,7 @@ extern crate time; use Result; use types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S"; +const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%f %z"; impl ToSql for time::Timespec { fn to_sql(&self) -> Result { From 0a114c4436e66faa468da3d704e40ee5ce2c567e Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 11 Jul 2017 17:15:07 +0200 Subject: [PATCH 2/5] Fixed loss of time information during string conversion --- src/types/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/time.rs b/src/types/time.rs index 42e088d..b8e7dc3 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -3,7 +3,7 @@ extern crate time; use Result; use types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%f %z"; +const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%f"; impl ToSql for time::Timespec { fn to_sql(&self) -> Result { From 8bc97972f8e37debc6397dffa81ef2b5d27a5586 Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 18 Jul 2017 17:43:25 +0200 Subject: [PATCH 3/5] fixed %F instead of %F:%s --- src/types/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/time.rs b/src/types/time.rs index b8e7dc3..4e75cb2 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -3,7 +3,7 @@ extern crate time; use Result; use types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%f"; +const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S:%f"; impl ToSql for time::Timespec { fn to_sql(&self) -> Result { From 6188a6a97c716083b7af056f86328a8736c60473 Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 18 Jul 2017 17:46:49 +0200 Subject: [PATCH 4/5] added more tests --- src/types/time.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/types/time.rs b/src/types/time.rs index 4e75cb2..a88c695 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -42,15 +42,27 @@ mod test { fn test_timespec() { let db = checked_memory_handle(); - let ts = time::Timespec { - sec: 10_000, - nsec: 0, - }; - db.execute("INSERT INTO foo(t) VALUES (?)", &[&ts]) - .unwrap(); + let mut ts_vec = vec![]; + + ts_vec.push(time::Timespec::new(10_000, 0));//January 1, 1970 2:46:40 AM + ts_vec.push(time::Timespec::new(10_000, 1000));//January 1, 1970 2:46:40 AM (and one microsecond) + ts_vec.push(time::Timespec::new(1500391124, 1_000_000));//July 18, 2017 + ts_vec.push(time::Timespec::new(2000000000, 2_000_000));//May 18, 2033 + ts_vec.push(time::Timespec::new(3000000000, 999_999_999));//January 24, 2065 + ts_vec.push(time::Timespec::new(10000000000, 0));//November 20, 2286 + + for ts in ts_vec { + + db.execute("INSERT INTO foo(t) VALUES (?)", &[&ts]) + .unwrap(); + + let from: time::Timespec = db.query_row("SELECT t FROM foo", &[], |r| r.get(0)) + .unwrap(); + + db.execute("DELETE FROM foo", &[]).unwrap(); + + assert_eq!(from, ts); + } - let from: time::Timespec = db.query_row("SELECT t FROM foo", &[], |r| r.get(0)) - .unwrap(); - assert_eq!(from, ts); } } From 301634add765ef4abd0cdd9150faf800ebbce566 Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 18 Jul 2017 09:56:02 -0600 Subject: [PATCH 5/5] fixed timezone issue --- src/types/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/time.rs b/src/types/time.rs index a88c695..703d70e 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -3,7 +3,7 @@ extern crate time; use Result; use types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, ValueRef}; -const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S:%f"; +const SQLITE_DATETIME_FMT: &'static str = "%Y-%m-%d %H:%M:%S:%f %Z"; impl ToSql for time::Timespec { fn to_sql(&self) -> Result {