Project

General

Profile

Bug #9372

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

Added by pblesi (Patrick Blesi) over 6 years ago. Updated almost 6 years ago.

Status:
Rejected
Priority:
Normal
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

Has duplicate Ruby master - Bug #9809: Date.new(2000,1,1).cweek should == 1Rejected05/06/2014Actions

Updated by pblesi (Patrick Blesi) over 6 years ago

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) over 6 years ago

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

Updated by tadf (tadayoshi funaba) over 6 years ago

  • 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) over 6 years ago

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 6 years ago

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

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

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

Updated by esaari (Eric Saari) almost 6 years ago

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?

Also available in: Atom PDF