Skip to content

Commit 5a8dcb0

Browse files
author
Devdutt Shenoi
committed
test: minute and slotting
1 parent 8b48680 commit 5a8dcb0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/utils/time.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,34 @@ mod tests {
470470
let left = prefixes.iter().map(String::as_str).collect::<Vec<&str>>();
471471
assert_eq!(left.as_slice(), right);
472472
}
473+
474+
#[test]
475+
fn valid_minute_to_minute_slot() {
476+
let res = Minute::try_from(10);
477+
assert!(res.is_ok());
478+
assert_eq!(res.unwrap().to_slot(1), "10");
479+
}
480+
481+
#[test]
482+
fn invalid_minute() {
483+
assert!(Minute::try_from(100).is_err());
484+
}
485+
486+
#[test]
487+
fn minute_from_timestamp() {
488+
let timestamp = NaiveDateTime::parse_from_str("2025-01-01 02:03", "%Y-%m-%d %H:%M").unwrap();
489+
assert_eq!(Minute::from(timestamp).to_slot(1), "03");
490+
}
491+
492+
#[test]
493+
fn slot_5_min_from_timestamp() {
494+
let timestamp = NaiveDateTime::parse_from_str("2025-01-01 02:03", "%Y-%m-%d %H:%M").unwrap();
495+
assert_eq!(Minute::from(timestamp).to_slot(5), "00-04");
496+
}
497+
498+
#[test]
499+
fn slot_30_min_from_timestamp() {
500+
let timestamp = NaiveDateTime::parse_from_str("2025-01-01 02:33", "%Y-%m-%d %H:%M").unwrap();
501+
assert_eq!(Minute::from(timestamp).to_slot(30), "30-59");
502+
}
473503
}

0 commit comments

Comments
 (0)