mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +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
|
@ -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…
Add table
Add a link
Reference in a new issue