Skip to content

Commit fabfee7

Browse files
committed
cqlvalue: make conversion to time_03 test utils
Since some other version of time_03 might be supported in the future, we cannot have multiple methods such as `as_date()` defined. I don't think it's good idea to expose version specific methods (e.g. `as_date_03()`) to the users. This is why we make them test utilities only.
1 parent 248d2db commit fabfee7

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

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

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

195+
#[cfg(test)]
195196
#[cfg(feature = "time-03")]
196-
pub fn as_date(&self) -> Option<time_03::Date> {
197+
fn as_date_03(&self) -> Option<time_03::Date> {
197198
self.as_cql_date().and_then(|date| date.try_into().ok())
198199
}
199200

@@ -209,8 +210,9 @@ impl CqlValue {
209210
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
210211
}
211212

213+
#[cfg(test)]
212214
#[cfg(feature = "time-03")]
213-
pub fn as_offset_date_time(&self) -> Option<time_03::OffsetDateTime> {
215+
fn as_offset_date_time_03(&self) -> Option<time_03::OffsetDateTime> {
214216
self.as_cql_timestamp().and_then(|ts| ts.try_into().ok())
215217
}
216218

@@ -226,8 +228,9 @@ impl CqlValue {
226228
self.as_cql_time().and_then(|ts| ts.try_into().ok())
227229
}
228230

231+
#[cfg(test)]
229232
#[cfg(feature = "time-03")]
230-
pub fn as_time(&self) -> Option<time_03::Time> {
233+
fn as_time_03(&self) -> Option<time_03::Time> {
231234
self.as_cql_time().and_then(|ts| ts.try_into().ok())
232235
}
233236

@@ -1330,7 +1333,7 @@ mod tests {
13301333
super::deser_cql_value(&ColumnType::Date, &mut (1u32 << 31).to_be_bytes().as_ref())
13311334
.unwrap();
13321335

1333-
assert_eq!(date.as_date(), Some(unix_epoch));
1336+
assert_eq!(date.as_date_03(), Some(unix_epoch));
13341337

13351338
// 2^31 - 30 when converted to time_03::Date is 1969-12-02
13361339
let before_epoch = Date::from_calendar_date(1969, December, 2).unwrap();
@@ -1340,7 +1343,7 @@ mod tests {
13401343
)
13411344
.unwrap();
13421345

1343-
assert_eq!(date.as_date(), Some(before_epoch));
1346+
assert_eq!(date.as_date_03(), Some(before_epoch));
13441347

13451348
// 2^31 + 30 when converted to time_03::Date is 1970-01-31
13461349
let after_epoch = Date::from_calendar_date(1970, January, 31).unwrap();
@@ -1350,20 +1353,20 @@ mod tests {
13501353
)
13511354
.unwrap();
13521355

1353-
assert_eq!(date.as_date(), Some(after_epoch));
1356+
assert_eq!(date.as_date_03(), Some(after_epoch));
13541357

13551358
// 0 and u32::MAX are out of NaiveDate range, fails with an error, not panics
13561359
assert_eq!(
13571360
super::deser_cql_value(&ColumnType::Date, &mut 0_u32.to_be_bytes().as_ref())
13581361
.unwrap()
1359-
.as_date(),
1362+
.as_date_03(),
13601363
None
13611364
);
13621365

13631366
assert_eq!(
13641367
super::deser_cql_value(&ColumnType::Date, &mut u32::MAX.to_be_bytes().as_ref())
13651368
.unwrap()
1366-
.as_date(),
1369+
.as_date_03(),
13671370
None
13681371
);
13691372
}
@@ -1441,8 +1444,7 @@ mod tests {
14411444
let time =
14421445
super::deser_cql_value(&ColumnType::Time, &mut (0i64).to_be_bytes().as_ref()).unwrap();
14431446

1444-
dbg!(&time);
1445-
assert_eq!(time.as_time(), Some(midnight));
1447+
assert_eq!(time.as_time_03(), Some(midnight));
14461448

14471449
// 10:10:30.500,000,001
14481450
let (h, m, s, n) = (10, 10, 30, 500_000_001);
@@ -1455,7 +1457,7 @@ mod tests {
14551457
)
14561458
.unwrap();
14571459

1458-
assert_eq!(time.as_time(), Some(midnight));
1460+
assert_eq!(time.as_time_03(), Some(midnight));
14591461

14601462
// 23:59:59.999,999,999
14611463
let (h, m, s, n) = (23, 59, 59, 999_999_999);
@@ -1468,7 +1470,7 @@ mod tests {
14681470
)
14691471
.unwrap();
14701472

1471-
assert_eq!(time.as_time(), Some(midnight));
1473+
assert_eq!(time.as_time_03(), Some(midnight));
14721474
}
14731475

14741476
#[test]
@@ -1552,7 +1554,7 @@ mod tests {
15521554
let date = super::deser_cql_value(&ColumnType::Timestamp, &mut 0i64.to_be_bytes().as_ref())
15531555
.unwrap();
15541556

1555-
assert_eq!(date.as_offset_date_time(), Some(unix_epoch));
1557+
assert_eq!(date.as_offset_date_time_03(), Some(unix_epoch));
15561558

15571559
// When converted to NaiveDateTime, this is 1969-12-01 11:29:29.5
15581560
let timestamp: i64 = -((((30 * 24 + 12) * 60 + 30) * 60 + 30) * 1000 + 500);
@@ -1567,7 +1569,7 @@ mod tests {
15671569
)
15681570
.unwrap();
15691571

1570-
assert_eq!(date.as_offset_date_time(), Some(before_epoch));
1572+
assert_eq!(date.as_offset_date_time_03(), Some(before_epoch));
15711573

15721574
// when converted to NaiveDateTime, this is is 1970-01-31 12:30:30.5
15731575
let timestamp: i64 = (((30 * 24 + 12) * 60 + 30) * 60 + 30) * 1000 + 500;
@@ -1582,20 +1584,20 @@ mod tests {
15821584
)
15831585
.unwrap();
15841586

1585-
assert_eq!(date.as_offset_date_time(), Some(after_epoch));
1587+
assert_eq!(date.as_offset_date_time_03(), Some(after_epoch));
15861588

15871589
// 0 and u32::MAX are out of NaiveDate range, fails with an error, not panics
15881590
assert_eq!(
15891591
super::deser_cql_value(&ColumnType::Timestamp, &mut i64::MIN.to_be_bytes().as_ref())
15901592
.unwrap()
1591-
.as_offset_date_time(),
1593+
.as_offset_date_time_03(),
15921594
None
15931595
);
15941596

15951597
assert_eq!(
15961598
super::deser_cql_value(&ColumnType::Timestamp, &mut i64::MAX.to_be_bytes().as_ref())
15971599
.unwrap()
1598-
.as_offset_date_time(),
1600+
.as_offset_date_time_03(),
15991601
None
16001602
);
16011603
}

0 commit comments

Comments
 (0)