ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:110574] [Ruby master Bug#19098] Time#strftime: %z and width
@ 2022-11-01 17:49 andrykonchin (Andrew Konchin)
  2022-11-02  6:03 ` [ruby-core:110579] [Ruby master Misc#19098] " nobu (Nobuyoshi Nakada)
  2022-11-15 15:43 ` [ruby-core:110769] " andrykonchin (Andrew Konchin)
  0 siblings, 2 replies; 3+ messages in thread
From: andrykonchin (Andrew Konchin) @ 2022-11-01 17:49 UTC (permalink / raw)
  To: ruby-core

Issue #19098 has been reported by andrykonchin (Andrew Konchin).

----------------------------------------
Bug #19098: Time#strftime: %z and width
https://bugs.ruby-lang.org/issues/19098

* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2p20
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
It seems `%z` behaves in some surprising way when it is combined with width - sign `+` is placed at the beginning of the result string:

```ruby
Time.now.strftime("%10z")
=> "+000000200"

Time.now.strftime("%_10z")
=> "      +200"
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:110579] [Ruby master Misc#19098] Time#strftime: %z and width
  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)
  2022-11-15 15:43 ` [ruby-core:110769] " andrykonchin (Andrew Konchin)
  1 sibling, 0 replies; 3+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2022-11-02  6:03 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:110769] [Ruby master Misc#19098] Time#strftime: %z and width
  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 ` [ruby-core:110579] [Ruby master Misc#19098] " nobu (Nobuyoshi Nakada)
@ 2022-11-15 15:43 ` andrykonchin (Andrew Konchin)
  1 sibling, 0 replies; 3+ messages in thread
From: andrykonchin (Andrew Konchin) @ 2022-11-15 15:43 UTC (permalink / raw)
  To: ruby-core

Issue #19098 has been updated by andrykonchin (Andrew Konchin).


I have checked on MacOS Monterey and Debian 11 (bullseye) (in Docker, if it matters) and received the same results like mentioned in the description.

----------------------------------------
Misc #19098: Time#strftime: %z and width
https://bugs.ruby-lang.org/issues/19098#change-100112

* 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-15 15:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:110579] [Ruby master Misc#19098] " nobu (Nobuyoshi Nakada)
2022-11-15 15:43 ` [ruby-core:110769] " andrykonchin (Andrew Konchin)

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).