Created
October 8, 2024 04:10
-
-
Save colrdavidson/e42c326435f0e739d274dee6a2f4e1e6 to your computer and use it in GitHub Desktop.
tztest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "core:fmt" | |
| import "core:time" | |
| import "core:time/datetime" | |
| import "core:time/timezone" | |
| check_tz :: proc(dt: datetime.DateTime, tz: ^datetime.TZ_Region) { | |
| tz_dt := timezone.datetime_to_tz(dt, tz) | |
| utc_dt := timezone.datetime_to_utc(tz_dt) | |
| fmt.printf("time in UTC: %v\n", timezone.datetime_to_str(dt)) | |
| fmt.printf("time in %v: %v\n", timezone.shortname(tz_dt), timezone.datetime_to_str(tz_dt)) | |
| fmt.printf("time in UTC: %v\n\n", timezone.datetime_to_str(utc_dt)) | |
| } | |
| main :: proc() { | |
| dst_dt, _ := datetime.components_to_datetime(2024, 10, 4, 23, 47, 0) | |
| std_dt, _ := datetime.components_to_datetime(2024, 11, 3, 23, 47, 0) | |
| local_tz, ok := timezone.region_load("local") | |
| if !ok { | |
| fmt.printf("Failed to load local tz!\n") | |
| return | |
| } | |
| defer timezone.region_destroy(local_tz) | |
| edm_tz, ok2 := timezone.region_load("America/Edmonton") | |
| if !ok2 { | |
| fmt.printf("Failed to load edm tz!\n") | |
| return | |
| } | |
| defer timezone.region_destroy(edm_tz) | |
| check_tz(dst_dt, local_tz) | |
| check_tz(std_dt, local_tz) | |
| check_tz(dst_dt, edm_tz) | |
| check_tz(std_dt, edm_tz) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment