mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibC+LibCore: Properly format 12-hour formatted hours
This fixes a small formatting issue where midnight and noon would display as 00 when they should display as 12.
This commit is contained in:
parent
31ca48ebb2
commit
0500d49acb
Notes:
sideshowbarker
2024-07-18 05:37:06 +09:00
Author: https://github.com/cflip Commit: https://github.com/SerenityOS/serenity/commit/0500d49acb Pull-request: https://github.com/SerenityOS/serenity/pull/13647 Reviewed-by: https://github.com/trflynn89
2 changed files with 24 additions and 8 deletions
|
@ -250,9 +250,13 @@ size_t strftime(char* destination, size_t max_size, char const* format, const st
|
|||
case 'H':
|
||||
builder.appendff("{:02}", tm->tm_hour);
|
||||
break;
|
||||
case 'I':
|
||||
builder.appendff("{:02}", tm->tm_hour % 12);
|
||||
case 'I': {
|
||||
int display_hour = tm->tm_hour % 12;
|
||||
if (display_hour == 0)
|
||||
display_hour = 12;
|
||||
builder.appendff("{:02}", display_hour);
|
||||
break;
|
||||
}
|
||||
case 'j':
|
||||
builder.appendff("{:03}", tm->tm_yday + 1);
|
||||
break;
|
||||
|
@ -268,9 +272,13 @@ size_t strftime(char* destination, size_t max_size, char const* format, const st
|
|||
case 'p':
|
||||
builder.append(tm->tm_hour < 12 ? "a.m." : "p.m.");
|
||||
break;
|
||||
case 'r':
|
||||
builder.appendff("{:02}:{:02}:{:02} {}", tm->tm_hour % 12, tm->tm_min, tm->tm_sec, tm->tm_hour < 12 ? "a.m." : "p.m.");
|
||||
case 'r': {
|
||||
int display_hour = tm->tm_hour % 12;
|
||||
if (display_hour == 0)
|
||||
display_hour = 12;
|
||||
builder.appendff("{:02}:{:02}:{:02} {}", display_hour, tm->tm_min, tm->tm_sec, tm->tm_hour < 12 ? "a.m." : "p.m.");
|
||||
break;
|
||||
}
|
||||
case 'R':
|
||||
builder.appendff("{:02}:{:02}", tm->tm_hour, tm->tm_min);
|
||||
break;
|
||||
|
|
|
@ -153,9 +153,13 @@ String DateTime::to_string(StringView format) const
|
|||
case 'H':
|
||||
builder.appendff("{:02}", tm.tm_hour);
|
||||
break;
|
||||
case 'I':
|
||||
builder.appendff("{:02}", tm.tm_hour % 12);
|
||||
case 'I': {
|
||||
int display_hour = tm.tm_hour % 12;
|
||||
if (display_hour == 0)
|
||||
display_hour = 12;
|
||||
builder.appendff("{:02}", display_hour);
|
||||
break;
|
||||
}
|
||||
case 'j':
|
||||
builder.appendff("{:03}", tm.tm_yday + 1);
|
||||
break;
|
||||
|
@ -171,9 +175,13 @@ String DateTime::to_string(StringView format) const
|
|||
case 'p':
|
||||
builder.append(tm.tm_hour < 12 ? "a.m." : "p.m.");
|
||||
break;
|
||||
case 'r':
|
||||
builder.appendff("{:02}:{:02}:{:02} {}", tm.tm_hour % 12, tm.tm_min, tm.tm_sec, tm.tm_hour < 12 ? "a.m." : "p.m.");
|
||||
case 'r': {
|
||||
int display_hour = tm.tm_hour % 12;
|
||||
if (display_hour == 0)
|
||||
display_hour = 12;
|
||||
builder.appendff("{:02}:{:02}:{:02} {}", display_hour, tm.tm_min, tm.tm_sec, tm.tm_hour < 12 ? "a.m." : "p.m.");
|
||||
break;
|
||||
}
|
||||
case 'R':
|
||||
builder.appendff("{:02}:{:02}", tm.tm_hour, tm.tm_min);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue