Skip to content

Commit

Permalink
config: test +HHMM offset in ReadableSchedule (#17081)
Browse files Browse the repository at this point in the history
close #17080

* Test both formats +HHMM offsets and as well as +HH:MM for ReadableSchedule.

Signed-off-by: Alex Feinberg <alex@strlen.net>
  • Loading branch information
afeinberg authored Jun 1, 2024
1 parent 7ccbe31 commit 44356c1
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion components/tikv_util/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,8 +2068,9 @@ mod tests {

#[test]
fn test_readable_schedule() {
// Tests HHMM offsets for timezones.
let schedule = ReadableSchedule(
vec!["09:30 +00:00", "23:00 +00:00"]
vec!["09:30 +0000", "11:15 +0530", "23:00 +0000"]
.into_iter()
.flat_map(ReadableOffsetTime::from_str)
.collect::<Vec<_>>(),
Expand All @@ -2080,26 +2081,51 @@ mod tests {
let time_c = DateTime::parse_from_rfc3339("2023-10-27T23:15:00-00:00").unwrap();
let time_d = DateTime::parse_from_rfc3339("2023-10-27T23:00:00-00:00").unwrap();
let time_e = DateTime::parse_from_rfc3339("2023-10-27T20:00:00-00:00").unwrap();
let time_f = DateTime::parse_from_rfc3339("2024-05-29T05:45:00-00:00").unwrap();

// positives for schedule by hour
assert!(schedule.is_scheduled_this_hour(&time_a));
assert!(schedule.is_scheduled_this_hour(&time_b));
assert!(schedule.is_scheduled_this_hour(&time_c));
assert!(schedule.is_scheduled_this_hour(&time_d));
assert!(schedule.is_scheduled_this_hour(&time_f));

// negatives for schedule by hour
assert!(!schedule.is_scheduled_this_hour(&time_e));

// positives for schedule by hour and minute
assert!(schedule.is_scheduled_this_hour_minute(&time_a));
assert!(schedule.is_scheduled_this_hour_minute(&time_d));
assert!(schedule.is_scheduled_this_hour_minute(&time_f));

// negatives for schedule by hour and minute
assert!(!schedule.is_scheduled_this_hour_minute(&time_b));
assert!(!schedule.is_scheduled_this_hour_minute(&time_c));
assert!(!schedule.is_scheduled_this_hour_minute(&time_e));
}

#[test]
fn test_readable_schedule_col_separated_offsets() {
// Test that HH:MM offsets are supported.
let schedule = ReadableSchedule(
vec!["09:30 +00:00", "11:15 +05:30", "23:00 +00:00"]
.into_iter()
.flat_map(ReadableOffsetTime::from_str)
.collect::<Vec<_>>(),
);

let time_a = DateTime::parse_from_rfc3339("2023-10-27T09:30:57-00:00").unwrap();
let time_b = DateTime::parse_from_rfc3339("2023-10-27T23:00:00-00:00").unwrap();
let time_c = DateTime::parse_from_rfc3339("2024-05-29T05:45:00-00:00").unwrap();
let time_d = DateTime::parse_from_rfc3339("2023-10-27T20:00:00-00:00").unwrap();

assert!(schedule.is_scheduled_this_hour(&time_a));
assert!(schedule.is_scheduled_this_hour(&time_b));
assert!(schedule.is_scheduled_this_hour(&time_c));
assert!(schedule.is_scheduled_this_hour_minute(&time_c));
assert!(!schedule.is_scheduled_this_hour_minute(&time_d));
}

#[test]
fn test_readable_schedule_parse() {
let check_parse = |vec_strs: Vec<String>, strs| {
Expand Down

0 comments on commit 44356c1

Please sign in to comment.