Initial cut of timezones

This commit is contained in:
Colin Davidson
2024-12-01 11:54:50 +11:00
committed by flysand7
parent b7e61095a9
commit fc9983e9c8
9 changed files with 1627 additions and 6 deletions
+44 -1
View File
@@ -77,12 +77,55 @@ Time :: struct {
nano: i32,
}
TZ_Record :: struct {
time: i64,
utc_offset: i64,
shortname: string,
dst: bool,
}
TZ_Date_Kind :: enum {
NoLeap,
Leap,
MonthWeekDay,
}
TZ_Transition_Date :: struct {
type: TZ_Date_Kind,
month: u8,
week: u8,
day: u16,
time: i64,
}
TZ_RRule :: struct {
has_dst: bool,
std_name: string,
std_offset: i64,
std_date: TZ_Transition_Date,
dst_name: string,
dst_offset: i64,
dst_date: TZ_Transition_Date,
}
TZ_Region :: struct {
name: string,
records: []TZ_Record,
shortnames: []string,
rrule: TZ_RRule,
}
/*
A type representing datetime.
*/
DateTime :: struct {
using date: Date,
using time: Time,
tz: ^TZ_Region,
}
/*
@@ -130,4 +173,4 @@ Weekday :: enum i8 {
}
@(private)
MONTH_DAYS :: [?]i8{-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
MONTH_DAYS :: [?]i8{-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
+3 -3
View File
@@ -76,7 +76,7 @@ datetime, an error is returned.
components_to_datetime :: proc "contextless" (#any_int year, #any_int month, #any_int day, #any_int hour, #any_int minute, #any_int second: i64, #any_int nanos := i64(0)) -> (datetime: DateTime, err: Error) {
date := components_to_date(year, month, day) or_return
time := components_to_time(hour, minute, second, nanos) or_return
return {date, time}, .None
return {date, time, nil}, .None
}
/*
@@ -88,7 +88,7 @@ object will always have the time equal to `00:00:00.000`.
*/
ordinal_to_datetime :: proc "contextless" (ordinal: Ordinal) -> (datetime: DateTime, err: Error) {
d := ordinal_to_date(ordinal) or_return
return {Date(d), {}}, .None
return {Date(d), {}, nil}, .None
}
/*
@@ -433,4 +433,4 @@ unsafe_ordinal_to_date :: proc "contextless" (ordinal: Ordinal) -> (date: Date)
day := i8(ordinal - unsafe_date_to_ordinal(Date{year, month, 1}) + 1)
return {year, month, day}
}
}