* [ruby-core:99265] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
@ 2020-07-22 14:08 mail
2020-07-22 17:56 ` [ruby-core:99272] " gamelinks007
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mail @ 2020-07-22 14:08 UTC (permalink / raw)
To: ruby-core
Issue #17042 has been reported by timcraft (Tim Craft).
----------------------------------------
Bug #17042: Times with timezones return incorrect week numbers
https://bugs.ruby-lang.org/issues/17042
* Author: timcraft (Tim Craft)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-07-15 master 79d06483a8)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Times with timezones return incorrect week numbers from strftime. For example:
$ irb -r tzinfo
irb(main):001:0> Time.utc(2020, 7, 22, 12, 0, 0).strftime('%U %V %W')
=> "29 30 29"
irb(main):002:0> Time.new(2020, 7, 22, 12, 0, 0, TZInfo::Timezone.get('America/New_York')).strftime('%U %V %W')
=> "00 00 00"
Follow up to #17024
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:99272] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
2020-07-22 14:08 [ruby-core:99265] [Ruby master Bug#17042] Times with timezones return incorrect week numbers mail
@ 2020-07-22 17:56 ` gamelinks007
2020-07-22 18:43 ` [ruby-core:99277] " gamelinks007
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: gamelinks007 @ 2020-07-22 17:56 UTC (permalink / raw)
To: ruby-core
Issue #17042 has been updated by S_H_ (Shun Hiraoka).
Same behaviour in `2.7` & `2.6`(checked `2.7.1`, `2.7.0`, `2.6.6`, `2.6.5`).
----------------------------------------
Bug #17042: Times with timezones return incorrect week numbers
https://bugs.ruby-lang.org/issues/17042#change-86660
* Author: timcraft (Tim Craft)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-07-15 master 79d06483a8)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Times with timezones return incorrect week numbers from strftime. For example:
$ irb -r tzinfo
irb(main):001:0> Time.utc(2020, 7, 22, 12, 0, 0).strftime('%U %V %W')
=> "29 30 29"
irb(main):002:0> Time.new(2020, 7, 22, 12, 0, 0, TZInfo::Timezone.get('America/New_York')).strftime('%U %V %W')
=> "00 00 00"
Follow up to #17024
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:99277] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
2020-07-22 14:08 [ruby-core:99265] [Ruby master Bug#17042] Times with timezones return incorrect week numbers mail
2020-07-22 17:56 ` [ruby-core:99272] " gamelinks007
@ 2020-07-22 18:43 ` gamelinks007
2020-07-22 19:15 ` [ruby-core:99278] " gamelinks007
2020-07-22 19:32 ` [ruby-core:99279] " gamelinks007
3 siblings, 0 replies; 5+ messages in thread
From: gamelinks007 @ 2020-07-22 18:43 UTC (permalink / raw)
To: ruby-core
Issue #17042 has been updated by S_H_ (Shun Hiraoka).
Apparently the calculation result `ret = ((timeptr->tm_yday + 7 - wday) / 7);` is negative(`timeptr->tm_yday` is negative).
```c
static int
weeknumber(const struct tm *timeptr, int firstweekday)
{
int wday = timeptr->tm_wday;
int ret;
if (firstweekday == 1) {
if (wday == 0) /* sunday */
wday = 6;
else
wday--;
}
ret = ((timeptr->tm_yday + 7 - wday) / 7);
if (ret < 0)
ret = 0;
return ret;
}
```
----------------------------------------
Bug #17042: Times with timezones return incorrect week numbers
https://bugs.ruby-lang.org/issues/17042#change-86665
* Author: timcraft (Tim Craft)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-07-15 master 79d06483a8)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Times with timezones return incorrect week numbers from strftime. For example:
$ irb -r tzinfo
irb(main):001:0> Time.utc(2020, 7, 22, 12, 0, 0).strftime('%U %V %W')
=> "29 30 29"
irb(main):002:0> Time.new(2020, 7, 22, 12, 0, 0, TZInfo::Timezone.get('America/New_York')).strftime('%U %V %W')
=> "00 00 00"
Follow up to #17024
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:99278] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
2020-07-22 14:08 [ruby-core:99265] [Ruby master Bug#17042] Times with timezones return incorrect week numbers mail
2020-07-22 17:56 ` [ruby-core:99272] " gamelinks007
2020-07-22 18:43 ` [ruby-core:99277] " gamelinks007
@ 2020-07-22 19:15 ` gamelinks007
2020-07-22 19:32 ` [ruby-core:99279] " gamelinks007
3 siblings, 0 replies; 5+ messages in thread
From: gamelinks007 @ 2020-07-22 19:15 UTC (permalink / raw)
To: ruby-core
Issue #17042 has been updated by S_H_ (Shun Hiraoka).
This code resolve this behaviour.
```c
static VALUE
time_strftime(VALUE time, VALUE format)
{
struct time_object *tobj;
const char *fmt;
long len;
rb_encoding *enc;
VALUE tmp;
GetTimeval(time, tobj);
if (tobj->vtm.yday == 0) {
VALUE zone = tobj->vtm.zone;
if (!NIL_P(zone)) zone_localtime(zone, time);
}
MAKE_TM(time, tobj);
StringValue(format);
if (!rb_enc_str_asciicompat_p(format)) {
rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
}
tmp = rb_str_tmp_frozen_acquire(format);
fmt = RSTRING_PTR(tmp);
len = RSTRING_LEN(tmp);
enc = rb_enc_get(format);
if (len == 0) {
rb_warning("strftime called with empty format string");
return rb_enc_str_new(0, 0, enc);
}
else {
VALUE str = rb_strftime_alloc(fmt, len, enc, time, &tobj->vtm, tobj->timew,
TZMODE_UTC_P(tobj));
rb_str_tmp_frozen_release(format, tmp);
if (!str) rb_raise(rb_eArgError, "invalid format: %"PRIsVALUE, format);
return str;
}
}
```
`tobj->vtm.yday`is seems to be 0.
So, these code resolve.
```c
if (tobj->vtm.yday == 0) {
VALUE zone = tobj->vtm.zone;
if (!NIL_P(zone)) zone_localtime(zone, time);
}
```
----------------------------------------
Bug #17042: Times with timezones return incorrect week numbers
https://bugs.ruby-lang.org/issues/17042#change-86666
* Author: timcraft (Tim Craft)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-07-15 master 79d06483a8)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Times with timezones return incorrect week numbers from strftime. For example:
$ irb -r tzinfo
irb(main):001:0> Time.utc(2020, 7, 22, 12, 0, 0).strftime('%U %V %W')
=> "29 30 29"
irb(main):002:0> Time.new(2020, 7, 22, 12, 0, 0, TZInfo::Timezone.get('America/New_York')).strftime('%U %V %W')
=> "00 00 00"
Follow up to #17024
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:99279] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
2020-07-22 14:08 [ruby-core:99265] [Ruby master Bug#17042] Times with timezones return incorrect week numbers mail
` (2 preceding siblings ...)
2020-07-22 19:15 ` [ruby-core:99278] " gamelinks007
@ 2020-07-22 19:32 ` gamelinks007
3 siblings, 0 replies; 5+ messages in thread
From: gamelinks007 @ 2020-07-22 19:32 UTC (permalink / raw)
To: ruby-core
Issue #17042 has been updated by S_H_ (Shun Hiraoka).
Created patch.
https://github.com/ruby/ruby/pull/3352
----------------------------------------
Bug #17042: Times with timezones return incorrect week numbers
https://bugs.ruby-lang.org/issues/17042#change-86667
* Author: timcraft (Tim Craft)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.8.0dev (2020-07-15 master 79d06483a8)
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Times with timezones return incorrect week numbers from strftime. For example:
$ irb -r tzinfo
irb(main):001:0> Time.utc(2020, 7, 22, 12, 0, 0).strftime('%U %V %W')
=> "29 30 29"
irb(main):002:0> Time.new(2020, 7, 22, 12, 0, 0, TZInfo::Timezone.get('America/New_York')).strftime('%U %V %W')
=> "00 00 00"
Follow up to #17024
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-22 19:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 14:08 [ruby-core:99265] [Ruby master Bug#17042] Times with timezones return incorrect week numbers mail
2020-07-22 17:56 ` [ruby-core:99272] " gamelinks007
2020-07-22 18:43 ` [ruby-core:99277] " gamelinks007
2020-07-22 19:15 ` [ruby-core:99278] " gamelinks007
2020-07-22 19:32 ` [ruby-core:99279] " gamelinks007
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).