Skip to content

Commit 248d2db

Browse files
committed
cargo: rename time feature to time-03.
1 parent 9e014b7 commit 248d2db

File tree

11 files changed

+176
-162
lines changed

11 files changed

+176
-162
lines changed

.github/workflows/rust.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ jobs:
4848
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "secrecy-08"
4949
- name: Cargo check with chrono feature
5050
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "chrono"
51-
- name: Cargo check with time feature
52-
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time"
51+
- name: Cargo check with time-03 feature
52+
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "time-03"
5353
- name: Cargo check with num-bigint-03 feature
5454
run: cargo check --all-targets --manifest-path "scylla/Cargo.toml" --features "num-bigint-03"
5555
- name: Cargo check with num-bigint-04 feature

examples/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ scylla = { path = "../scylla", features = [
1414
"ssl",
1515
"cloud",
1616
"chrono",
17-
"time",
17+
"time-03",
1818
"num-bigint-03",
1919
"num-bigint-04",
2020
"bigdecimal-04",

scylla-cql/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ 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 }
29-
time = { version = "0.3", optional = true }
29+
time-03 = { package = "time", version = "0.3", optional = true }
3030

3131
[dev-dependencies]
3232
assert_matches = "1.5.0"
3333
criterion = "0.4" # Note: v0.5 needs at least rust 1.70.0
3434
# Use large-dates feature to test potential edge cases
35-
time = { version = "0.3.21", features = ["large-dates"] }
35+
time-03 = { package = "time", version = "0.3.21", features = ["large-dates"] }
3636
uuid = { version = "1.0", features = ["v4"] }
3737

3838
[[bench]]
@@ -41,14 +41,14 @@ harness = false
4141

4242
[features]
4343
secrecy-08 = ["dep:secrecy-08"]
44-
time = ["dep:time"]
44+
time-03 = ["dep:time-03"]
4545
chrono = ["dep:chrono"]
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 = [
5050
"chrono",
51-
"time",
51+
"time-03",
5252
"secrecy-08",
5353
"num-bigint-03",
5454
"num-bigint-04",

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

+59-50
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ impl FromCqlVal<CqlValue> for NaiveDate {
185185
}
186186
}
187187

188-
#[cfg(feature = "time")]
189-
impl FromCqlVal<CqlValue> for time::Date {
188+
#[cfg(feature = "time-03")]
189+
impl FromCqlVal<CqlValue> for time_03::Date {
190190
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
191191
match cql_val {
192192
CqlValue::Date(cql_date) => cql_date.try_into().map_err(|_| FromCqlValError::BadVal),
@@ -205,8 +205,8 @@ impl FromCqlVal<CqlValue> for NaiveTime {
205205
}
206206
}
207207

208-
#[cfg(feature = "time")]
209-
impl FromCqlVal<CqlValue> for time::Time {
208+
#[cfg(feature = "time-03")]
209+
impl FromCqlVal<CqlValue> for time_03::Time {
210210
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
211211
match cql_val {
212212
CqlValue::Time(cql_time) => cql_time.try_into().map_err(|_| FromCqlValError::BadVal),
@@ -226,8 +226,8 @@ impl FromCqlVal<CqlValue> for DateTime<Utc> {
226226
}
227227
}
228228

229-
#[cfg(feature = "time")]
230-
impl FromCqlVal<CqlValue> for time::OffsetDateTime {
229+
#[cfg(feature = "time-03")]
230+
impl FromCqlVal<CqlValue> for time_03::OffsetDateTime {
231231
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
232232
cql_val
233233
.as_cql_timestamp()
@@ -565,43 +565,49 @@ mod tests {
565565
assert_eq!(Ok(CqlDate(u32::MAX)), CqlDate::from_cql(max_date));
566566
}
567567

568-
#[cfg(feature = "time")]
568+
#[cfg(feature = "time-03")]
569569
#[test]
570-
fn date_from_cql() {
570+
fn date_03_from_cql() {
571571
// UNIX epoch
572572
let unix_epoch = CqlValue::Date(CqlDate(1 << 31));
573573
assert_eq!(
574-
Ok(time::Date::from_ordinal_date(1970, 1).unwrap()),
575-
time::Date::from_cql(unix_epoch)
574+
Ok(time_03::Date::from_ordinal_date(1970, 1).unwrap()),
575+
time_03::Date::from_cql(unix_epoch)
576576
);
577577

578578
// 7 days after UNIX epoch
579579
let after_epoch = CqlValue::Date(CqlDate((1 << 31) + 7));
580580
assert_eq!(
581-
Ok(time::Date::from_ordinal_date(1970, 8).unwrap()),
582-
time::Date::from_cql(after_epoch)
581+
Ok(time_03::Date::from_ordinal_date(1970, 8).unwrap()),
582+
time_03::Date::from_cql(after_epoch)
583583
);
584584

585585
// 3 days before UNIX epoch
586586
let before_epoch = CqlValue::Date(CqlDate((1 << 31) - 3));
587587
assert_eq!(
588-
Ok(time::Date::from_ordinal_date(1969, 363).unwrap()),
589-
time::Date::from_cql(before_epoch)
588+
Ok(time_03::Date::from_ordinal_date(1969, 363).unwrap()),
589+
time_03::Date::from_cql(before_epoch)
590590
);
591591

592-
// Min possible stored date. Since value is out of `time::Date` range, it should return `BadVal` error
592+
// Min possible stored date. Since value is out of `time_03::Date` range, it should return `BadVal` error
593593
let min_date = CqlValue::Date(CqlDate(u32::MIN));
594-
assert_eq!(Err(FromCqlValError::BadVal), time::Date::from_cql(min_date));
594+
assert_eq!(
595+
Err(FromCqlValError::BadVal),
596+
time_03::Date::from_cql(min_date)
597+
);
595598

596-
// Max possible stored date. Since value is out of `time::Date` range, it should return `BadVal` error
599+
// Max possible stored date. Since value is out of `time_03::Date` range, it should return `BadVal` error
597600
let max_date = CqlValue::Date(CqlDate(u32::MAX));
598-
assert_eq!(Err(FromCqlValError::BadVal), time::Date::from_cql(max_date));
601+
assert_eq!(
602+
Err(FromCqlValError::BadVal),
603+
time_03::Date::from_cql(max_date)
604+
);
599605

600-
// Different CQL type. Since value can't be casted, it should return `BadCqlType` error
606+
// Different CQL type. Since value can't be cast, it should return `BadCqlType` error
601607
let bad_type = CqlValue::Double(0.5);
602608
assert_eq!(
603609
Err(FromCqlValError::BadCqlType),
604-
time::Date::from_cql(bad_type)
610+
time_03::Date::from_cql(bad_type)
605611
);
606612
}
607613

@@ -658,56 +664,59 @@ mod tests {
658664
let bad_time2 = CqlValue::Time(CqlTime(i64::MAX));
659665
assert_eq!(Err(FromCqlValError::BadVal), NaiveTime::from_cql(bad_time2));
660666

661-
// Different CQL type. Since value can't be casted, it should return `BadCqlType` error
667+
// Different CQL type. Since value can't be cast, it should return `BadCqlType` error
662668
let bad_type = CqlValue::Double(0.5);
663669
assert_eq!(
664670
Err(FromCqlValError::BadCqlType),
665671
NaiveTime::from_cql(bad_type)
666672
);
667673
}
668674

669-
#[cfg(feature = "time")]
675+
#[cfg(feature = "time-03")]
670676
#[test]
671-
fn time_from_cql() {
677+
fn time_03_from_cql() {
672678
// Midnight
673679
let midnight = CqlValue::Time(CqlTime(0));
674-
assert_eq!(Ok(time::Time::MIDNIGHT), time::Time::from_cql(midnight));
680+
assert_eq!(
681+
Ok(time_03::Time::MIDNIGHT),
682+
time_03::Time::from_cql(midnight)
683+
);
675684

676685
// 7:15:21.123456789
677686
let morning = CqlValue::Time(CqlTime(
678687
(7 * 3600 + 15 * 60 + 21) * 1_000_000_000 + 123_456_789,
679688
));
680689
assert_eq!(
681-
Ok(time::Time::from_hms_nano(7, 15, 21, 123_456_789).unwrap()),
682-
time::Time::from_cql(morning)
690+
Ok(time_03::Time::from_hms_nano(7, 15, 21, 123_456_789).unwrap()),
691+
time_03::Time::from_cql(morning)
683692
);
684693

685694
// 23:59:59.999999999
686695
let late_night = CqlValue::Time(CqlTime(
687696
(23 * 3600 + 59 * 60 + 59) * 1_000_000_000 + 999_999_999,
688697
));
689698
assert_eq!(
690-
Ok(time::Time::from_hms_nano(23, 59, 59, 999_999_999).unwrap()),
691-
time::Time::from_cql(late_night)
699+
Ok(time_03::Time::from_hms_nano(23, 59, 59, 999_999_999).unwrap()),
700+
time_03::Time::from_cql(late_night)
692701
);
693702

694-
// Bad values. Since value is out of `time::Time` range, it should return `BadVal` error
703+
// Bad values. Since value is out of `time_03::Time` range, it should return `BadVal` error
695704
let bad_time1 = CqlValue::Time(CqlTime(-1));
696705
assert_eq!(
697706
Err(FromCqlValError::BadVal),
698-
time::Time::from_cql(bad_time1)
707+
time_03::Time::from_cql(bad_time1)
699708
);
700709
let bad_time2 = CqlValue::Time(CqlTime(i64::MAX));
701710
assert_eq!(
702711
Err(FromCqlValError::BadVal),
703-
time::Time::from_cql(bad_time2)
712+
time_03::Time::from_cql(bad_time2)
704713
);
705714

706-
// Different CQL type. Since value can't be casted, it should return `BadCqlType` error
715+
// Different CQL type. Since value can't be cast, it should return `BadCqlType` error
707716
let bad_type = CqlValue::Double(0.5);
708717
assert_eq!(
709718
Err(FromCqlValError::BadCqlType),
710-
time::Time::from_cql(bad_type)
719+
time_03::Time::from_cql(bad_type)
711720
);
712721
}
713722

@@ -741,55 +750,55 @@ mod tests {
741750
);
742751
}
743752

744-
#[cfg(feature = "time")]
753+
#[cfg(feature = "time-03")]
745754
#[test]
746-
fn offset_datetime_from_cql() {
755+
fn offset_datetime_03_from_cql() {
747756
// UNIX epoch
748757
let unix_epoch = CqlValue::Timestamp(CqlTimestamp(0));
749758
assert_eq!(
750-
Ok(time::OffsetDateTime::UNIX_EPOCH),
751-
time::OffsetDateTime::from_cql(unix_epoch)
759+
Ok(time_03::OffsetDateTime::UNIX_EPOCH),
760+
time_03::OffsetDateTime::from_cql(unix_epoch)
752761
);
753762

754763
// 1 day 2 hours 3 minutes 4 seconds and 5 nanoseconds before UNIX epoch
755764
let before_epoch = CqlValue::Timestamp(CqlTimestamp(-(26 * 3600 + 3 * 60 + 4) * 1000 - 5));
756765
assert_eq!(
757-
Ok(time::OffsetDateTime::UNIX_EPOCH
758-
- time::Duration::new(26 * 3600 + 3 * 60 + 4, 5 * 1_000_000)),
759-
time::OffsetDateTime::from_cql(before_epoch)
766+
Ok(time_03::OffsetDateTime::UNIX_EPOCH
767+
- time_03::Duration::new(26 * 3600 + 3 * 60 + 4, 5 * 1_000_000)),
768+
time_03::OffsetDateTime::from_cql(before_epoch)
760769
);
761770

762771
// 6 days 7 hours 8 minutes 9 seconds and 10 nanoseconds after UNIX epoch
763772
let after_epoch =
764773
CqlValue::Timestamp(CqlTimestamp(((6 * 24 + 7) * 3600 + 8 * 60 + 9) * 1000 + 10));
765774
assert_eq!(
766-
Ok(time::PrimitiveDateTime::new(
767-
time::Date::from_ordinal_date(1970, 7).unwrap(),
768-
time::Time::from_hms_milli(7, 8, 9, 10).unwrap()
775+
Ok(time_03::PrimitiveDateTime::new(
776+
time_03::Date::from_ordinal_date(1970, 7).unwrap(),
777+
time_03::Time::from_hms_milli(7, 8, 9, 10).unwrap()
769778
)
770779
.assume_utc()),
771-
time::OffsetDateTime::from_cql(after_epoch)
780+
time_03::OffsetDateTime::from_cql(after_epoch)
772781
);
773782

774-
// Min possible stored timestamp. Since value is out of `time::OffsetDateTime` range, it should return `BadVal` error
783+
// Min possible stored timestamp. Since value is out of `time_03::OffsetDateTime` range, it should return `BadVal` error
775784
let min_timestamp = CqlValue::Timestamp(CqlTimestamp(i64::MIN));
776785
assert_eq!(
777786
Err(FromCqlValError::BadVal),
778-
time::OffsetDateTime::from_cql(min_timestamp)
787+
time_03::OffsetDateTime::from_cql(min_timestamp)
779788
);
780789

781-
// Max possible stored timestamp. Since value is out of `time::OffsetDateTime` range, it should return `BadVal` error
790+
// Max possible stored timestamp. Since value is out of `time_03::OffsetDateTime` range, it should return `BadVal` error
782791
let max_timestamp = CqlValue::Timestamp(CqlTimestamp(i64::MAX));
783792
assert_eq!(
784793
Err(FromCqlValError::BadVal),
785-
time::OffsetDateTime::from_cql(max_timestamp)
794+
time_03::OffsetDateTime::from_cql(max_timestamp)
786795
);
787796

788-
// Different CQL type. Since value can't be casted, it should return `BadCqlType` error
797+
// Different CQL type. Since value can't be cast, it should return `BadCqlType` error
789798
let bad_type = CqlValue::Double(0.5);
790799
assert_eq!(
791800
Err(FromCqlValError::BadCqlType),
792-
time::OffsetDateTime::from_cql(bad_type)
801+
time_03::OffsetDateTime::from_cql(bad_type)
793802
);
794803
}
795804

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

+19-19
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ impl CqlValue {
192192
self.as_cql_date().and_then(|date| date.try_into().ok())
193193
}
194194

195-
#[cfg(feature = "time")]
196-
pub fn as_date(&self) -> Option<time::Date> {
195+
#[cfg(feature = "time-03")]
196+
pub fn as_date(&self) -> Option<time_03::Date> {
197197
self.as_cql_date().and_then(|date| date.try_into().ok())
198198
}
199199

@@ -209,8 +209,8 @@ impl CqlValue {
209209
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
210210
}
211211

212-
#[cfg(feature = "time")]
213-
pub fn as_offset_date_time(&self) -> Option<time::OffsetDateTime> {
212+
#[cfg(feature = "time-03")]
213+
pub fn as_offset_date_time(&self) -> Option<time_03::OffsetDateTime> {
214214
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
215215
}
216216

@@ -226,8 +226,8 @@ impl CqlValue {
226226
self.as_cql_time().and_then(|ts| ts.try_into().ok())
227227
}
228228

229-
#[cfg(feature = "time")]
230-
pub fn as_time(&self) -> Option<time::Time> {
229+
#[cfg(feature = "time-03")]
230+
pub fn as_time(&self) -> Option<time_03::Time> {
231231
self.as_cql_time().and_then(|ts| ts.try_into().ok())
232232
}
233233

@@ -1318,21 +1318,21 @@ mod tests {
13181318
);
13191319
}
13201320

1321-
#[cfg(feature = "time")]
1321+
#[cfg(feature = "time-03")]
13221322
#[test]
1323-
fn test_date_from_cql() {
1324-
use time::Date;
1325-
use time::Month::*;
1323+
fn test_date_03_from_cql() {
1324+
use time_03::Date;
1325+
use time_03::Month::*;
13261326

1327-
// 2^31 when converted to time::Date is 1970-01-01
1327+
// 2^31 when converted to time_03::Date is 1970-01-01
13281328
let unix_epoch = Date::from_calendar_date(1970, January, 1).unwrap();
13291329
let date =
13301330
super::deser_cql_value(&ColumnType::Date, &mut (1u32 << 31).to_be_bytes().as_ref())
13311331
.unwrap();
13321332

13331333
assert_eq!(date.as_date(), Some(unix_epoch));
13341334

1335-
// 2^31 - 30 when converted to time::Date is 1969-12-02
1335+
// 2^31 - 30 when converted to time_03::Date is 1969-12-02
13361336
let before_epoch = Date::from_calendar_date(1969, December, 2).unwrap();
13371337
let date = super::deser_cql_value(
13381338
&ColumnType::Date,
@@ -1342,7 +1342,7 @@ mod tests {
13421342

13431343
assert_eq!(date.as_date(), Some(before_epoch));
13441344

1345-
// 2^31 + 30 when converted to time::Date is 1970-01-31
1345+
// 2^31 + 30 when converted to time_03::Date is 1970-01-31
13461346
let after_epoch = Date::from_calendar_date(1970, January, 31).unwrap();
13471347
let date = super::deser_cql_value(
13481348
&ColumnType::Date,
@@ -1431,10 +1431,10 @@ mod tests {
14311431
assert_eq!(time.as_naive_time(), Some(midnight));
14321432
}
14331433

1434-
#[cfg(feature = "time")]
1434+
#[cfg(feature = "time-03")]
14351435
#[test]
1436-
fn test_primitive_time_from_cql() {
1437-
use time::Time;
1436+
fn test_primitive_time_03_from_cql() {
1437+
use time_03::Time;
14381438

14391439
// 0 when converted to NaiveTime is 0:0:0.0
14401440
let midnight = Time::from_hms_nano(0, 0, 0, 0).unwrap();
@@ -1542,10 +1542,10 @@ mod tests {
15421542
);
15431543
}
15441544

1545-
#[cfg(feature = "time")]
1545+
#[cfg(feature = "time-03")]
15461546
#[test]
1547-
fn test_offset_datetime_from_cql() {
1548-
use time::{Date, Month::*, OffsetDateTime, PrimitiveDateTime, Time};
1547+
fn test_offset_datetime_03_from_cql() {
1548+
use time_03::{Date, Month::*, OffsetDateTime, PrimitiveDateTime, Time};
15491549

15501550
// 0 when converted to OffsetDateTime is 1970-01-01 0:00:00.00
15511551
let unix_epoch = OffsetDateTime::from_unix_timestamp(0).unwrap();

0 commit comments

Comments
 (0)