Skip to content

Commit

Permalink
Deal with chrono deprecations
Browse files Browse the repository at this point in the history
Chrono deprecated several method in 0.4.35 / 0.4.34

- chrono::Duration::days -> chrono::Duration::try_days
  New method was introduced in 0.4.33, so quite recently.
  This requires us to bump minimum chrono version.

- NaiveDateTime::from_timestamp_opt -> DateTime::from_timestamp
  This requires some other changes, because of the switch from
  NaiveDateTime to DateTime.

- NaiveDateTime::timestamp_millis -> .and_utc().timestamp_millis()

I also added a comment explaining the implementation of CqlValueDisplayer
and why it doesn't use existing `impl TryInto<NaiveDate> for CqlDate`.
  • Loading branch information
Lorak-mmk committed Mar 6, 2024
1 parent da49a7d commit 0058d93
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 67 deletions.
145 changes: 101 additions & 44 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scylla-cql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ thiserror = "1.0"
num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true }
num-bigint-04 = { package = "num-bigint", version = "0.4", optional = true }
bigdecimal-04 = { package = "bigdecimal", version = "0.4", optional = true }
chrono = { version = "0.4.27", default-features = false, optional = true }
chrono = { version = "0.4.33", default-features = false, optional = true }
lz4_flex = { version = "0.11.1" }
async-trait = "0.1.57"
serde = { version = "1.0", features = ["derive"], optional = true }
Expand Down
4 changes: 2 additions & 2 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,10 +1580,10 @@ mod tests {
#[cfg(feature = "chrono")]
#[test]
fn test_datetime_from_cql() {
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime};

// 0 when converted to DateTime is 1970-01-01 0:00:00.00
let unix_epoch = NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc();
let unix_epoch = DateTime::from_timestamp(0, 0).unwrap();
let date = super::deser_cql_value(&ColumnType::Timestamp, &mut 0i64.to_be_bytes().as_ref())
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion scylla-cql/src/frame/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ impl TryInto<NaiveDate> for CqlDate {

// date_days is u32 then converted to i64 then we subtract 2^31;
// Max value is 2^31, min value is -2^31. Both values can safely fit in chrono::Duration, this call won't panic
let duration_since_unix_epoch = chrono::Duration::days(days_since_unix_epoch);
let duration_since_unix_epoch = chrono::Duration::try_days(days_since_unix_epoch).unwrap();

NaiveDate::from_yo_opt(1970, 1)
.unwrap()
Expand Down
Loading

0 comments on commit 0058d93

Please sign in to comment.