From: gamelinks007@... Date: 2020-07-22T19:15:28+00:00 Subject: [ruby-core:99278] [Ruby master Bug#17042] Times with timezones return incorrect week numbers 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/ Unsubscribe: