Skip to content

Commit c737490

Browse files
committed
cargo: rename chrono feature to chrono-04
1 parent fabfee7 commit c737490

File tree

11 files changed

+132
-143
lines changed

11 files changed

+132
-143
lines changed

.github/workflows/rust.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --all-features
4747
- name: Cargo check with secrecy-08 feature
4848
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "secrecy-08"
49-
- name: Cargo check with chrono feature
50-
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono"
49+
- name: Cargo check with chrono-04 feature
50+
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono-04"
5151
- name: Cargo check with time-03 feature
5252
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time-03"
5353
- name: Cargo check with num-bigint-03 feature

examples/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rustyline-derive = "0.6"
1313
scylla = { path = "../scylla", features = [
1414
"ssl",
1515
"cloud",
16-
"chrono",
16+
"chrono-04",
1717
"time-03",
1818
"num-bigint-03",
1919
"num-bigint-04",

scylla-cql/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ thiserror = "1.0"
2222
num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true }
2323
num-bigint-04 = { package = "num-bigint", version = "0.4", optional = true }
2424
bigdecimal-04 = { package = "bigdecimal", version = "0.4", optional = true }
25-
chrono = { version = "0.4.32", default-features = false, optional = true }
25+
chrono-04 = { package = "chrono", version = "0.4.32", default-features = false, optional = true }
2626
lz4_flex = { version = "0.11.1" }
2727
async-trait = "0.1.57"
2828
serde = { version = "1.0", features = ["derive"], optional = true }
@@ -42,12 +42,12 @@ harness = false
4242
[features]
4343
secrecy-08 = ["dep:secrecy-08"]
4444
time-03 = ["dep:time-03"]
45-
chrono = ["dep:chrono"]
45+
chrono-04 = ["dep:chrono-04"]
4646
num-bigint-03 = ["dep:num-bigint-03"]
4747
num-bigint-04 = ["dep:num-bigint-04"]
4848
bigdecimal-04 = ["dep:bigdecimal-04"]
4949
full-serialization = [
50-
"chrono",
50+
"chrono-04",
5151
"time-03",
5252
"secrecy-08",
5353
"num-bigint-03",

scylla-cql/src/frame/response/cql_to_rust.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ use std::net::IpAddr;
88
use thiserror::Error;
99
use uuid::Uuid;
1010

11-
#[cfg(feature = "chrono")]
12-
use chrono::{DateTime, NaiveDate, NaiveTime, Utc};
13-
1411
#[derive(Error, Debug, Clone, PartialEq, Eq)]
1512
pub enum FromRowError {
1613
#[error("{err} in the column with index {column}")]
@@ -175,8 +172,8 @@ impl FromCqlVal<CqlValue> for bigdecimal_04::BigDecimal {
175172
}
176173
}
177174

178-
#[cfg(feature = "chrono")]
179-
impl FromCqlVal<CqlValue> for NaiveDate {
175+
#[cfg(feature = "chrono-04")]
176+
impl FromCqlVal<CqlValue> for chrono_04::NaiveDate {
180177
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
181178
match cql_val {
182179
CqlValue::Date(cql_date) => cql_date.try_into().map_err(|_| FromCqlValError::BadVal),
@@ -195,8 +192,8 @@ impl FromCqlVal<CqlValue> for time_03::Date {
195192
}
196193
}
197194

198-
#[cfg(feature = "chrono")]
199-
impl FromCqlVal<CqlValue> for NaiveTime {
195+
#[cfg(feature = "chrono-04")]
196+
impl FromCqlVal<CqlValue> for chrono_04::NaiveTime {
200197
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
201198
match cql_val {
202199
CqlValue::Time(cql_time) => cql_time.try_into().map_err(|_| FromCqlValError::BadVal),
@@ -215,8 +212,8 @@ impl FromCqlVal<CqlValue> for time_03::Time {
215212
}
216213
}
217214

218-
#[cfg(feature = "chrono")]
219-
impl FromCqlVal<CqlValue> for DateTime<Utc> {
215+
#[cfg(feature = "chrono-04")]
216+
impl FromCqlVal<CqlValue> for chrono_04::DateTime<chrono_04::Utc> {
220217
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
221218
cql_val
222219
.as_cql_timestamp()
@@ -523,10 +520,10 @@ mod tests {
523520
assert_eq!(Ok(counter), Counter::from_cql(CqlValue::Counter(counter)));
524521
}
525522

526-
#[cfg(feature = "chrono")]
523+
#[cfg(feature = "chrono-04")]
527524
#[test]
528-
fn naive_date_from_cql() {
529-
use chrono::NaiveDate;
525+
fn naive_date_04_from_cql() {
526+
use chrono_04::NaiveDate;
530527

531528
let unix_epoch: CqlValue = CqlValue::Date(CqlDate(2_u32.pow(31)));
532529
assert_eq!(
@@ -631,10 +628,10 @@ mod tests {
631628
assert_eq!(time_ns, CqlTime::from_cql(cql_value).unwrap().0);
632629
}
633630

634-
#[cfg(feature = "chrono")]
631+
#[cfg(feature = "chrono-04")]
635632
#[test]
636-
fn naive_time_from_cql() {
637-
use chrono::NaiveTime;
633+
fn naive_time_04_from_cql() {
634+
use chrono_04::NaiveTime;
638635

639636
// Midnight
640637
let midnight = CqlValue::Time(CqlTime(0));
@@ -658,7 +655,7 @@ mod tests {
658655
NaiveTime::from_cql(late_night)
659656
);
660657

661-
// Bad values. Since value is out of `chrono::NaiveTime` range, it should return `BadVal` error
658+
// Bad values. Since value is out of `chrono_04::NaiveTime` range, it should return `BadVal` error
662659
let bad_time1 = CqlValue::Time(CqlTime(-1));
663660
assert_eq!(Err(FromCqlValError::BadVal), NaiveTime::from_cql(bad_time1));
664661
let bad_time2 = CqlValue::Time(CqlTime(i64::MAX));
@@ -731,10 +728,10 @@ mod tests {
731728
);
732729
}
733730

734-
#[cfg(feature = "chrono")]
731+
#[cfg(feature = "chrono-04")]
735732
#[test]
736-
fn datetime_from_cql() {
737-
use chrono::{DateTime, NaiveDate, Utc};
733+
fn datetime_04_from_cql() {
734+
use chrono_04::{DateTime, NaiveDate, Utc};
738735
let naivedatetime_utc = NaiveDate::from_ymd_opt(2022, 12, 31)
739736
.unwrap()
740737
.and_hms_opt(2, 0, 0)

scylla-cql/src/frame/response/result.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use std::borrow::Cow;
1212
use std::{convert::TryInto, net::IpAddr, result::Result as StdResult, str};
1313
use uuid::Uuid;
1414

15-
#[cfg(feature = "chrono")]
16-
use chrono::{DateTime, NaiveDate, Utc};
17-
1815
#[derive(Debug)]
1916
pub struct SetKeyspace {
2017
pub keyspace_name: String,
@@ -187,8 +184,8 @@ impl CqlValue {
187184
}
188185
}
189186

190-
#[cfg(feature = "chrono")]
191-
pub fn as_naive_date(&self) -> Option<NaiveDate> {
187+
#[cfg(feature = "chrono-04")]
188+
pub fn as_naive_date(&self) -> Option<chrono_04::NaiveDate> {
192189
self.as_cql_date().and_then(|date| date.try_into().ok())
193190
}
194191

@@ -205,8 +202,8 @@ impl CqlValue {
205202
}
206203
}
207204

208-
#[cfg(feature = "chrono")]
209-
pub fn as_datetime(&self) -> Option<DateTime<Utc>> {
205+
#[cfg(feature = "chrono-04")]
206+
pub fn as_datetime(&self) -> Option<chrono_04::DateTime<chrono_04::Utc>> {
210207
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
211208
}
212209

@@ -223,8 +220,8 @@ impl CqlValue {
223220
}
224221
}
225222

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

@@ -1272,10 +1269,10 @@ mod tests {
12721269
assert_eq!(date.as_cql_date(), Some(max_date));
12731270
}
12741271

1275-
#[cfg(feature = "chrono")]
1272+
#[cfg(feature = "chrono-04")]
12761273
#[test]
1277-
fn test_naive_date_from_cql() {
1278-
use chrono::NaiveDate;
1274+
fn test_naive_date_04_from_cql() {
1275+
use chrono_04::NaiveDate;
12791276

12801277
// 2^31 when converted to NaiveDate is 1970-01-01
12811278
let unix_epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
@@ -1395,10 +1392,10 @@ mod tests {
13951392
}
13961393
}
13971394

1398-
#[cfg(feature = "chrono")]
1395+
#[cfg(feature = "chrono-04")]
13991396
#[test]
1400-
fn test_naive_time_from_cql() {
1401-
use chrono::NaiveTime;
1397+
fn test_naive_time_04_from_cql() {
1398+
use chrono_04::NaiveTime;
14021399

14031400
// 0 when converted to NaiveTime is 0:0:0.0
14041401
let midnight = NaiveTime::from_hms_nano_opt(0, 0, 0, 0).unwrap();
@@ -1486,10 +1483,10 @@ mod tests {
14861483
}
14871484
}
14881485

1489-
#[cfg(feature = "chrono")]
1486+
#[cfg(feature = "chrono-04")]
14901487
#[test]
1491-
fn test_datetime_from_cql() {
1492-
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime};
1488+
fn test_datetime_04_from_cql() {
1489+
use chrono_04::{DateTime, NaiveDate, NaiveDateTime, NaiveTime};
14931490

14941491
// 0 when converted to DateTime is 1970-01-01 0:00:00.00
14951492
let unix_epoch = DateTime::from_timestamp(0, 0).unwrap();

scylla-cql/src/frame/value.rs

+33-34
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use std::net::IpAddr;
99
use thiserror::Error;
1010
use uuid::Uuid;
1111

12-
#[cfg(feature = "chrono")]
13-
use chrono::{DateTime, NaiveDate, NaiveTime, TimeZone, Utc};
14-
1512
use super::response::result::CqlValue;
1613
use super::types::vint_encode;
1714
use super::types::RawValue;
@@ -464,10 +461,10 @@ pub struct CqlTimestamp(pub i64);
464461
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
465462
pub struct CqlTime(pub i64);
466463

467-
#[cfg(feature = "chrono")]
468-
impl From<NaiveDate> for CqlDate {
469-
fn from(value: NaiveDate) -> Self {
470-
let unix_epoch = NaiveDate::from_yo_opt(1970, 1).unwrap();
464+
#[cfg(feature = "chrono-04")]
465+
impl From<chrono_04::NaiveDate> for CqlDate {
466+
fn from(value: chrono_04::NaiveDate) -> Self {
467+
let unix_epoch = chrono_04::NaiveDate::from_yo_opt(1970, 1).unwrap();
471468

472469
// `NaiveDate` range is -262145-01-01 to 262143-12-31
473470
// Both values are well within supported range
@@ -477,50 +474,52 @@ impl From<NaiveDate> for CqlDate {
477474
}
478475
}
479476

480-
#[cfg(feature = "chrono")]
481-
impl TryInto<NaiveDate> for CqlDate {
477+
#[cfg(feature = "chrono-04")]
478+
impl TryInto<chrono_04::NaiveDate> for CqlDate {
482479
type Error = ValueOverflow;
483480

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

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

491-
NaiveDate::from_yo_opt(1970, 1)
489+
chrono_04::NaiveDate::from_yo_opt(1970, 1)
492490
.unwrap()
493491
.checked_add_signed(duration_since_unix_epoch)
494492
.ok_or(ValueOverflow)
495493
}
496494
}
497495

498-
#[cfg(feature = "chrono")]
499-
impl From<DateTime<Utc>> for CqlTimestamp {
500-
fn from(value: DateTime<Utc>) -> Self {
496+
#[cfg(feature = "chrono-04")]
497+
impl From<chrono_04::DateTime<chrono_04::Utc>> for CqlTimestamp {
498+
fn from(value: chrono_04::DateTime<chrono_04::Utc>) -> Self {
501499
Self(value.timestamp_millis())
502500
}
503501
}
504502

505-
#[cfg(feature = "chrono")]
506-
impl TryInto<DateTime<Utc>> for CqlTimestamp {
503+
#[cfg(feature = "chrono-04")]
504+
impl TryInto<chrono_04::DateTime<chrono_04::Utc>> for CqlTimestamp {
507505
type Error = ValueOverflow;
508506

509-
fn try_into(self) -> Result<DateTime<Utc>, Self::Error> {
510-
match Utc.timestamp_millis_opt(self.0) {
511-
chrono::LocalResult::Single(datetime) => Ok(datetime),
507+
fn try_into(self) -> Result<chrono_04::DateTime<chrono_04::Utc>, Self::Error> {
508+
use chrono_04::TimeZone;
509+
match chrono_04::Utc.timestamp_millis_opt(self.0) {
510+
chrono_04::LocalResult::Single(datetime) => Ok(datetime),
512511
_ => Err(ValueOverflow),
513512
}
514513
}
515514
}
516515

517-
#[cfg(feature = "chrono")]
518-
impl TryFrom<NaiveTime> for CqlTime {
516+
#[cfg(feature = "chrono-04")]
517+
impl TryFrom<chrono_04::NaiveTime> for CqlTime {
519518
type Error = ValueOverflow;
520519

521-
fn try_from(value: NaiveTime) -> Result<Self, Self::Error> {
520+
fn try_from(value: chrono_04::NaiveTime) -> Result<Self, Self::Error> {
522521
let nanos = value
523-
.signed_duration_since(chrono::NaiveTime::MIN)
522+
.signed_duration_since(chrono_04::NaiveTime::MIN)
524523
.num_nanoseconds()
525524
.unwrap();
526525

@@ -533,18 +532,18 @@ impl TryFrom<NaiveTime> for CqlTime {
533532
}
534533
}
535534

536-
#[cfg(feature = "chrono")]
537-
impl TryInto<NaiveTime> for CqlTime {
535+
#[cfg(feature = "chrono-04")]
536+
impl TryInto<chrono_04::NaiveTime> for CqlTime {
538537
type Error = ValueOverflow;
539538

540-
fn try_into(self) -> Result<NaiveTime, Self::Error> {
539+
fn try_into(self) -> Result<chrono_04::NaiveTime, Self::Error> {
541540
let secs = (self.0 / 1_000_000_000)
542541
.try_into()
543542
.map_err(|_| ValueOverflow)?;
544543
let nanos = (self.0 % 1_000_000_000)
545544
.try_into()
546545
.map_err(|_| ValueOverflow)?;
547-
NaiveTime::from_num_seconds_from_midnight_opt(secs, nanos).ok_or(ValueOverflow)
546+
chrono_04::NaiveTime::from_num_seconds_from_midnight_opt(secs, nanos).ok_or(ValueOverflow)
548547
}
549548
}
550549

@@ -1007,8 +1006,8 @@ impl Value for bigdecimal_04::BigDecimal {
10071006
}
10081007
}
10091008

1010-
#[cfg(feature = "chrono")]
1011-
impl Value for NaiveDate {
1009+
#[cfg(feature = "chrono-04")]
1010+
impl Value for chrono_04::NaiveDate {
10121011
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
10131012
CqlDate::from(*self).serialize(buf)
10141013
}
@@ -1045,8 +1044,8 @@ impl Value for CqlTime {
10451044
}
10461045
}
10471046

1048-
#[cfg(feature = "chrono")]
1049-
impl Value for DateTime<Utc> {
1047+
#[cfg(feature = "chrono-04")]
1048+
impl Value for chrono_04::DateTime<chrono_04::Utc> {
10501049
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
10511050
CqlTimestamp::from(*self).serialize(buf)
10521051
}
@@ -1059,8 +1058,8 @@ impl Value for time_03::OffsetDateTime {
10591058
}
10601059
}
10611060

1062-
#[cfg(feature = "chrono")]
1063-
impl Value for NaiveTime {
1061+
#[cfg(feature = "chrono-04")]
1062+
impl Value for chrono_04::NaiveTime {
10641063
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
10651064
CqlTime::try_from(*self)
10661065
.map_err(|_| ValueTooBig)?

0 commit comments

Comments
 (0)