Skip to content

Commit

Permalink
cargo: rename chrono feature to chrono-04
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Feb 22, 2024
1 parent 1733fd0 commit c339175
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Cargo check with secret feature
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "secrecy-08"
- name: Cargo check with chrono feature
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono"
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono-04"
- name: Cargo check with time feature
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time-03"
- name: Cargo check with num-bigint-03 feature
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ futures = "0.3.6"
openssl = "0.10.32"
rustyline = "9"
rustyline-derive = "0.6"
scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time-03", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]}
scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono-04", "time-03", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]}
tokio = {version = "1.1.0", features = ["full"]}
tracing = "0.1.25"
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }
Expand Down
6 changes: 3 additions & 3 deletions 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", default-features = false, optional = true }
chrono-04 = { package = "chrono", version = "0.4", 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 All @@ -39,8 +39,8 @@ harness = false
[features]
secrecy-08 = ["dep:secrecy-08"]
time-03 = ["dep:time-03"]
chrono = ["dep:chrono"]
chrono-04 = ["dep:chrono-04"]
num-bigint-03 = ["dep:num-bigint-03"]
num-bigint-04 = ["dep:num-bigint-04"]
bigdecimal-04 = ["dep:bigdecimal-04"]
full-serialization = ["chrono", "time-03", "secrecy-08", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]
full-serialization = ["chrono-04", "time-03", "secrecy-08", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]
24 changes: 12 additions & 12 deletions scylla-cql/src/frame/response/cql_to_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::net::IpAddr;
use thiserror::Error;
use uuid::Uuid;

#[cfg(feature = "chrono")]
use chrono::{DateTime, NaiveDate, NaiveTime, Utc};
#[cfg(feature = "chrono-04")]
use chrono_04::{DateTime, NaiveDate, NaiveTime, Utc};

#[cfg(feature = "secrecy-08")]
use secrecy_08::{Secret, Zeroize};
Expand Down Expand Up @@ -178,7 +178,7 @@ impl FromCqlVal<CqlValue> for bigdecimal_04::BigDecimal {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl FromCqlVal<CqlValue> for NaiveDate {
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
match cql_val {
Expand All @@ -198,7 +198,7 @@ impl FromCqlVal<CqlValue> for time_03::Date {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl FromCqlVal<CqlValue> for NaiveTime {
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
match cql_val {
Expand All @@ -218,7 +218,7 @@ impl FromCqlVal<CqlValue> for time_03::Time {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl FromCqlVal<CqlValue> for DateTime<Utc> {
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
cql_val
Expand Down Expand Up @@ -526,10 +526,10 @@ mod tests {
assert_eq!(Ok(counter), Counter::from_cql(CqlValue::Counter(counter)));
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn naive_date_from_cql() {
use chrono::NaiveDate;
use chrono_04::NaiveDate;

let unix_epoch: CqlValue = CqlValue::Date(CqlDate(2_u32.pow(31)));
assert_eq!(
Expand Down Expand Up @@ -634,10 +634,10 @@ mod tests {
assert_eq!(time_ns, CqlTime::from_cql(cql_value).unwrap().0);
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn naive_time_from_cql() {
use chrono::NaiveTime;
use chrono_04::NaiveTime;

// Midnight
let midnight = CqlValue::Time(CqlTime(0));
Expand All @@ -661,7 +661,7 @@ mod tests {
NaiveTime::from_cql(late_night)
);

// Bad values. Since value is out of `chrono::NaiveTime` range, it should return `BadVal` error
// Bad values. Since value is out of `chrono_04::NaiveTime` range, it should return `BadVal` error
let bad_time1 = CqlValue::Time(CqlTime(-1));
assert_eq!(Err(FromCqlValError::BadVal), NaiveTime::from_cql(bad_time1));
let bad_time2 = CqlValue::Time(CqlTime(i64::MAX));
Expand Down Expand Up @@ -734,10 +734,10 @@ mod tests {
);
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn datetime_from_cql() {
use chrono::{DateTime, NaiveDate, Utc};
use chrono_04::{DateTime, NaiveDate, Utc};
let naivedatetime_utc = NaiveDate::from_ymd_opt(2022, 12, 31)
.unwrap()
.and_hms_opt(2, 0, 0)
Expand Down
24 changes: 12 additions & 12 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use std::{
};
use uuid::Uuid;

#[cfg(feature = "chrono")]
use chrono::{DateTime, NaiveDate, Utc};
#[cfg(feature = "chrono-04")]
use chrono_04::{DateTime, NaiveDate, Utc};

#[derive(Debug)]
pub struct SetKeyspace {
Expand Down Expand Up @@ -156,7 +156,7 @@ impl CqlValue {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
pub fn as_naive_date(&self) -> Option<NaiveDate> {
self.as_cql_date().and_then(|date| date.try_into().ok())
}
Expand All @@ -173,7 +173,7 @@ impl CqlValue {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
pub fn as_datetime(&self) -> Option<DateTime<Utc>> {
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
}
Expand All @@ -190,8 +190,8 @@ impl CqlValue {
}
}

#[cfg(feature = "chrono")]
pub fn as_naive_time(&self) -> Option<chrono::NaiveTime> {
#[cfg(feature = "chrono-04")]
pub fn as_naive_time(&self) -> Option<chrono_04::NaiveTime> {
self.as_cql_time().and_then(|ts| ts.try_into().ok())
}

Expand Down Expand Up @@ -1362,10 +1362,10 @@ mod tests {
assert_eq!(date.as_cql_date(), Some(max_date));
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn test_naive_date_from_cql() {
use chrono::NaiveDate;
use chrono_04::NaiveDate;

// 2^31 when converted to NaiveDate is 1970-01-01
let unix_epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
Expand Down Expand Up @@ -1485,10 +1485,10 @@ mod tests {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn test_naive_time_from_cql() {
use chrono::NaiveTime;
use chrono_04::NaiveTime;

// 0 when converted to NaiveTime is 0:0:0.0
let midnight = NaiveTime::from_hms_nano_opt(0, 0, 0, 0).unwrap();
Expand Down Expand Up @@ -1577,10 +1577,10 @@ mod tests {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn test_datetime_from_cql() {
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use chrono_04::{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();
Expand Down
30 changes: 15 additions & 15 deletions scylla-cql/src/frame/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::net::IpAddr;
use thiserror::Error;
use uuid::Uuid;

#[cfg(feature = "chrono")]
use chrono::{DateTime, NaiveDate, NaiveTime, TimeZone, Utc};
#[cfg(feature = "chrono-04")]
use chrono_04::{DateTime, NaiveDate, NaiveTime, TimeZone, Utc};

use super::response::result::CqlValue;
use super::types::vint_encode;
Expand Down Expand Up @@ -467,7 +467,7 @@ pub struct CqlTimestamp(pub i64);
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct CqlTime(pub i64);

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl From<NaiveDate> for CqlDate {
fn from(value: NaiveDate) -> Self {
let unix_epoch = NaiveDate::from_yo_opt(1970, 1).unwrap();
Expand All @@ -480,16 +480,16 @@ impl From<NaiveDate> for CqlDate {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl TryInto<NaiveDate> for CqlDate {
type Error = ValueOverflow;

fn try_into(self) -> Result<NaiveDate, Self::Error> {
let days_since_unix_epoch = self.0 as i64 - (1 << 31);

// 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);
// Max value is 2^31, min value is -2^31. Both values can safely fit in chrono_04::Duration, this call won't panic
let duration_since_unix_epoch = chrono_04::Duration::days(days_since_unix_epoch);

NaiveDate::from_yo_opt(1970, 1)
.unwrap()
Expand All @@ -498,32 +498,32 @@ impl TryInto<NaiveDate> for CqlDate {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl From<DateTime<Utc>> for CqlTimestamp {
fn from(value: DateTime<Utc>) -> Self {
Self(value.timestamp_millis())
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl TryInto<DateTime<Utc>> for CqlTimestamp {
type Error = ValueOverflow;

fn try_into(self) -> Result<DateTime<Utc>, Self::Error> {
match Utc.timestamp_millis_opt(self.0) {
chrono::LocalResult::Single(datetime) => Ok(datetime),
chrono_04::LocalResult::Single(datetime) => Ok(datetime),
_ => Err(ValueOverflow),
}
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl TryFrom<NaiveTime> for CqlTime {
type Error = ValueOverflow;

fn try_from(value: NaiveTime) -> Result<Self, Self::Error> {
let nanos = value
.signed_duration_since(chrono::NaiveTime::MIN)
.signed_duration_since(chrono_04::NaiveTime::MIN)
.num_nanoseconds()
.unwrap();

Expand All @@ -536,7 +536,7 @@ impl TryFrom<NaiveTime> for CqlTime {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl TryInto<NaiveTime> for CqlTime {
type Error = ValueOverflow;

Expand Down Expand Up @@ -1004,7 +1004,7 @@ impl Value for bigdecimal_04::BigDecimal {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl Value for NaiveDate {
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
CqlDate::from(*self).serialize(buf)
Expand Down Expand Up @@ -1042,7 +1042,7 @@ impl Value for CqlTime {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl Value for DateTime<Utc> {
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
CqlTimestamp::from(*self).serialize(buf)
Expand All @@ -1056,7 +1056,7 @@ impl Value for time_03::OffsetDateTime {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
impl Value for NaiveTime {
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
CqlTime::try_from(*self)
Expand Down
12 changes: 6 additions & 6 deletions scylla-cql/src/frame/value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ fn ipaddr_serialization() {
);
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn naive_date_serialization() {
use chrono::NaiveDate;
use chrono_04::NaiveDate;
// 1970-01-31 is 2^31
let unix_epoch: NaiveDate = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
assert_eq!(
Expand Down Expand Up @@ -410,10 +410,10 @@ fn cql_time_serialization() {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn naive_time_serialization() {
use chrono::NaiveTime;
use chrono_04::NaiveTime;

let midnight_time: i64 = 0;
let max_time: i64 = 24 * 60 * 60 * 1_000_000_000 - 1;
Expand Down Expand Up @@ -490,10 +490,10 @@ fn cql_timestamp_serialization() {
}
}

#[cfg(feature = "chrono")]
#[cfg(feature = "chrono-04")]
#[test]
fn naive_date_time_serialization() {
use chrono::NaiveDateTime;
use chrono_04::NaiveDateTime;
let test_cases = [
(
// Max time serialized without error
Expand Down
Loading

0 comments on commit c339175

Please sign in to comment.