summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-04-12 17:53:04 -0600
committerTim Flynn <trflynn89@pm.me>2022-04-15 08:24:20 -0400
commit0500d49acb132f57a4bb4e5a8e7b86e9c7d61710 (patch)
tree6035f23af90202c195e5d2a0ccdc57346dd58294 /Userland/Libraries/LibC
parent31ca48ebb29e3cfe6937e575cadfba96b9c3fd09 (diff)
downloadserenity-0500d49acb132f57a4bb4e5a8e7b86e9c7d61710.zip
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.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/time.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp
index c28351c97a..a2a7b4eee8 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -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;