Skip to content

Commit 25c1728

Browse files
committed
Extend test coverage for session schedule calculations
1 parent 0444d73 commit 25c1728

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

crates/hotfix/src/session_schedule.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,19 @@ mod tests {
11421142
assert!(schedule.is_err());
11431143
}
11441144

1145+
#[test]
1146+
fn test_is_same_session_period_nonstop() {
1147+
let schedule = SessionSchedule::NonStop;
1148+
1149+
let dt1 = DateTime::parse_from_rfc3339("2025-01-15T01:30:00-05:00")
1150+
.unwrap()
1151+
.to_utc();
1152+
let dt2 = DateTime::parse_from_rfc3339("2026-01-15T23:30:00-05:00")
1153+
.unwrap()
1154+
.to_utc();
1155+
assert!(schedule.is_same_session_period(&dt1, &dt2).unwrap());
1156+
}
1157+
11451158
#[test]
11461159
fn test_is_same_session_period_daily_utc() {
11471160
let schedule = SessionSchedule::Daily {
@@ -1236,6 +1249,36 @@ mod tests {
12361249
assert!(schedule.is_same_session_period(&dt7, &dt8).is_err());
12371250
}
12381251

1252+
#[test]
1253+
fn test_is_same_session_period_daily_nyc_with_midnight_crossover() {
1254+
// schedule end time is past midnight
1255+
let schedule = SessionSchedule::Daily {
1256+
start_time: NaiveTime::from_hms_opt(6, 0, 0).unwrap(),
1257+
end_time: NaiveTime::from_hms_opt(1, 0, 0).unwrap(),
1258+
timezone: Tz::America__New_York,
1259+
};
1260+
1261+
// same session period on consecutive days
1262+
let dt1 = DateTime::parse_from_rfc3339("2025-01-15T15:30:00-05:00")
1263+
.unwrap()
1264+
.to_utc();
1265+
let dt2 = DateTime::parse_from_rfc3339("2025-01-16T00:45:00-05:00")
1266+
.unwrap()
1267+
.to_utc();
1268+
assert!(schedule.is_same_session_period(&dt1, &dt2).unwrap());
1269+
assert!(schedule.is_same_session_period(&dt2, &dt1).unwrap());
1270+
1271+
// different session period on the same day
1272+
let dt1 = DateTime::parse_from_rfc3339("2025-01-15T15:30:00-05:00")
1273+
.unwrap()
1274+
.to_utc();
1275+
let dt2 = DateTime::parse_from_rfc3339("2025-01-15T00:45:00-05:00")
1276+
.unwrap()
1277+
.to_utc();
1278+
assert!(!schedule.is_same_session_period(&dt1, &dt2).unwrap());
1279+
assert!(!schedule.is_same_session_period(&dt2, &dt1).unwrap());
1280+
}
1281+
12391282
#[test]
12401283
fn test_is_same_session_period_weekdays_utc() {
12411284
let schedule = SessionSchedule::Weekdays {
@@ -1303,4 +1346,28 @@ mod tests {
13031346
assert!(schedule.is_same_session_period(&dt1, &dt4).is_err());
13041347
assert!(schedule.is_same_session_period(&dt4, &dt1).is_err());
13051348
}
1349+
1350+
#[test]
1351+
fn construct_utc_at_gap() {
1352+
// Test DST gap (spring forward) - 2:30 AM doesn't exist on March 10, 2024 in US/Eastern
1353+
let date = NaiveDate::from_ymd_opt(2024, 3, 10).unwrap();
1354+
let time = NaiveTime::from_hms_opt(2, 30, 0).unwrap(); // This time is skipped during DST transition
1355+
let timezone = chrono_tz::US::Eastern;
1356+
1357+
let result = construct_utc(&date, &time, &timezone);
1358+
1359+
assert!(result.is_err());
1360+
}
1361+
1362+
#[test]
1363+
fn construct_utc_at_fold() {
1364+
// Test DST fold (fall back) - 1:30 AM occurs twice on November 3, 2024 in US/Eastern
1365+
let date = NaiveDate::from_ymd_opt(2024, 11, 3).unwrap();
1366+
let time = NaiveTime::from_hms_opt(1, 30, 0).unwrap(); // This time exists twice during DST transition
1367+
let timezone = chrono_tz::US::Eastern;
1368+
1369+
let result = construct_utc(&date, &time, &timezone);
1370+
1371+
assert!(result.is_err());
1372+
}
13061373
}

0 commit comments

Comments
 (0)