Add %x support to strftime

This commit is contained in:
Wildan M
2026-05-21 06:52:01 +07:00
parent e3514fa329
commit 90676dcf04
2 changed files with 12 additions and 0 deletions
+6
View File
@@ -230,6 +230,12 @@ pub unsafe fn strftime<W: WriteByte>(w: &mut W, format: *const c_char, t: *const
(unsafe { (*t).tm_yday } + 7 - (unsafe { (*t).tm_wday } + 6) % 7) / 7
),
// US format date: %m/%d/%y.
b'x' => w!(recurse "%m/%d/%y"),
// US format time: %H:%M:%S
b'X' => w!(recurse "%T"),
// Last two digits of year: %y
b'y' => w!("{:02}", unsafe { (*t).tm_year } % 100),
+6
View File
@@ -105,6 +105,12 @@ void strftime_mix(void) {
strftime(buf, BUFS, "%T", &t);
assert(strcmp(buf, "23:59:59") == 0);
strftime(buf, BUFS, "%x", &t);
assert(strcmp(buf, "12/31/20") == 0);
strftime(buf, BUFS, "%X", &t);
assert(strcmp(buf, "23:59:59") == 0);
}
void test_v(void) {