From e3af8fdb94ee85fede2ef0bb1786dc8ea049029e Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Fri, 30 Jun 2017 23:40:08 +0800 Subject: [PATCH] Upgrade chrono to 0.4 --- README.md | 2 +- postgres-shared/Cargo.toml | 2 +- postgres-shared/src/types/chrono.rs | 18 +++++++++--------- postgres-shared/src/types/mod.rs | 4 ++-- postgres/Cargo.toml | 2 +- postgres/tests/types/chrono.rs | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5e2cef137..019e3d47d 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ types. The driver currently supports the following conversions: time::Timespec, - chrono::DateTime<UTC>, + chrono::DateTime<Utc>, chrono::DateTime<Local>, and chrono::DateTime<FixedOffset> diff --git a/postgres-shared/Cargo.toml b/postgres-shared/Cargo.toml index 035ef0ad6..d78b91bcc 100644 --- a/postgres-shared/Cargo.toml +++ b/postgres-shared/Cargo.toml @@ -23,7 +23,7 @@ phf = "=0.7.21" postgres-protocol = { version = "0.3", path = "../postgres-protocol" } bit-vec = { version = "0.4", optional = true } -chrono = { version = "0.3", optional = true } +chrono = { version = "0.4", optional = true } eui48 = { version = "0.1", optional = true } geo = { version = "0.4", optional = true } rustc-serialize = { version = "0.3", optional = true } diff --git a/postgres-shared/src/types/chrono.rs b/postgres-shared/src/types/chrono.rs index ad796f138..c7670a627 100644 --- a/postgres-shared/src/types/chrono.rs +++ b/postgres-shared/src/types/chrono.rs @@ -1,7 +1,7 @@ extern crate chrono; use postgres_protocol::types; -use self::chrono::{Duration, NaiveDate, NaiveTime, NaiveDateTime, DateTime, UTC, Local, +use self::chrono::{Duration, NaiveDate, NaiveTime, NaiveDateTime, DateTime, Utc, Local, FixedOffset}; use std::error::Error; @@ -39,18 +39,18 @@ impl ToSql for NaiveDateTime { to_sql_checked!(); } -impl FromSql for DateTime { +impl FromSql for DateTime { fn from_sql(type_: &Type, raw: &[u8]) - -> Result, Box> { + -> Result, Box> { let naive = NaiveDateTime::from_sql(type_, raw)?; - Ok(DateTime::from_utc(naive, UTC)) + Ok(DateTime::from_utc(naive, Utc)) } accepts!(Type::Timestamptz); } -impl ToSql for DateTime { +impl ToSql for DateTime { fn to_sql(&self, type_: &Type, w: &mut Vec) @@ -66,7 +66,7 @@ impl FromSql for DateTime { fn from_sql(type_: &Type, raw: &[u8]) -> Result, Box> { - let utc = DateTime::::from_sql(type_, raw)?; + let utc = DateTime::::from_sql(type_, raw)?; Ok(utc.with_timezone(&Local)) } @@ -78,7 +78,7 @@ impl ToSql for DateTime { type_: &Type, mut w: &mut Vec) -> Result> { - self.with_timezone(&UTC).to_sql(type_, w) + self.with_timezone(&Utc).to_sql(type_, w) } accepts!(Type::Timestamptz); @@ -89,7 +89,7 @@ impl FromSql for DateTime { fn from_sql(type_: &Type, raw: &[u8]) -> Result, Box> { - let utc = DateTime::::from_sql(type_, raw)?; + let utc = DateTime::::from_sql(type_, raw)?; Ok(utc.with_timezone(&FixedOffset::east(0))) } @@ -101,7 +101,7 @@ impl ToSql for DateTime { type_: &Type, w: &mut Vec) -> Result> { - self.with_timezone(&UTC).to_sql(type_, w) + self.with_timezone(&Utc).to_sql(type_, w) } accepts!(Type::Timestamptz); diff --git a/postgres-shared/src/types/mod.rs b/postgres-shared/src/types/mod.rs index c18f6b815..3a3965e40 100644 --- a/postgres-shared/src/types/mod.rs +++ b/postgres-shared/src/types/mod.rs @@ -262,7 +262,7 @@ impl WrongType { /// | `serde_json::Value` | JSON, JSONB | /// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE | /// | `chrono::NaiveDateTime` | TIMESTAMP | -/// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | +/// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | /// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | /// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | /// | `chrono::NaiveDate` | DATE | @@ -461,7 +461,7 @@ pub enum IsNull { /// | `serde_json::Value` | JSON, JSONB | /// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE | /// | `chrono::NaiveDateTime` | TIMESTAMP | -/// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | +/// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | /// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | /// | `chrono::DateTime` | TIMESTAMP WITH TIME ZONE | /// | `chrono::NaiveDate` | DATE | diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index 1514f8b36..51670a8cf 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -60,7 +60,7 @@ hex = "0.2" url = "1.0" bit-vec = "0.4" -chrono = "0.3" +chrono = "0.4" eui48 = "0.1" geo = "0.4" rustc-serialize = "0.3" diff --git a/postgres/tests/types/chrono.rs b/postgres/tests/types/chrono.rs index 865854c89..6b1aaff29 100644 --- a/postgres/tests/types/chrono.rs +++ b/postgres/tests/types/chrono.rs @@ -1,6 +1,6 @@ extern crate chrono; -use self::chrono::{TimeZone, NaiveDate, NaiveTime, NaiveDateTime, DateTime, UTC}; +use self::chrono::{TimeZone, NaiveDate, NaiveTime, NaiveDateTime, DateTime, Utc}; use types::test_type; use postgres::types::{Date, Timestamp}; @@ -33,8 +33,8 @@ fn test_with_special_naive_date_time_params() { #[test] fn test_date_time_params() { - fn make_check<'a>(time: &'a str) -> (Option>, &'a str) { - (Some(UTC.datetime_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), time) + fn make_check<'a>(time: &'a str) -> (Option>, &'a str) { + (Some(Utc.datetime_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), time) } test_type("TIMESTAMP WITH TIME ZONE", &[make_check("'1970-01-01 00:00:00.010000000'"), @@ -45,8 +45,8 @@ fn test_date_time_params() { #[test] fn test_with_special_date_time_params() { - fn make_check<'a>(time: &'a str) -> (Timestamp>, &'a str) { - (Timestamp::Value(UTC.datetime_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), time) + fn make_check<'a>(time: &'a str) -> (Timestamp>, &'a str) { + (Timestamp::Value(Utc.datetime_from_str(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), time) } test_type("TIMESTAMP WITH TIME ZONE", &[make_check("'1970-01-01 00:00:00.010000000'"),