Opened 7 years ago

Last modified 23 months ago

#16757 new defect

dojo.date.locale.format : _getWeekOfYear - iso8601 - week number

Reported by: tro Owned by: Adam Peller
Priority: undecided Milestone: 1.15
Component: Date Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

Using dojo.date.locale.format , the week number seems to be wrong according to iso 8601.

Example: For today (02-25-2013) week number is "8" while it should be "9" (ISO8601 specification).

Solution proposal(dojo/date/locale.js):

exports._getWeekOfYear = function(/*Date*/ dateObject, /*Number*/ firstDayOfWeek){

if(arguments.length == 1){ firstDayOfWeek = 0; } Sunday

var determinedate = new Date(); determinedate.setFullYear(dateObject.getFullYear(), dateObject.getMonth(), dateObject.getDate()); var D = determinedate.getDay(); if(D == firstDayOfWeek) D = 7; determinedate.setDate(determinedate.getDate() + (4 - D)); var YN = determinedate.getFullYear(); var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000); var WN = 1 + Math.floor(ZBDoCY / 7); return WN;

};

Change History (3)

comment:1 Changed 4 years ago by dylan

Milestone: tbd1.12

The following test confirms the issue. That said, I think the issue is that the internal API is starting at week 0 rather than week 1.

diff --git a/tests/unit/date/locale.js b/tests/unit/date/locale.js
index a5fc1b8..7161b51 100644
--- a/tests/unit/date/locale.js
+++ b/tests/unit/date/locale.js
@@ -371,6 +371,7 @@ define([
                        assert.equal(locale._getWeekOfYear(new Date(2007, 0, 1), 1), 1);
                        assert.equal(locale._getWeekOfYear(new Date(2007, 6, 14)), 27);
                        assert.equal(locale._getWeekOfYear(new Date(2007, 6, 14), 1), 28);
+                       assert.equal(locale._getWeekOfYear(new Date(2013, 1, 25)), 9);
+                       assert.equal(locale._getWeekOfYear(new Date(2013, 0, 1)), 1);
                }
        });
 });

So I'm not sure this is something to actually fix.

comment:2 Changed 3 years ago by dylan

Milestone: 1.131.15

Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.

comment:3 Changed 23 months ago by der_reisende

At least formatPattern must be changed by adding +1 to the calculated week number.

In 2018, all week numbers are wrong when using dojo/date/locale.format with datePattern y-ww, e.g. 2018-01-01 gives "2018-00", which is not a Week number according to ISO

Solution proposal:

case 'w':
   var firstDay = 0;
   s = exports._getWeekOfYear(dateObject, firstDay) + 1 ; pad = true;
Note: See TracTickets for help on using tickets.