mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:57:35 +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
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue