mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibCore: Output invalid DateTime::to_string() specifiers as literals
While working on #13764 I noticed that DateTime::to_string() would just return an empty String if the format included an invalid specifier (eg `%Q`). This seems to be a mistake. POSIX date(1), which I believe we are basing our implementation on, only replaces valid specifiers, and any invalid ones get included as literals in the output. For example, on Linux `date "+%Quiz"` returns "%Quiz", but we were returning "".
This commit is contained in:
parent
5e4d5a436e
commit
4d2e18fb07
1 changed files with 12 additions and 6 deletions
|
@ -239,11 +239,15 @@ String DateTime::to_string(StringView format) const
|
||||||
format_time_zone_offset(false);
|
format_time_zone_offset(false);
|
||||||
break;
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
if (++i == format_len)
|
if (++i == format_len) {
|
||||||
return String::empty();
|
builder.append("%:");
|
||||||
if (format[i] != 'z')
|
break;
|
||||||
return String::empty();
|
}
|
||||||
|
if (format[i] != 'z') {
|
||||||
|
builder.append("%:");
|
||||||
|
builder.append(format[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
format_time_zone_offset(true);
|
format_time_zone_offset(true);
|
||||||
break;
|
break;
|
||||||
case 'Z':
|
case 'Z':
|
||||||
|
@ -253,7 +257,9 @@ String DateTime::to_string(StringView format) const
|
||||||
builder.append('%');
|
builder.append('%');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return String();
|
builder.append('%');
|
||||||
|
builder.append(format[i]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue