Skip to content

Upgrade chrono to 0.4 #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ types. The driver currently supports the following conversions:
<tr>
<td>
<a href="https://github.com/rust-lang-deprecated/time">time::Timespec</a>,
<a href="https://github.com/lifthrasiir/rust-chrono">chrono::DateTime&lt;UTC&gt;</a>,
<a href="https://github.com/lifthrasiir/rust-chrono">chrono::DateTime&lt;Utc&gt;</a>,
<a href="https://github.com/lifthrasiir/rust-chrono">chrono::DateTime&lt;Local&gt;</a>,
and
<a href="https://github.com/lifthrasiir/rust-chrono">chrono::DateTime&lt;FixedOffset&gt;</a>
Expand Down
2 changes: 1 addition & 1 deletion postgres-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
18 changes: 9 additions & 9 deletions postgres-shared/src/types/chrono.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -39,18 +39,18 @@ impl ToSql for NaiveDateTime {
to_sql_checked!();
}

impl FromSql for DateTime<UTC> {
impl FromSql for DateTime<Utc> {
fn from_sql(type_: &Type,
raw: &[u8])
-> Result<DateTime<UTC>, Box<Error + Sync + Send>> {
-> Result<DateTime<Utc>, Box<Error + Sync + Send>> {
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<UTC> {
impl ToSql for DateTime<Utc> {
fn to_sql(&self,
type_: &Type,
w: &mut Vec<u8>)
Expand All @@ -66,7 +66,7 @@ impl FromSql for DateTime<Local> {
fn from_sql(type_: &Type,
raw: &[u8])
-> Result<DateTime<Local>, Box<Error + Sync + Send>> {
let utc = DateTime::<UTC>::from_sql(type_, raw)?;
let utc = DateTime::<Utc>::from_sql(type_, raw)?;
Ok(utc.with_timezone(&Local))
}

Expand All @@ -78,7 +78,7 @@ impl ToSql for DateTime<Local> {
type_: &Type,
mut w: &mut Vec<u8>)
-> Result<IsNull, Box<Error + Sync + Send>> {
self.with_timezone(&UTC).to_sql(type_, w)
self.with_timezone(&Utc).to_sql(type_, w)
}

accepts!(Type::Timestamptz);
Expand All @@ -89,7 +89,7 @@ impl FromSql for DateTime<FixedOffset> {
fn from_sql(type_: &Type,
raw: &[u8])
-> Result<DateTime<FixedOffset>, Box<Error + Sync + Send>> {
let utc = DateTime::<UTC>::from_sql(type_, raw)?;
let utc = DateTime::<Utc>::from_sql(type_, raw)?;
Ok(utc.with_timezone(&FixedOffset::east(0)))
}

Expand All @@ -101,7 +101,7 @@ impl ToSql for DateTime<FixedOffset> {
type_: &Type,
w: &mut Vec<u8>)
-> Result<IsNull, Box<Error + Sync + Send>> {
self.with_timezone(&UTC).to_sql(type_, w)
self.with_timezone(&Utc).to_sql(type_, w)
}

accepts!(Type::Timestamptz);
Expand Down
4 changes: 2 additions & 2 deletions postgres-shared/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl WrongType {
/// | `serde_json::Value` | JSON, JSONB |
/// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
/// | `chrono::NaiveDateTime` | TIMESTAMP |
/// | `chrono::DateTime<UTC>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::DateTime<Utc>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::DateTime<Local>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::DateTime<FixedOffset>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::NaiveDate` | DATE |
Expand Down Expand Up @@ -461,7 +461,7 @@ pub enum IsNull {
/// | `serde_json::Value` | JSON, JSONB |
/// | `time::Timespec` | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
/// | `chrono::NaiveDateTime` | TIMESTAMP |
/// | `chrono::DateTime<UTC>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::DateTime<Utc>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::DateTime<Local>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::DateTime<FixedOffset>` | TIMESTAMP WITH TIME ZONE |
/// | `chrono::NaiveDate` | DATE |
Expand Down
2 changes: 1 addition & 1 deletion postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions postgres/tests/types/chrono.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<DateTime<UTC>>, &'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<DateTime<Utc>>, &'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'"),
Expand All @@ -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<DateTime<UTC>>, &'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<DateTime<Utc>>, &'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'"),
Expand Down