ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: gamelinks007@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99278] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
Date: Wed, 22 Jul 2020 19:15:28 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-86666.20200722191528.7520@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17042.20200722140843.7520@ruby-lang.org

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/

  parent reply	other threads:[~2020-07-22 19:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-07-22 19:32 ` [ruby-core:99279] " gamelinks007

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-86666.20200722191528.7520@ruby-lang.org \
    --to=ruby-core@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).