Skip to content

Commit 0e97a45

Browse files
committed
Add test case for NYC timezone same range tests
1 parent ec1cd7b commit 0e97a45

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

crates/hotfix/src/session_schedule.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ mod tests {
11351135
}
11361136

11371137
#[test]
1138-
fn test_is_same_session_period_daily_simple_utc() {
1138+
fn test_is_same_session_period_daily_utc() {
11391139
let schedule = SessionSchedule::Daily {
11401140
start_time: NaiveTime::from_hms_opt(9, 0, 0).unwrap(),
11411141
end_time: NaiveTime::from_hms_opt(17, 0, 0).unwrap(),
@@ -1182,4 +1182,49 @@ mod tests {
11821182
assert!(schedule.is_same_session_period(&dt1, &dt4).is_err());
11831183
assert!(schedule.is_same_session_period(&dt4, &dt1).is_err());
11841184
}
1185+
1186+
#[test]
1187+
fn test_is_same_session_period_daily_nyc() {
1188+
let schedule = SessionSchedule::Daily {
1189+
start_time: NaiveTime::from_hms_opt(1, 0, 0).unwrap(),
1190+
end_time: NaiveTime::from_hms_opt(23, 0, 0).unwrap(),
1191+
timezone: Tz::America__New_York,
1192+
};
1193+
1194+
// same session period on the same day (both in EST)
1195+
let dt1 = DateTime::parse_from_rfc3339("2025-01-15T01:30:00-05:00")
1196+
.unwrap()
1197+
.to_utc();
1198+
let dt2 = DateTime::parse_from_rfc3339("2025-01-15T22:45:00-05:00")
1199+
.unwrap()
1200+
.to_utc();
1201+
assert!(schedule.is_same_session_period(&dt1, &dt2).unwrap());
1202+
1203+
// different session periods on consecutive days
1204+
let dt3 = DateTime::parse_from_rfc3339("2024-01-15T22:30:00-05:00")
1205+
.unwrap()
1206+
.to_utc();
1207+
let dt4 = DateTime::parse_from_rfc3339("2024-01-16T02:30:00-05:00")
1208+
.unwrap()
1209+
.to_utc();
1210+
assert!(!schedule.is_same_session_period(&dt3, &dt4).unwrap());
1211+
1212+
// session boundary testing - end of session vs start of next session
1213+
let dt5 = DateTime::parse_from_rfc3339("2024-01-15T22:59:59-05:00")
1214+
.unwrap()
1215+
.to_utc();
1216+
let dt6 = DateTime::parse_from_rfc3339("2024-01-16T01:00:01-05:00")
1217+
.unwrap()
1218+
.to_utc();
1219+
assert!(!schedule.is_same_session_period(&dt5, &dt6).unwrap());
1220+
1221+
// time that doesn't fall into any session period
1222+
let dt7 = DateTime::parse_from_rfc3339("2024-01-15T23:30:00-05:00")
1223+
.unwrap()
1224+
.to_utc();
1225+
let dt8 = DateTime::parse_from_rfc3339("2024-01-15T10:00:00-05:00")
1226+
.unwrap()
1227+
.to_utc();
1228+
assert!(schedule.is_same_session_period(&dt7, &dt8).is_err());
1229+
}
11851230
}

0 commit comments

Comments
 (0)