core/time/timezone
timezone
Types
5Leapsecond_Record
Leapsecond_Record :: struct #packed {
occur: i64be,
corr: i32be,
}SourceLocal_Time_Type
Local_Time_Type :: struct #packed {
utoff: i32be,
dst: Sun_Shift,
idx: u8,
}SourceSun_Shift
Sun_Shift :: enum u8 {
Standard = 0,
DST = 1,
}SourceTZif_Header
TZif_Header :: struct #packed {
magic: u32be,
version: TZif_Version,
reserved: [15]u8,
isutcnt: u32be,
isstdcnt: u32be,
leapcnt: u32be,
timecnt: u32be,
typecnt: u32be,
charcnt: u32be,
}SourceTZif_Version
TZif_Version :: enum u8 {
V1 = 0,
V2 = '2',
V3 = '3',
V4 = '4',
}SourceConstants
3BIG_BANG_ISH
BIG_BANG_ISH :: -0x800000000000000SourceTWO_AM
TWO_AM :: 2 * 60 * 60SourceTZIF_MAGIC
TZIF_MAGIC :: u32be = u32be(0x545A6966)SourceImplementing RFC8536 [https://datatracker.ietf.org/doc/html/rfc8536]
Procedures
18_region_load
_region_load :: proc(_reg_str: string, allocator: mem.Allocator = context.allocator) -> (out_reg: ^datetime.TZ_Region, success: bool)Sourcedatetime_to_str
datetime_to_str :: proc(dt: datetime.DateTime, allocator: mem.Allocator = context.allocator) -> (string)Sourcedatetime_to_tz
datetime_to_tz :: proc(dt: datetime.DateTime, tz: ^datetime.TZ_Region) -> (out: datetime.DateTime, success: bool)SourceConverts a datetime on one timezone to another timezone
Inputs:
- dt: The input datetime
- tz: The timezone to convert to
NOTE: tz will be referenced in the result datetime, so it must stay alive/allocated as long as it is used Returns:
- out: The converted datetime
- success:
falseif the datetime was invalid
datetime_to_utc
datetime_to_utc :: proc(dt: datetime.DateTime) -> (out: datetime.DateTime, success: bool)Sourcedst
dst :: proc(dt: datetime.DateTime) -> (is_dst: bool, success: bool)SourceChecks DST for a given date.
Inputs:
- dt: The input datetime
Returns:
- is_dst: returns
trueif dt is in daylight savings time,falseif not - success: returns
falseif the passed datetime is invalid
dst_unsafe
dst_unsafe :: proc(dt: datetime.DateTime) -> (bool)SourceChecks DST for a given date.
WARNING: This is unsafe because it doesn't check if your datetime is valid or if your region contains a valid record.
Inputs:
- dt: The input datetime
Returns:
- is_dst: returns
trueif dt is in daylight savings time,falseif not
load_tzif_file
load_tzif_file :: proc(filename: string, region_name: string, allocator: mem.Allocator = context.allocator) -> (out: ^datetime.TZ_Region, ok: bool)Sourcelocal_tz_name
local_tz_name :: proc(allocator: mem.Allocator = context.allocator) -> (name: string, success: bool)Sourceparse_posix_rrule
parse_posix_rrule :: proc(str: string) -> (out: datetime.TZ_Transition_Date, idx: int, ok: bool)Sourceparse_posix_tz
parse_posix_tz :: proc(posix_tz: string, allocator: mem.Allocator = context.allocator) -> (out: datetime.TZ_RRule, ok: bool)Sourceparse_tzif
parse_tzif :: proc(_buffer: []u8, region_name: string, allocator: mem.Allocator = context.allocator) -> (out: ^datetime.TZ_Region, ok: bool)Sourceregion_destroy
region_destroy :: proc(region: ^datetime.TZ_Region, allocator: mem.Allocator = context.allocator)Sourceregion_load
region_load :: proc(reg: string, allocator: mem.Allocator = context.allocator) -> (out_reg: ^datetime.TZ_Region, ok: bool)Sourceregion_load_from_buffer
region_load_from_buffer :: proc(buffer: []u8, reg: string, allocator: mem.Allocator = context.allocator) -> (out_reg: ^datetime.TZ_Region, ok: bool)Sourceregion_load_from_file
region_load_from_file :: proc(file_path: string, reg: string, allocator: mem.Allocator = context.allocator) -> (out_reg: ^datetime.TZ_Region, ok: bool)Sourcerrule_destroy
rrule_destroy :: proc(rrule: datetime.TZ_RRule, allocator: mem.Allocator = context.allocator)Sourceshortname
shortname :: proc(dt: datetime.DateTime) -> (name: string, success: bool)SourceGets the timezone abbreviation/shortname for a given date. (ex: "PDT")
Inputs:
- dt: The datetime containing the date, time, and timezone pointer for the lookup
NOTE: The lifetime of name matches the timezone it was pulled from. Returns:
- name: The timezone abbreviation
- success: returns
falseif the passed datetime is invalid
shortname_unsafe
shortname_unsafe :: proc(dt: datetime.DateTime) -> (string)SourceGets the timezone abbreviation/shortname for a given date. (ex: "PDT")
WARNING: This is unsafe because it doesn't check if your datetime is valid or if your region contains a valid record.
Inputs:
- dt: The input datetime
NOTE: The lifetime of name matches the timezone it was pulled from. Returns:
- name: The timezone abbreviation