From: "nobu (Nobuyoshi Nakada)" Date: 2022-11-02T06:03:59+00:00 Subject: [ruby-core:110579] [Ruby master Misc#19098] Time#strftime: %z and width Issue #19098 has been updated by nobu (Nobuyoshi Nakada). ```c #include #include void test_strftime(const char *fmt, const struct tm *t) { char buf[1024]; int n = strftime(buf, sizeof(buf), fmt, t); printf("%-10s=>\t[%s]\n", fmt, buf); } int main(void) { time_t t = time(NULL); struct tm *tm = localtime(&t); test_strftime("%z", tm); test_strftime("%_z", tm); test_strftime("%10z", tm); test_strftime("%10::z", tm); test_strftime("%_10z", tm); test_strftime("%_10::z", tm); return 0; } ``` This program shows Ubuntu 22.04: ``` %z => [+0900] %_z => [+ 900] %10z => [ +0000000900] %10::z => [ %10::z] %_10z => [ + 900] %_10::z => [ %_10::z] ``` macOS Monterey: ``` %z => [+0900] %_z => [+ 900] %10z => [10z] %10::z => [10::z] %_10z => [10z] %_10::z => [10::z] ``` `%z` with width seems not standardized. ---------------------------------------- Misc #19098: Time#strftime: %z and width https://bugs.ruby-lang.org/issues/19098#change-99912 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal ---------------------------------------- It seems `%z` behaves in some surprising way when it is combined with a width - sign `+` is placed at the beginning of the result string: ```ruby Time.now.strftime("%10z") => "+000000200" Time.now.strftime("%_10z") => " +200" ``` It seems a time zone offset is treated as a number. It probably makes sense with default format but it looks strange with `:` separators: ```ruby Time.now.strftime("%10::z") # => "+002:00:00" ``` So I would expect that `%z` directive output to be treated as a non-numerical and padded by default with spaces. -- https://bugs.ruby-lang.org/ Unsubscribe: