Skip to content

Commit cc705ad

Browse files
committed
cqlvalue: make chrono conversions test utility
Made `CqlValue`-to-chrono types conversion methods a private utility methods used only for tests.
1 parent c737490 commit cc705ad

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

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

+19-16
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ impl CqlValue {
184184
}
185185
}
186186

187+
#[cfg(test)]
187188
#[cfg(feature = "chrono-04")]
188-
pub fn as_naive_date(&self) -> Option<chrono_04::NaiveDate> {
189+
fn as_naive_date_04(&self) -> Option<chrono_04::NaiveDate> {
189190
self.as_cql_date().and_then(|date| date.try_into().ok())
190191
}
191192

@@ -202,8 +203,9 @@ impl CqlValue {
202203
}
203204
}
204205

206+
#[cfg(test)]
205207
#[cfg(feature = "chrono-04")]
206-
pub fn as_datetime(&self) -> Option<chrono_04::DateTime<chrono_04::Utc>> {
208+
fn as_datetime_04(&self) -> Option<chrono_04::DateTime<chrono_04::Utc>> {
207209
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
208210
}
209211

@@ -220,8 +222,9 @@ impl CqlValue {
220222
}
221223
}
222224

225+
#[cfg(test)]
223226
#[cfg(feature = "chrono-04")]
224-
pub fn as_naive_time(&self) -> Option<chrono_04::NaiveTime> {
227+
fn as_naive_time_04(&self) -> Option<chrono_04::NaiveTime> {
225228
self.as_cql_time().and_then(|ts| ts.try_into().ok())
226229
}
227230

@@ -1280,7 +1283,7 @@ mod tests {
12801283
super::deser_cql_value(&ColumnType::Date, &mut (1u32 << 31).to_be_bytes().as_ref())
12811284
.unwrap();
12821285

1283-
assert_eq!(date.as_naive_date(), Some(unix_epoch));
1286+
assert_eq!(date.as_naive_date_04(), Some(unix_epoch));
12841287

12851288
// 2^31 - 30 when converted to NaiveDate is 1969-12-02
12861289
let before_epoch = NaiveDate::from_ymd_opt(1969, 12, 2).unwrap();
@@ -1290,7 +1293,7 @@ mod tests {
12901293
)
12911294
.unwrap();
12921295

1293-
assert_eq!(date.as_naive_date(), Some(before_epoch));
1296+
assert_eq!(date.as_naive_date_04(), Some(before_epoch));
12941297

12951298
// 2^31 + 30 when converted to NaiveDate is 1970-01-31
12961299
let after_epoch = NaiveDate::from_ymd_opt(1970, 1, 31).unwrap();
@@ -1300,20 +1303,20 @@ mod tests {
13001303
)
13011304
.unwrap();
13021305

1303-
assert_eq!(date.as_naive_date(), Some(after_epoch));
1306+
assert_eq!(date.as_naive_date_04(), Some(after_epoch));
13041307

13051308
// 0 and u32::MAX are out of NaiveDate range, fails with an error, not panics
13061309
assert_eq!(
13071310
super::deser_cql_value(&ColumnType::Date, &mut 0_u32.to_be_bytes().as_ref())
13081311
.unwrap()
1309-
.as_naive_date(),
1312+
.as_naive_date_04(),
13101313
None
13111314
);
13121315

13131316
assert_eq!(
13141317
super::deser_cql_value(&ColumnType::Date, &mut u32::MAX.to_be_bytes().as_ref())
13151318
.unwrap()
1316-
.as_naive_date(),
1319+
.as_naive_date_04(),
13171320
None
13181321
);
13191322
}
@@ -1402,7 +1405,7 @@ mod tests {
14021405
let time =
14031406
super::deser_cql_value(&ColumnType::Time, &mut (0i64).to_be_bytes().as_ref()).unwrap();
14041407

1405-
assert_eq!(time.as_naive_time(), Some(midnight));
1408+
assert_eq!(time.as_naive_time_04(), Some(midnight));
14061409

14071410
// 10:10:30.500,000,001
14081411
let (h, m, s, n) = (10, 10, 30, 500_000_001);
@@ -1415,7 +1418,7 @@ mod tests {
14151418
)
14161419
.unwrap();
14171420

1418-
assert_eq!(time.as_naive_time(), Some(midnight));
1421+
assert_eq!(time.as_naive_time_04(), Some(midnight));
14191422

14201423
// 23:59:59.999,999,999
14211424
let (h, m, s, n) = (23, 59, 59, 999_999_999);
@@ -1428,7 +1431,7 @@ mod tests {
14281431
)
14291432
.unwrap();
14301433

1431-
assert_eq!(time.as_naive_time(), Some(midnight));
1434+
assert_eq!(time.as_naive_time_04(), Some(midnight));
14321435
}
14331436

14341437
#[cfg(feature = "time-03")]
@@ -1493,7 +1496,7 @@ mod tests {
14931496
let date = super::deser_cql_value(&ColumnType::Timestamp, &mut 0i64.to_be_bytes().as_ref())
14941497
.unwrap();
14951498

1496-
assert_eq!(date.as_datetime(), Some(unix_epoch));
1499+
assert_eq!(date.as_datetime_04(), Some(unix_epoch));
14971500

14981501
// When converted to NaiveDateTime, this is 1969-12-01 11:29:29.5
14991502
let timestamp: i64 = -((((30 * 24 + 12) * 60 + 30) * 60 + 30) * 1000 + 500);
@@ -1508,7 +1511,7 @@ mod tests {
15081511
)
15091512
.unwrap();
15101513

1511-
assert_eq!(date.as_datetime(), Some(before_epoch));
1514+
assert_eq!(date.as_datetime_04(), Some(before_epoch));
15121515

15131516
// when converted to NaiveDateTime, this is is 1970-01-31 12:30:30.5
15141517
let timestamp: i64 = (((30 * 24 + 12) * 60 + 30) * 60 + 30) * 1000 + 500;
@@ -1523,20 +1526,20 @@ mod tests {
15231526
)
15241527
.unwrap();
15251528

1526-
assert_eq!(date.as_datetime(), Some(after_epoch));
1529+
assert_eq!(date.as_datetime_04(), Some(after_epoch));
15271530

15281531
// 0 and u32::MAX are out of NaiveDate range, fails with an error, not panics
15291532
assert_eq!(
15301533
super::deser_cql_value(&ColumnType::Timestamp, &mut i64::MIN.to_be_bytes().as_ref())
15311534
.unwrap()
1532-
.as_datetime(),
1535+
.as_datetime_04(),
15331536
None
15341537
);
15351538

15361539
assert_eq!(
15371540
super::deser_cql_value(&ColumnType::Timestamp, &mut i64::MAX.to_be_bytes().as_ref())
15381541
.unwrap()
1539-
.as_datetime(),
1542+
.as_datetime_04(),
15401543
None
15411544
);
15421545
}

0 commit comments

Comments
 (0)