From c9158b3220951ac22ba37a3cac15c198e94c3955 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Tue, 5 Nov 2024 03:44:07 -0800 Subject: [PATCH 1/2] add new test, better fail-check, and non-transitioning tz fix --- core/time/timezone/tz_windows.odin | 16 ++++++++++++++++ core/time/timezone/tzdate.odin | 2 ++ tests/core/time/test_core_time.odin | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/core/time/timezone/tz_windows.odin b/core/time/timezone/tz_windows.odin index f1604b939..a86598d90 100644 --- a/core/time/timezone/tz_windows.odin +++ b/core/time/timezone/tz_windows.odin @@ -203,6 +203,22 @@ generate_rrule_from_tzi :: proc(tzi: ^REG_TZI_FORMAT, abbrevs: TZ_Abbrev, alloca if err != nil { return } defer if err != nil { delete(std_name, allocator) } + if (tzi.std_date.month == 0) { + return datetime.TZ_RRule{ + has_dst = false, + + std_name = std_name, + std_offset = -(i64(tzi.bias) + i64(tzi.std_bias)) * 60, + dst_date = datetime.TZ_Transition_Date{ + type = .Month_Week_Day, + month = u8(tzi.std_date.month), + week = u8(tzi.std_date.day), + day = tzi.std_date.day_of_week, + time = (i64(tzi.std_date.hour) * 60 * 60) + (i64(tzi.std_date.minute) * 60) + i64(tzi.std_date.second), + } + }, true + } + dst_name: string dst_name, err = strings.clone(abbrevs.dst, allocator) if err != nil { return } diff --git a/core/time/timezone/tzdate.odin b/core/time/timezone/tzdate.odin index 8f83d1bf4..96df44299 100644 --- a/core/time/timezone/tzdate.odin +++ b/core/time/timezone/tzdate.odin @@ -93,6 +93,8 @@ trans_date_to_seconds :: proc(year: i64, td: datetime.TZ_Transition_Date) -> (se switch td.type { case .Month_Week_Day: + if td.month < 1 { return } + t += month_to_seconds(int(td.month) - 1, is_leap) weekday := ((t + (4 * DAY_SEC)) %% (7 * DAY_SEC)) / DAY_SEC diff --git a/tests/core/time/test_core_time.odin b/tests/core/time/test_core_time.odin index 93bc73789..3bd4c3151 100644 --- a/tests/core/time/test_core_time.odin +++ b/tests/core/time/test_core_time.odin @@ -561,3 +561,17 @@ test_check_timezone_posix_tz :: proc(t: ^testing.T) { defer tz.rrule_destroy(wgt_rrule) testing.expectf(t, rrule_eq(wgt_rrule, correct_wgt_rrule), "POSIX TZ parsed incorrectly") } + +@test +test_check_timezone_edgecases :: proc(t: ^testing.T) { + utc_dt, _ := dt.components_to_datetime(2024, 10, 4, 0, 47, 0) + + tok_tz, tok_load_ok := tz.region_load("Asia/Tokyo") + testing.expectf(t, tok_load_ok, "Failed to load Asia/Tokyo timezone") + defer tz.region_destroy(tok_tz) + + ret_dt := tz.datetime_to_tz(utc_dt, tok_tz) + expected_tok_dt, _ := dt.components_to_datetime(2024, 10, 4, 9, 47, 0) + + testing.expectf(t, datetime_eq(ret_dt, expected_tok_dt), "Failed to convert to Tokyo time") +} From b2d1fbba9cf6bfafc01a4d24af20bfdc79c2652d Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Tue, 5 Nov 2024 03:48:47 -0800 Subject: [PATCH 2/2] oops, missed a comma --- core/time/timezone/tz_windows.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/time/timezone/tz_windows.odin b/core/time/timezone/tz_windows.odin index a86598d90..238c4c933 100644 --- a/core/time/timezone/tz_windows.odin +++ b/core/time/timezone/tz_windows.odin @@ -215,7 +215,7 @@ generate_rrule_from_tzi :: proc(tzi: ^REG_TZI_FORMAT, abbrevs: TZ_Abbrev, alloca week = u8(tzi.std_date.day), day = tzi.std_date.day_of_week, time = (i64(tzi.std_date.hour) * 60 * 60) + (i64(tzi.std_date.minute) * 60) + i64(tzi.std_date.second), - } + }, }, true }