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:99277] [Ruby master Bug#17042] Times with timezones return incorrect week numbers
Date: Wed, 22 Jul 2020 18:43:56 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-86665.20200722184355.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).


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/

  parent reply	other threads:[~2020-07-22 18:44 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 ` gamelinks007 [this message]
2020-07-22 19:15 ` [ruby-core:99278] " gamelinks007
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-86665.20200722184355.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).