mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Change Ordinal from int to i64
This commit is contained in:
+28
-28
@@ -22,17 +22,13 @@ rfc3339_to_time_utc :: proc(rfc_datetime: string, is_leap: ^bool = nil) -> (res:
|
||||
// Optional pointer to boolean `is_leap` will return `true` if the moment was a leap second.
|
||||
// Leap seconds are smeared into 23:59:59.
|
||||
rfc3339_to_time_and_offset :: proc(rfc_datetime: string, is_leap: ^bool = nil) -> (res: Time, utc_offset: int, consumed: int) {
|
||||
moment, offset, count := rfc3339_to_components(rfc_datetime)
|
||||
moment, offset, leap_second, count := rfc3339_to_components(rfc_datetime)
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Leap second handling
|
||||
if moment.minute == 59 && moment.second == 60 {
|
||||
moment.second = 59
|
||||
if is_leap != nil {
|
||||
is_leap^ = true
|
||||
}
|
||||
if is_leap != nil {
|
||||
is_leap^ = leap_second
|
||||
}
|
||||
|
||||
if _res, ok := datetime_to_time(moment.year, moment.month, moment.day, moment.hour, moment.minute, moment.second, moment.nano); !ok {
|
||||
@@ -45,40 +41,48 @@ rfc3339_to_time_and_offset :: proc(rfc_datetime: string, is_leap: ^bool = nil) -
|
||||
// Parses an RFC 3339 string and returns Time and a UTC offset in minutes.
|
||||
// e.g. 1985-04-12T23:20:50.52Z
|
||||
// Performs no validation on whether components are valid, e.g. it'll return hour = 25 if that's what it's given
|
||||
rfc3339_to_components :: proc(rfc_datetime: string) -> (res: dt.DateTime, utc_offset: int, consumed: int) {
|
||||
count: int
|
||||
moment, offset, ok := _rfc3339_to_components(rfc_datetime, &count)
|
||||
rfc3339_to_components :: proc(rfc_datetime: string) -> (res: dt.DateTime, utc_offset: int, is_leap: bool, consumed: int) {
|
||||
moment, offset, count, leap_second, ok := _rfc3339_to_components(rfc_datetime)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
return moment, offset, count
|
||||
return moment, offset, leap_second, count
|
||||
}
|
||||
|
||||
// Parses an RFC 3339 string and returns datetime.DateTime.
|
||||
// Performs no validation on whether components are valid, e.g. it'll return hour = 25 if that's what it's given
|
||||
@(private)
|
||||
_rfc3339_to_components :: proc(rfc_datetime: string, consume_count: ^int = nil) -> (res: dt.DateTime, utc_offset: int, ok: bool) {
|
||||
_rfc3339_to_components :: proc(rfc_datetime: string) -> (res: dt.DateTime, utc_offset: int, consumed: int, is_leap: bool, ok: bool) {
|
||||
// A compliant date is at minimum 20 characters long, e.g. YYYY-MM-DDThh:mm:ssZ
|
||||
(len(rfc_datetime) >= 20) or_return
|
||||
|
||||
// Scan and eat YYYY-MM-DD[Tt]
|
||||
res.year = scan_digits(rfc_datetime[0:], "-", 4) or_return
|
||||
res.month = scan_digits(rfc_datetime[5:], "-", 2) or_return
|
||||
res.day = scan_digits(rfc_datetime[8:], "Tt", 2) or_return
|
||||
|
||||
// Scan and eat HH:MM:SS, leave separator
|
||||
res.hour = scan_digits(rfc_datetime[11:], ":", 2) or_return
|
||||
res.minute = scan_digits(rfc_datetime[14:], ":", 2) or_return
|
||||
res.second = scan_digits(rfc_datetime[17:], "", 2) or_return
|
||||
count := 19
|
||||
// Scan and eat YYYY-MM-DD[Tt], then scan and eat HH:MM:SS, leave separator
|
||||
year := scan_digits(rfc_datetime[0:], "-", 4) or_return
|
||||
month := scan_digits(rfc_datetime[5:], "-", 2) or_return
|
||||
day := scan_digits(rfc_datetime[8:], "Tt", 2) or_return
|
||||
hour := scan_digits(rfc_datetime[11:], ":", 2) or_return
|
||||
minute := scan_digits(rfc_datetime[14:], ":", 2) or_return
|
||||
second := scan_digits(rfc_datetime[17:], "", 2) or_return
|
||||
nanos := 0
|
||||
count := 19
|
||||
|
||||
if rfc_datetime[count] == '.' {
|
||||
// Scan hundredths. The string must be at least 4 bytes long (.hhZ)
|
||||
(len(rfc_datetime[count:]) >= 4) or_return
|
||||
hundredths := scan_digits(rfc_datetime[count+1:], "", 2) or_return
|
||||
count += 3
|
||||
nanos = 10_000_000 * hundredths
|
||||
}
|
||||
|
||||
res.nano = 10_000_000 * hundredths
|
||||
// Leap second handling
|
||||
if minute == 59 && second == 60 {
|
||||
second = 59
|
||||
is_leap = true
|
||||
}
|
||||
|
||||
err: dt.Error
|
||||
if res, err = dt.components_to_datetime(year, month, day, hour, minute, second, nanos); err != .None {
|
||||
return {}, 0, 0, false, false
|
||||
}
|
||||
|
||||
// Scan UTC offset
|
||||
@@ -95,11 +99,7 @@ _rfc3339_to_components :: proc(rfc_datetime: string, consume_count: ^int = nil)
|
||||
utc_offset *= -1 if rfc_datetime[count] == '-' else 1
|
||||
count += 6
|
||||
}
|
||||
|
||||
if consume_count != nil {
|
||||
consume_count^ = count
|
||||
}
|
||||
return res, utc_offset, true
|
||||
return res, utc_offset, count, is_leap, true
|
||||
}
|
||||
|
||||
@(private)
|
||||
|
||||
Reference in New Issue
Block a user