Project

General

Profile

Actions

Bug #9372

closed

Date function cweek reports innaccurately for the date December 30, 2013

Bug #9372: Date function cweek reports innaccurately for the date December 30, 2013

Added by pblesi (Patrick Blesi) almost 12 years ago. Updated about 11 years ago.

Status:
Rejected
Target version:
-
[ruby-core:59598]

Description

Date function cweek reports innaccurately for the date December 30, 2013. The current week is reported as 1 instead of 53.


Related issues 1 (0 open1 closed)

Has duplicate Ruby - Bug #9809: Date.new(2000,1,1).cweek should == 1RejectedActions

Updated by pblesi (Patrick Blesi) almost 12 years ago Actions #1 [ruby-core:59599]

I've added some code for extra clarity.

2.0.0p247 :017 > require 'date'
 => true 
2.0.0p247 :018 > d = Date.new(2013,12,30)
 => #<Date: 2013-12-30 ((2456657j,0s,0n),+0s,2299161j)> 
2.0.0p247 :019 > d.cweek
 => 1 

2.0.0p247 :005 > d = Date.new(2013, 12, 29)
 => #<Date: 2013-12-29 ((2456656j,0s,0n),+0s,2299161j)> 
2.0.0p247 :006 > d.cweek
 => 52 

Updated by tadf (tadayoshi funaba) almost 12 years ago Actions #2 [ruby-core:59607]

  • Status changed from Open to Assigned
  • Assignee set to tadf (tadayoshi funaba)

Updated by tadf (tadayoshi funaba) almost 12 years ago Actions #3 [ruby-core:59608]

  • Status changed from Assigned to Rejected

A period of time of seven days within a calendar year, starting on a
Monday and identified by its ordinal number within the year; the first
calendar week of the year is the one that includes the first Thursday
of that year. In the Gregorian calendar, this is equivalent to the
week which includes 4 January.

Updated by duerst (Martin Dürst) almost 12 years ago Actions #4 [ruby-core:59618]

tadf (tadayoshi funaba) wrote:

A period of time of seven days within a calendar year, starting on a
Monday and identified by its ordinal number within the year; the first
calendar week of the year is the one that includes the first Thursday
of that year. In the Gregorian calendar, this is equivalent to the
week which includes 4 January.

This may not yet be completely clear, because it says "within a [calendar] year" twice. The following quote, from http://en.wikipedia.org/wiki/ISO_week_date, is even clearer:

"ISO week-numbering years have a year numbering which is approximately the same as the Gregorian years, but not exactly since an ISO week-numbering year (also called ISO year or week year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days."

It may be a good idea to add the following example (borrowed from cwyear)

Date.new(2000,1,1).cweek         #=> 53, see Date#cwyear

Tadayoshi, I can do that if you are okay.

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #5 [ruby-core:62437]

  • Has duplicate Bug #9809: Date.new(2000,1,1).cweek should == 1 added

Updated by nobu (Nobuyoshi Nakada) over 11 years ago Actions #6 [ruby-core:62438]

This is a repeated question, so it feels nice to add examples.

Updated by esaari (Eric Saari) about 11 years ago · Edited Actions #7 [ruby-core:64795]

Nobuyoshi Nakada wrote:

This is a repeated question, so it feels nice to add examples.

Even though this is a closed issue, I am seeing the same issue for the years 2018 and 2019:

$> date = Date.new(2018,12,31)
=> #<Date: 2018-12-31 ((2458484j,0s,0n),+0s,2299161j)>
$> date.cweek
=> 1
$> date = Date.new(2019,12,31)
=> #<Date: 2019-12-31 ((2458849j,0s,0n),+0s,2299161j)>
$> date.cweek
=> 1

Can this same issue apply for two calendar years in a row?

Actions

Also available in: PDF Atom