From: "nobu (Nobuyoshi Nakada)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110579] [Ruby master Misc#19098] Time#strftime: %z and width
Date: Wed, 02 Nov 2022 06:03:59 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-99912.20221102060358.13553@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19098.20221101174920.13553@ruby-lang.org
Issue #19098 has been updated by nobu (Nobuyoshi Nakada).
```c
#include <stdio.h>
#include <time.h>
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/
next prev parent reply other threads:[~2022-11-02 6:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 17:49 [ruby-core:110574] [Ruby master Bug#19098] Time#strftime: %z and width andrykonchin (Andrew Konchin)
2022-11-02 6:03 ` nobu (Nobuyoshi Nakada) [this message]
2022-11-15 15:43 ` [ruby-core:110769] [Ruby master Misc#19098] " andrykonchin (Andrew Konchin)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-99912.20221102060358.13553@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=ruby-core@neon.ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).