aboutsummaryrefslogtreecommitdiff
path: root/core/time
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-02-11 17:53:16 +0000
committerGitHub <noreply@github.com>2026-02-11 17:53:16 +0000
commit355b8a8c83badc64d23dbb34ea00bb89ac9245db (patch)
tree1103d5bde2dd10c28a81f2104d9c17fa0f4c3166 /core/time
parentb5bf28dc47dd1c32a45ba0bbedcbcef80409b798 (diff)
parent1a37f4eb0cc792783784fca216c79e3f02a3234e (diff)
Merge pull request #6245 from odin-lang/new_os
`core:os/os2` -> `core:os` integration
Diffstat (limited to 'core/time')
-rw-r--r--core/time/timezone/tz_os.odin19
-rw-r--r--core/time/timezone/tz_unix.odin30
-rw-r--r--core/time/timezone/tzdate.odin4
-rw-r--r--core/time/timezone/tzif.odin19
4 files changed, 42 insertions, 30 deletions
diff --git a/core/time/timezone/tz_os.odin b/core/time/timezone/tz_os.odin
new file mode 100644
index 000000000..fae4980c3
--- /dev/null
+++ b/core/time/timezone/tz_os.odin
@@ -0,0 +1,19 @@
+#+build !freestanding
+#+build !js
+package timezone
+
+import "core:os"
+import "core:time/datetime"
+
+load_tzif_file :: proc(filename: string, region_name: string, allocator := context.allocator) -> (out: ^datetime.TZ_Region, ok: bool) {
+ 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)
+}
+
+region_load_from_file :: proc(file_path, reg: string, allocator := context.allocator) -> (out_reg: ^datetime.TZ_Region, ok: bool) {
+ return load_tzif_file(file_path, reg, allocator)
+} \ No newline at end of file
diff --git a/core/time/timezone/tz_unix.odin b/core/time/timezone/tz_unix.odin
index 542e5c4f2..3939b3265 100644
--- a/core/time/timezone/tz_unix.odin
+++ b/core/time/timezone/tz_unix.odin
@@ -4,17 +4,17 @@ package timezone
import "core:os"
import "core:strings"
-import "core:path/filepath"
import "core:time/datetime"
+import "core:path/filepath"
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 {
+ if err == .Not_Exist {
str, err2 := strings.clone("UTC", allocator)
if err2 != nil { return }
return str, true
@@ -28,16 +28,20 @@ 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
}
// Looking for tz path (ex fmt: "UTC", "Etc/UTC" or "America/Los_Angeles")
- path_dir, path_file := filepath.split(path)
+ path_dir, path_file := os.split_path(path)
+
if path_dir == "" {
return
}
- upper_path_dir, upper_path_chunk := filepath.split(path_dir[:len(path_dir)-1])
+ upper_path_dir, upper_path_chunk := os.split_path(path_dir[:len(path_dir)])
if upper_path_dir == "" {
return
}
@@ -47,8 +51,8 @@ local_tz_name :: proc(allocator := context.allocator) -> (name: string, success:
if err != nil { return }
return region_str, true
} else {
- region_str, err := filepath.join({upper_path_chunk, path_file}, allocator = allocator)
- if err != nil { return }
+ region_str, region_str_err := os.join_path({upper_path_chunk, path_file}, allocator = allocator)
+ if region_str_err != nil { return }
return region_str, true
}
}
@@ -85,9 +89,10 @@ _region_load :: proc(_reg_str: string, allocator := context.allocator) -> (out_r
defer if tzdir_ok { delete(tzdir_str, allocator) }
if tzdir_ok {
- region_path := filepath.join({tzdir_str, reg_str}, allocator)
+ region_path, err := filepath.join({tzdir_str, reg_str}, allocator)
+ if err != nil { return nil, false }
defer delete(region_path, allocator)
-
+
if tz_reg, ok := load_tzif_file(region_path, reg_str, allocator); ok {
return tz_reg, true
}
@@ -95,7 +100,8 @@ _region_load :: proc(_reg_str: string, allocator := context.allocator) -> (out_r
db_paths := []string{"/usr/share/zoneinfo", "/share/zoneinfo", "/etc/zoneinfo"}
for db_path in db_paths {
- region_path := filepath.join({db_path, reg_str}, allocator)
+ region_path, err := filepath.join({db_path, reg_str}, allocator)
+ if err != nil { return nil, false}
defer delete(region_path, allocator)
if tz_reg, ok := load_tzif_file(region_path, reg_str, allocator); ok {
@@ -104,4 +110,4 @@ _region_load :: proc(_reg_str: string, allocator := context.allocator) -> (out_r
}
return nil, false
-}
+} \ No newline at end of file
diff --git a/core/time/timezone/tzdate.odin b/core/time/timezone/tzdate.odin
index f01553573..29e8ad25c 100644
--- a/core/time/timezone/tzdate.odin
+++ b/core/time/timezone/tzdate.odin
@@ -10,10 +10,6 @@ region_load :: proc(reg: string, allocator := context.allocator) -> (out_reg: ^
return _region_load(reg, allocator)
}
-region_load_from_file :: proc(file_path, reg: string, allocator := context.allocator) -> (out_reg: ^datetime.TZ_Region, ok: bool) {
- return load_tzif_file(file_path, reg, allocator)
-}
-
region_load_from_buffer :: proc(buffer: []u8, reg: string, allocator := context.allocator) -> (out_reg: ^datetime.TZ_Region, ok: bool) {
return parse_tzif(buffer, reg, allocator)
}
diff --git a/core/time/timezone/tzif.odin b/core/time/timezone/tzif.odin
index 804211ef4..3b92364ac 100644
--- a/core/time/timezone/tzif.odin
+++ b/core/time/timezone/tzif.odin
@@ -1,12 +1,10 @@
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 "core:strconv"
+import "core:time/datetime"
// Implementing RFC8536 [https://datatracker.ietf.org/doc/html/rfc8536]
@@ -68,13 +66,6 @@ tzif_data_block_size :: proc(hdr: ^TZif_Header, version: TZif_Version) -> (block
int(hdr.isutcnt), true
}
-
-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
- defer delete(tzif_data, allocator)
- return parse_tzif(tzif_data, region_name, allocator)
-}
-
@private
is_alphabetic :: proc(ch: u8) -> bool {
// ('A' -> 'Z') || ('a' -> 'z')