From f7efbba32d57aeacbd2362239d9875ddcfdfd9fa Mon Sep 17 00:00:00 2001 From: Kyle Lanmon Date: Sun, 28 Jan 2024 23:27:35 -0600 Subject: [PATCH] LibCore: Add parser for time offset without a sign There is already a parser for the time offset but it requires a positive or negative sign. There are some weird formats on the web that do not have the sign, so let's support that. I chose to implement this as a new option instead of editing the old one to avoid any unknown breaking changes. --- Userland/Libraries/LibCore/DateTime.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/Libraries/LibCore/DateTime.cpp b/Userland/Libraries/LibCore/DateTime.cpp index 004251d31a..3cca850bb2 100644 --- a/Userland/Libraries/LibCore/DateTime.cpp +++ b/Userland/Libraries/LibCore/DateTime.cpp @@ -515,6 +515,21 @@ Optional DateTime::parse(StringView format, StringView string) tm.tm_min += sign * minutes; break; } + case 'x': { + tm_represents_utc_time = true; + auto hours = parse_number(); + int minutes; + if (string_lexer.consume_specific(':')) { + minutes = parse_number(); + } else { + minutes = hours % 100; + hours = hours / 100; + } + + tm.tm_hour -= hours; + tm.tm_min -= minutes; + break; + } case 'Z': parsed_time_zone = parse_time_zone_name(string_lexer); if (!parsed_time_zone.has_value())