diff options
| author | Colin Davidson <colrdavidson@gmail.com> | 2024-10-10 09:14:29 -0700 |
|---|---|---|
| committer | Colin Davidson <colrdavidson@gmail.com> | 2024-10-10 09:14:29 -0700 |
| commit | 4c8e3554446caa8894fef17b536f9b043177b23a (patch) | |
| tree | 592666a77b91fe41ccb6982ff2f4945775f7348c /core/time | |
| parent | a6502c3e8c9572ad22595d33eb3a36d2c7f06796 (diff) | |
tweaks per laytan suggestions
Diffstat (limited to 'core/time')
| -rw-r--r-- | core/time/datetime/constants.odin | 4 | ||||
| -rw-r--r-- | core/time/timezone/tz_unix.odin | 8 | ||||
| -rw-r--r-- | core/time/timezone/tzdate.odin | 6 | ||||
| -rw-r--r-- | core/time/timezone/tzif.odin | 4 |
4 files changed, 13 insertions, 9 deletions
diff --git a/core/time/datetime/constants.odin b/core/time/datetime/constants.odin index 003d4fca4..e24709e49 100644 --- a/core/time/datetime/constants.odin +++ b/core/time/datetime/constants.odin @@ -85,9 +85,9 @@ TZ_Record :: struct { } TZ_Date_Kind :: enum { - NoLeap, + No_Leap, Leap, - MonthWeekDay, + Month_Week_Day, } TZ_Transition_Date :: struct { diff --git a/core/time/timezone/tz_unix.odin b/core/time/timezone/tz_unix.odin index 9fe8ff92c..b3ab0d4cc 100644 --- a/core/time/timezone/tz_unix.odin +++ b/core/time/timezone/tz_unix.odin @@ -11,7 +11,7 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: local_str, ok := os.lookup_env("TZ", allocator) if !ok { orig_localtime_path := "/etc/localtime" - path, err := os.absolute_path_from_relative(orig_localtime_path) + path, err := os.absolute_path_from_relative(orig_localtime_path, allocator) if err != nil { // If we can't find /etc/localtime, fallback to UTC if err == .ENOENT { @@ -22,11 +22,11 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: return } - defer delete(path) + defer delete(path, allocator) // FreeBSD makes me sad. if path == orig_localtime_path { - data := os.read_entire_file("/var/db/zoneinfo") or_return + data := os.read_entire_file("/var/db/zoneinfo", allocator) or_return return strings.trim_right_space(string(data)), true } @@ -52,6 +52,8 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: } if local_str == "" { + delete(local_str) + str, err := strings.clone("UTC", allocator) if err != nil { return } return str, true diff --git a/core/time/timezone/tzdate.odin b/core/time/timezone/tzdate.odin index 672ebbba5..c96f8aab3 100644 --- a/core/time/timezone/tzdate.odin +++ b/core/time/timezone/tzdate.odin @@ -38,6 +38,7 @@ region_destroy :: proc(region: ^datetime.TZ_Region, allocator := context.allocat } +@private region_get_nearest :: proc(region: ^datetime.TZ_Region, tm: time.Time) -> (out: datetime.TZ_Record, success: bool) { if len(region.records) == 0 { return process_rrule(region.rrule, tm) @@ -86,7 +87,7 @@ trans_date_to_seconds :: proc(year: i64, td: datetime.TZ_Transition_Date) -> (se ONE_DAY :: 86_400 #partial switch td.type { - case .MonthWeekDay: + case .Month_Week_Day: year_start := datetime.DateTime{{year, 1, 1}, {0, 0, 0, 0}, nil} year_start_time := time.datetime_to_time(year_start) or_return @@ -115,7 +116,8 @@ trans_date_to_seconds :: proc(year: i64, td: datetime.TZ_Transition_Date) -> (se return } - + +@private process_rrule :: proc(rrule: datetime.TZ_RRule, tm: time.Time) -> (out: datetime.TZ_Record, success: bool) { if !rrule.has_dst { return datetime.TZ_Record{ diff --git a/core/time/timezone/tzif.odin b/core/time/timezone/tzif.odin index dce54a4e7..609cbda73 100644 --- a/core/time/timezone/tzif.odin +++ b/core/time/timezone/tzif.odin @@ -282,7 +282,7 @@ parse_posix_rrule :: proc(str: string) -> (out: datetime.TZ_Transition_Date, idx } return datetime.TZ_Transition_Date{ - type = .NoLeap, + type = .No_Leap, day = u16(day), time = offset, }, i, true @@ -350,7 +350,7 @@ parse_posix_rrule :: proc(str: string) -> (out: datetime.TZ_Transition_Date, idx } return datetime.TZ_Transition_Date{ - type = .MonthWeekDay, + type = .Month_Week_Day, month = u8(month), week = u8(week), day = u16(day), |