From 90676dcf049fb22d6abae0b3917c51b898971dca Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 21 May 2026 06:52:01 +0700 Subject: [PATCH] Add %x support to strftime --- src/header/time/strftime.rs | 6 ++++++ tests/time/strftime.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/header/time/strftime.rs b/src/header/time/strftime.rs index 49ab8e48fc..5c2ef5f432 100644 --- a/src/header/time/strftime.rs +++ b/src/header/time/strftime.rs @@ -230,6 +230,12 @@ pub unsafe fn strftime(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), diff --git a/tests/time/strftime.c b/tests/time/strftime.c index 629f86f838..fecdff8458 100644 --- a/tests/time/strftime.c +++ b/tests/time/strftime.c @@ -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) {