mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibCore: Support wildcard-skipping characters in Core::DateTime::parse
For example, LibJS will need to parse date strings of the form: Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time) This string contains both the time zone offset (-05:00) and a display name for the time zone (Eastern Standard Time). Because we will already handle time zone adjustments when we handle the offsets, we will want to just skip the time zone name. This patch will let us use a format string of the form "GMT%z (%+)" to do so.
This commit is contained in:
parent
350fdf1e43
commit
ee7ab5d053
2 changed files with 41 additions and 0 deletions
|
@ -512,6 +512,24 @@ Optional<DateTime> DateTime::parse(StringView format, StringView string)
|
|||
|
||||
tm_represents_utc_time = true;
|
||||
break;
|
||||
case '+': {
|
||||
Optional<char> next_format_character;
|
||||
|
||||
if (format_pos + 1 < format.length()) {
|
||||
next_format_character = format[format_pos + 1];
|
||||
|
||||
// Disallow another formatter directly after %+. This is to avoid ambiguity when parsing a string like
|
||||
// "ignoreJan" with "%+%b", as it would be non-trivial to know that where the %b field begins.
|
||||
if (next_format_character == '%')
|
||||
return {};
|
||||
}
|
||||
|
||||
auto discarded = string_lexer.consume_until([&](auto ch) { return ch == next_format_character; });
|
||||
if (discarded.is_empty())
|
||||
return {};
|
||||
|
||||
break;
|
||||
}
|
||||
case '%':
|
||||
consume('%');
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue