diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index 59ae7726e5f3..dd939484d61b 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -13,7 +13,7 @@ categories = ["database"] [dependencies] byteorder = "1.0" -chrono = { version = "0.3", optional = true } +chrono = { version = "0.4", optional = true } clippy = { optional = true, version = "=0.0.126" } libc = { version = "0.2.0", optional = true } libsqlite3-sys = { version = ">=0.8.0, <0.9.0", optional = true, features = ["min_sqlite_version_3_7_16"] } diff --git a/diesel/src/mysql/types/date_and_time.rs b/diesel/src/mysql/types/date_and_time.rs index 4e214f776215..b8c1c96150b9 100644 --- a/diesel/src/mysql/types/date_and_time.rs +++ b/diesel/src/mysql/types/date_and_time.rs @@ -129,8 +129,7 @@ mod tests { extern crate dotenv; extern crate chrono; - use self::chrono::{Duration, NaiveDate, NaiveTime, UTC, TimeZone, FixedOffset}; - use self::chrono::naive::date; + use self::chrono::{Duration, NaiveDate, NaiveTime, Utc, TimeZone, FixedOffset}; use self::dotenv::dotenv; use expression::dsl::{sql, now}; @@ -169,11 +168,11 @@ mod tests { #[test] fn times_relative_to_now_encode_correctly() { let connection = connection(); - let time = UTC::now().naive_utc() + Duration::days(1); + let time = Utc::now().naive_utc() + Duration::days(1); let query = select(now.lt(time)); assert!(query.get_result::(&connection).unwrap()); - let time = UTC::now().naive_utc() - Duration::days(1); + let time = Utc::now().naive_utc() - Duration::days(1); let query = select(now.gt(time)); assert!(query.get_result::(&connection).unwrap()); } diff --git a/diesel/src/pg/types/date_and_time/chrono.rs b/diesel/src/pg/types/date_and_time/chrono.rs index 2a731bed58f0..e12caa674c41 100644 --- a/diesel/src/pg/types/date_and_time/chrono.rs +++ b/diesel/src/pg/types/date_and_time/chrono.rs @@ -4,8 +4,8 @@ extern crate chrono; use std::error::Error; use std::io::Write; -use self::chrono::{Duration, NaiveDateTime, NaiveDate, NaiveTime, DateTime, TimeZone, UTC, FixedOffset, Local}; -use self::chrono::naive::date; +use self::chrono::{Duration, NaiveDateTime, NaiveDate, NaiveTime, DateTime, TimeZone, Utc, FixedOffset, Local}; +use self::chrono::naive::MAX_DATE; use pg::Pg; use super::{PgDate, PgTime, PgTimestamp}; @@ -13,14 +13,14 @@ use types::{Date, FromSql, IsNull, Time, Timestamp, Timestamptz, ToSql}; expression_impls! { Timestamptz -> NaiveDateTime, - Timestamptz -> DateTime, + Timestamptz -> DateTime, Timestamptz -> DateTime, Timestamptz -> DateTime, } queryable_impls! { Timestamptz -> NaiveDateTime, - Timestamptz -> DateTime, + Timestamptz -> DateTime, } // Postgres timestamps start from January 1st 2000. @@ -66,10 +66,10 @@ impl ToSql for NaiveDateTime { } } -impl FromSql for DateTime { +impl FromSql for DateTime { fn from_sql(bytes: Option<&[u8]>) -> Result> { let naive_date_time = try!(>::from_sql(bytes)); - Ok(DateTime::from_utc(naive_date_time, UTC)) + Ok(DateTime::from_utc(naive_date_time, Utc)) } } @@ -119,7 +119,7 @@ impl FromSql for NaiveDate { Some(date) => Ok(date), None => { let error_message = format!("Chrono can only represent dates up to {:?}", - date::MAX); + MAX_DATE); Err(Box::::from(error_message)) } } @@ -131,8 +131,8 @@ mod tests { extern crate dotenv; extern crate chrono; - use self::chrono::{Duration, NaiveDate, NaiveTime, UTC, TimeZone, FixedOffset}; - use self::chrono::naive::date; + use self::chrono::{Duration, NaiveDate, NaiveTime, Utc, TimeZone, FixedOffset}; + use self::chrono::naive::MAX_DATE; use self::dotenv::dotenv; use ::select; @@ -161,7 +161,7 @@ mod tests { #[test] fn unix_epoch_encodes_correctly_with_utc_timezone() { let connection = connection(); - let time = UTC.ymd(1970, 1, 1).and_hms(0, 0, 0); + let time = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0); let query = select(sql::("'1970-01-01Z'::timestamptz").eq(time)); assert!(query.get_result::(&connection).unwrap()); } @@ -186,7 +186,7 @@ mod tests { #[test] fn unix_epoch_decodes_correctly_with_timezone() { let connection = connection(); - let time = UTC.ymd(1970, 1, 1).and_hms(0, 0, 0); + let time = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0); let epoch_from_sql = select(sql::("'1970-01-01Z'::timestamptz")) .get_result(&connection); assert_eq!(Ok(time), epoch_from_sql); @@ -195,11 +195,11 @@ mod tests { #[test] fn times_relative_to_now_encode_correctly() { let connection = connection(); - let time = UTC::now().naive_utc() + Duration::seconds(60); + let time = Utc::now().naive_utc() + Duration::seconds(60); let query = select(now.at_time_zone("utc").lt(time)); assert!(query.get_result::(&connection).unwrap()); - let time = UTC::now().naive_utc() - Duration::seconds(60); + let time = Utc::now().naive_utc() - Duration::seconds(60); let query = select(now.at_time_zone("utc").gt(time)); assert!(query.get_result::(&connection).unwrap()); } @@ -262,7 +262,7 @@ mod tests { let query = select(sql::("'J0'::date").eq(julian_epoch)); assert!(query.get_result::(&connection).unwrap()); - let max_date = date::MAX; + let max_date = MAX_DATE; let query = select(sql::("'262143-12-31'::date").eq(max_date)); assert!(query.get_result::(&connection).unwrap()); @@ -290,7 +290,7 @@ mod tests { let query = select(sql::("'J0'::date")); assert_eq!(Ok(julian_epoch), query.get_result::(&connection)); - let max_date = date::MAX; + let max_date = MAX_DATE; let query = select(sql::("'262143-12-31'::date")); assert_eq!(Ok(max_date), query.get_result::(&connection)); diff --git a/diesel/src/sqlite/types/date_and_time/chrono.rs b/diesel/src/sqlite/types/date_and_time/chrono.rs index 09ff269e743f..5fe38b8878a0 100644 --- a/diesel/src/sqlite/types/date_and_time/chrono.rs +++ b/diesel/src/sqlite/types/date_and_time/chrono.rs @@ -91,8 +91,8 @@ mod tests { extern crate dotenv; extern crate chrono; - use self::chrono::{Duration, NaiveDate, NaiveTime, NaiveDateTime, UTC, Timelike}; - use self::chrono::naive::date; + use self::chrono::{Duration, NaiveDate, NaiveTime, NaiveDateTime, Utc, Timelike}; + use self::chrono::naive::MAX_DATE; use self::dotenv::dotenv; use ::select; @@ -131,11 +131,11 @@ mod tests { #[test] fn times_relative_to_now_encode_correctly() { let connection = connection(); - let time = UTC::now().naive_utc() + Duration::seconds(60); + let time = Utc::now().naive_utc() + Duration::seconds(60); let query = select(now.lt(time)); assert!(query.get_result::(&connection).unwrap()); - let time = UTC::now().naive_utc() - Duration::seconds(600); + let time = Utc::now().naive_utc() - Duration::seconds(600); let query = select(now.gt(time)); assert!(query.get_result::(&connection).unwrap()); } @@ -184,7 +184,7 @@ mod tests { let query = select(sql::("'-398-04-11'").eq(distant_past)); assert!(query.get_result::(&connection).unwrap()); - let max_date = date::MAX; + let max_date = MAX_DATE; let query = select(sql::("'262143-12-31'").eq(max_date)); assert!(query.get_result::(&connection).unwrap()); @@ -208,7 +208,7 @@ mod tests { let query = select(sql::("'-399-04-11'")); assert_eq!(Ok(distant_past), query.get_result::(&connection)); - let max_date = date::MAX; + let max_date = MAX_DATE; let query = select(sql::("'262143-12-31'")); assert_eq!(Ok(max_date), query.get_result::(&connection)); diff --git a/diesel_cli/Cargo.toml b/diesel_cli/Cargo.toml index ecf28ab0efbc..8594e4c1cb05 100644 --- a/diesel_cli/Cargo.toml +++ b/diesel_cli/Cargo.toml @@ -14,7 +14,7 @@ keywords = ["orm", "database", "postgres", "postgresql", "sql"] name = "diesel" [dependencies] -chrono = "0.3" +chrono = "0.4" clap = "2.20.3" diesel = { version = "0.13.0", default-features = false } dotenv = ">=0.8, <0.11" diff --git a/diesel_cli/src/main.rs b/diesel_cli/src/main.rs index e590ec5ff0b4..146eef61ebc4 100644 --- a/diesel_cli/src/main.rs +++ b/diesel_cli/src/main.rs @@ -102,9 +102,9 @@ fn run_migration_command(matches: &ArgMatches) { // sort migrations by version timestamp, push non-conforming timestamped versions to the bottom sorted.sort_by(|a, b| { let version_a = a.0.split('_').nth(0).expect(&format!("Unexpected version format {:?}", a.0)); - let ver_date_a = UTC.datetime_from_str(version_a, TIMESTAMP_FORMAT); + let ver_date_a = Utc.datetime_from_str(version_a, TIMESTAMP_FORMAT); let version_b = b.0.split('_').nth(0).expect(&format!("Unexpected version format {:?}", b.0)); - let ver_date_b = UTC.datetime_from_str(version_b, TIMESTAMP_FORMAT); + let ver_date_b = Utc.datetime_from_str(version_b, TIMESTAMP_FORMAT); match (ver_date_a.is_ok(), ver_date_b.is_ok()) { (false, false) => version_a.to_lowercase().cmp(&version_b.to_lowercase()), (true, false) => Ordering::Less, @@ -159,7 +159,7 @@ fn run_migration_command(matches: &ArgMatches) { use std::fmt::Display; fn migration_version<'a>(matches: &'a ArgMatches) -> Box { matches.value_of("MIGRATION_VERSION").map(|s| Box::new(s) as Box) - .unwrap_or_else(|| Box::new(UTC::now().format(TIMESTAMP_FORMAT))) + .unwrap_or_else(|| Box::new(Utc::now().format(TIMESTAMP_FORMAT))) } fn migrations_dir(matches: &ArgMatches) -> PathBuf { diff --git a/diesel_cli/tests/migration_generate.rs b/diesel_cli/tests/migration_generate.rs index 5aa4a89c35f8..21500a0dfe49 100644 --- a/diesel_cli/tests/migration_generate.rs +++ b/diesel_cli/tests/migration_generate.rs @@ -26,7 +26,7 @@ Creating migrations.\\d*_hello.down.sql\ let captured_timestamps = Regex::new(r"(?P\d*)_hello").unwrap(); let mut stamps_found = 0; for caps in captured_timestamps.captures_iter(result.stdout()) { - let timestamp = UTC.datetime_from_str(&caps["stamp"], TIMESTAMP_FORMAT); + let timestamp = Utc.datetime_from_str(&caps["stamp"], TIMESTAMP_FORMAT); assert!(timestamp.is_ok(), "Found invalid timestamp format: {:?}", &caps["stamp"]); stamps_found += 1; } diff --git a/diesel_cli/tests/migration_list.rs b/diesel_cli/tests/migration_list.rs index 2ea6c6de006e..e5121c458d55 100644 --- a/diesel_cli/tests/migration_list.rs +++ b/diesel_cli/tests/migration_list.rs @@ -1,5 +1,5 @@ -use chrono::UTC; +use chrono::Utc; use std::thread::sleep; use std::time::Duration; @@ -60,7 +60,7 @@ fn migration_list_lists_migrations_ordered_by_timestamp() { p.command("setup").run(); - let tag1 = format!("{}_initial", UTC::now().format(TIMESTAMP_FORMAT)); + let tag1 = format!("{}_initial", Utc::now().format(TIMESTAMP_FORMAT)); p.create_migration(&tag1, "", ""); let result = p.command("migration") @@ -71,7 +71,7 @@ fn migration_list_lists_migrations_ordered_by_timestamp() { sleep(Duration::from_millis(1100)); - let tag2 = format!("{}_alter", UTC::now().format(TIMESTAMP_FORMAT)); + let tag2 = format!("{}_alter", Utc::now().format(TIMESTAMP_FORMAT)); p.create_migration(&tag2, "", ""); let result = p.command("migration") @@ -90,7 +90,7 @@ fn migration_list_orders_unknown_timestamps_last() { p.command("setup").run(); - let tag1 = format!("{}_migration1", UTC::now().format(TIMESTAMP_FORMAT)); + let tag1 = format!("{}_migration1", Utc::now().format(TIMESTAMP_FORMAT)); p.create_migration(&tag1, "", ""); let tag4 = "abc_migration4"; @@ -101,12 +101,12 @@ fn migration_list_orders_unknown_timestamps_last() { sleep(Duration::from_millis(1100)); - let tag2 = format!("{}_migration2", UTC::now().format(TIMESTAMP_FORMAT)); + let tag2 = format!("{}_migration2", Utc::now().format(TIMESTAMP_FORMAT)); p.create_migration(&tag2, "", ""); sleep(Duration::from_millis(1100)); - let tag3 = format!("{}_migration3", UTC::now().format(TIMESTAMP_FORMAT)); + let tag3 = format!("{}_migration3", Utc::now().format(TIMESTAMP_FORMAT)); p.create_migration(&tag3, "", ""); let result = p.command("migration") @@ -140,7 +140,7 @@ fn migration_list_orders_nontimestamp_versions_lexicographically() { let tag3 = "7letters"; p.create_migration(&tag3, "", ""); - let tag1 = format!("{}_stamped_migration", UTC::now().format(TIMESTAMP_FORMAT)); + let tag1 = format!("{}_stamped_migration", Utc::now().format(TIMESTAMP_FORMAT)); p.create_migration(&tag1, "", ""); let result = p.command("migration") diff --git a/diesel_tests/Cargo.toml b/diesel_tests/Cargo.toml index cbd957ecfcd9..00c3ee68b8d5 100644 --- a/diesel_tests/Cargo.toml +++ b/diesel_tests/Cargo.toml @@ -11,7 +11,7 @@ dotenv = ">=0.8, <0.11" [dependencies] assert_matches = "1.0.1" -chrono = { version = "0.3" } +chrono = { version = "0.4" } diesel = { path = "../diesel", default-features = false, features = ["quickcheck", "chrono", "uuid", "serde_json", "network-address"] } diesel_codegen = { path = "../diesel_codegen" } dotenv = ">=0.8, <0.11" diff --git a/diesel_tests/tests/types_roundtrip.rs b/diesel_tests/tests/types_roundtrip.rs index e766f214ce24..dbf4b46ea226 100644 --- a/diesel_tests/tests/types_roundtrip.rs +++ b/diesel_tests/tests/types_roundtrip.rs @@ -1,8 +1,8 @@ extern crate chrono; pub use quickcheck::quickcheck; -use self::chrono::{Duration, NaiveDate, NaiveDateTime, NaiveTime, DateTime, UTC}; -use self::chrono::naive::date; +use self::chrono::{Duration, NaiveDate, NaiveDateTime, NaiveTime, DateTime, Utc}; +use self::chrono::naive::{MIN_DATE, MAX_DATE}; pub use schema::{connection, TestConnection}; pub use diesel::*; @@ -154,14 +154,14 @@ pub fn mk_naive_time(data: (u32, u32)) -> NaiveTime { NaiveTime::from_num_seconds_from_midnight(data.0, data.1 / 1000) } -pub fn mk_datetime(data: (i64, u32)) -> DateTime { - DateTime::from_utc(mk_naive_datetime(data), UTC) +pub fn mk_datetime(data: (i64, u32)) -> DateTime { + DateTime::from_utc(mk_naive_datetime(data), Utc) } #[cfg(feature = "postgres")] pub fn mk_naive_date(days: u32) -> NaiveDate { let earliest_pg_date = NaiveDate::from_ymd(-4713, 11, 24); - let latest_chrono_date = date::MAX; + let latest_chrono_date = MAX_DATE; let num_days_representable = latest_chrono_date.signed_duration_since(earliest_pg_date).num_days(); earliest_pg_date + Duration::days(days as i64 % num_days_representable) } @@ -176,8 +176,8 @@ pub fn mk_naive_date(days: u32) -> NaiveDate { #[cfg(feature = "sqlite")] pub fn mk_naive_date(days: u32) -> NaiveDate { - let earliest_sqlite_date = date::MIN; - let latest_sqlite_date = date::MAX; + let earliest_sqlite_date = MIN_DATE; + let latest_sqlite_date = MAX_DATE; let num_days_representable = latest_sqlite_date.signed_duration_since(earliest_sqlite_date).num_days(); earliest_sqlite_date + Duration::days(days as i64 % num_days_representable) }