Opened 8 years ago
Last modified 3 years 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 5 years ago by
Milestone: | tbd → 1.12 |
---|
comment:2 Changed 4 years ago by
Milestone: | 1.13 → 1.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 3 years ago by
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;
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.
So I'm not sure this is something to actually fix.