From b4e6abc79f8dc868789a9be63fc56ad61da3f832 Mon Sep 17 00:00:00 2001 From: Alec Murphy Date: Sat, 8 Mar 2025 16:28:12 -0500 Subject: [PATCH] System/Utilities/Time: Update for DST --- System/Utilities/Time.HC | 42 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/System/Utilities/Time.HC b/System/Utilities/Time.HC index ce5328d..3760dad 100644 --- a/System/Utilities/Time.HC +++ b/System/Utilities/Time.HC @@ -63,22 +63,40 @@ U0 @time_update(U8* date_str, I64 mS_delta, I64 hour_offset) @time_cmos_update_byte(0x00, second); } +Bool @is_dst(I64 month, I64 day, I64 day_of_week, I64 hour) +{ + if (month < 3 || month > 11) { + return FALSE; + } + if (month > 3 && month < 11) { + return TRUE; + } + if (month == 3) { + if (day < (14 - day_of_week)) { + return FALSE; + } + if (day > (14 - day_of_week) && hour >= 2) { + return TRUE; + } + return FALSE; + } + if (month == 11) { + if (day < (7 - day_of_week)) { + return TRUE; + } + if (day == (7 - day_of_week) && hour < 1) { + return TRUE; + } + return FALSE; + } + return FALSE; +} + Bool @time_in_dst() { CDateStruct ds; Date2Struct(&ds, Now); - if (ds.mon > 3 && ds.mon < 11) - return TRUE; - if (ds.mon < 3 || ds.mon > 11) - return FALSE; - if (ds.mon == 3 && ds.day_of_mon != 8) - return ds.day_of_mon > 8; - if (ds.mon == 3) - return ds.hour > 1; - if (ds.mon == 11 && ds.day_of_mon != 1) - return FALSE; - if (ds.mon == 11) - return ds.hour < 2; + return @is_dst(ds.mon, ds.day_of_mon, ds.day_of_week, ds.hour); } I64 @time_tz_offset()