From ff94ca9e426374ec701a1c78e36e9e26c2f4c321 Mon Sep 17 00:00:00 2001 From: Vitalii Kravchenko Date: Fri, 24 May 2024 17:37:57 +0100 Subject: [PATCH] Allow space (in addition to T and t) as RFC 3339 date/time separator. --- core/time/rfc3339.odin | 12 ++++++------ tests/core/time/test_core_time.odin | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/time/rfc3339.odin b/core/time/rfc3339.odin index 30c255c79..a4d03789d 100644 --- a/core/time/rfc3339.odin +++ b/core/time/rfc3339.odin @@ -57,12 +57,12 @@ _rfc3339_to_components :: proc(rfc_datetime: string) -> (res: dt.DateTime, utc_o (len(rfc_datetime) >= 20) or_return // 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 + 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 diff --git a/tests/core/time/test_core_time.odin b/tests/core/time/test_core_time.odin index 2cea47680..7161cf349 100644 --- a/tests/core/time/test_core_time.odin +++ b/tests/core/time/test_core_time.odin @@ -92,6 +92,8 @@ RFC3339_Test :: struct{ rfc3339_tests :: []RFC3339_Test{ // This represents 20 minutes and 50.52 seconds after the 23rd hour of April 12th, 1985 in UTC. {"1985-04-12T23:20:50.52Z", {482196050520000000}, true, 0, 23, false}, + {"1985-04-12t23:20:50.52Z", {482196050520000000}, true, 0, 23, false}, + {"1985-04-12 23:20:50.52Z", {482196050520000000}, true, 0, 23, false}, // This represents 39 minutes and 57 seconds after the 16th hour of December 19th, 1996 with an offset of -08:00 from UTC (Pacific Standard Time). // Note that this is equivalent to 1996-12-20T00:39:57Z in UTC.