Skip to content

Commit 853a2fe

Browse files
author
Devdutt Shenoi
committed
panic on unacceptable granularity
1 parent 5a8dcb0 commit 853a2fe

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/utils/time.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ impl From<NaiveDateTime> for Minute {
303303
impl Minute {
304304
/// Convert minutes to a slot range
305305
/// e.g. given minute = 15 and OBJECT_STORE_DATA_GRANULARITY = 10 returns "10-19"
306+
///
307+
/// ### PANICS
308+
/// If the provided `data_granularity` value isn't cleanly divisble from 60
306309
pub fn to_slot(self, data_granularity: u32) -> String {
310+
assert!(data_granularity % 60 == 0);
307311
let block_n = self.block / data_granularity;
308312
let block_start = block_n * data_granularity;
309313
if data_granularity == 1 {
@@ -500,4 +504,10 @@ mod tests {
500504
let timestamp = NaiveDateTime::parse_from_str("2025-01-01 02:33", "%Y-%m-%d %H:%M").unwrap();
501505
assert_eq!(Minute::from(timestamp).to_slot(30), "30-59");
502506
}
507+
508+
#[test]
509+
#[should_panic]
510+
fn illegal_slot_granularity() {
511+
Minute::try_from(0).unwrap().to_slot(40);
512+
}
503513
}

0 commit comments

Comments
 (0)