core:time/timezone -> os2

This commit is contained in:
Jeroen van Rijn
2025-10-30 13:45:59 +01:00
parent 67db0fde4f
commit c265d297b5
2 changed files with 19 additions and 14 deletions

View File

@@ -2,16 +2,16 @@
#+private
package timezone
import "core:os"
import "core:strings"
import "core:path/filepath"
import "core:time/datetime"
import os "core:os/os2"
import "core:strings"
import "core:path/filepath"
import "core:time/datetime"
local_tz_name :: proc(allocator := context.allocator) -> (name: string, success: bool) {
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, allocator)
path, err := os.get_absolute_path(orig_localtime_path, allocator)
if err != nil {
// If we can't find /etc/localtime, fallback to UTC
if err == .ENOENT {
@@ -28,7 +28,10 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success:
// This is a hackaround, because FreeBSD copies rather than softlinks their local timezone file,
// *sometimes* and then stores the original name of the timezone in /var/db/zoneinfo instead
if path == orig_localtime_path {
data := os.read_entire_file("/var/db/zoneinfo", allocator) or_return
data, data_err := os.read_entire_file("/var/db/zoneinfo", allocator)
if data_err != nil {
return "", false
}
return strings.trim_right_space(string(data)), true
}

View File

@@ -1,12 +1,11 @@
package timezone
import "base:intrinsics"
import "core:slice"
import "core:strings"
import "core:os"
import "core:strconv"
import "core:time/datetime"
import "base:intrinsics"
import "core:slice"
import "core:strings"
import os "core:os/os2"
import "core:strconv"
import "core:time/datetime"
// Implementing RFC8536 [https://datatracker.ietf.org/doc/html/rfc8536]
@@ -70,7 +69,10 @@ tzif_data_block_size :: proc(hdr: ^TZif_Header, version: TZif_Version) -> (block
load_tzif_file :: proc(filename: string, region_name: string, allocator := context.allocator) -> (out: ^datetime.TZ_Region, ok: bool) {
tzif_data := os.read_entire_file_from_filename(filename, allocator) or_return
tzif_data, tzif_err := os.read_entire_file(filename, allocator)
if tzif_err != nil {
return nil, false
}
defer delete(tzif_data, allocator)
return parse_tzif(tzif_data, region_name, allocator)
}