I have a widget I created way back in 0.4 that I'm porting over to 1.0
It is using dojo.date.add a lot and today I found a problem.
Back in Dojo 0.4 a call like this dojo.date.add(date, dojo.date.dateParts.DAY, 1); resulted in the following code:
In Dojo 1.0.x the call dojo.date.add(date, "day", 1); results in the following code:
The problem with using the UTC date is that when daylight savings go in/out of effect the we don't add a "Day" we add 25/23 hours.
To highlight the problem even more I supply the following code snippet.
dojo.require("dojo.date.locale");
function createCalendarDates(date){
var curDojoDate = new Date(date);
var curJSDate = new Date(date);
var numberOfDays = dojo.date.getDaysInMonth(date);
var sDojoString = sJSString = '';
for(var i=0; i<numberOfDays; i++) {
sDojoString += curDojoDate + '';
sJSString += curJSDate + '';
curDojoDate = dojo.date.add(curDojoDate, "day", 1);
curJSDate.setDate(curJSDate.getDate() + 1);
}
dojo.byId("byDojoDateAdd").innerHTML = sDojoString;
dojo.byId("byJSDateAdd").innerHTML = sJSString;
}
dojo.addOnLoad(function(){
var nov1 = new Date(2007,10,1);
createCalendarDates(nov1);
});
</script>
<span id="byDojoDateAdd" style="float:left; width:450px;"></span>
<span id="byJSDateAdd" style="float:left;"></span>
The resulting HTML page will look something like this:
Fri Nov 02 2007 00:00:00 GMT-0500 (Central Daylight Time) Fri Nov 02 2007 00:00:00 GMT-0500 (Central Daylight Time)
Sat Nov 03 2007 00:00:00 GMT-0500 (Central Daylight Time) Sat Nov 03 2007 00:00:00 GMT-0500 (Central Daylight Time)
Sun Nov 04 2007 00:00:00 GMT-0500 (Central Daylight Time) Sun Nov 04 2007 00:00:00 GMT-0500 (Central Daylight Time)
Sun Nov 04 2007 23:00:00 GMT-0600 (Central Standard Time) Mon Nov 05 2007 00:00:00 GMT-0600 (Central Standard Time)
Mon Nov 05 2007 23:00:00 GMT-0600 (Central Standard Time) Tue Nov 06 2007 00:00:00 GMT-0600 (Central Standard Time)
...
Wed Nov 28 2007 23:00:00 GMT-0600 (Central Standard Time) Thu Nov 29 2007 00:00:00 GMT-0600 (Central Standard Time)
Thu Nov 29 2007 23:00:00 GMT-0600 (Central Standard Time) Fri Nov 30 2007 00:00:00 GMT-0600 (Central Standard Time)
Is this something I'm the only one having problems with or can we see a fix???
The fix that I would like, would be to change line 191 of dojocore/dojo/date.js from:
to:
Sincerely,
Viktor

Thanks for reporting this.
Thanks for reporting this. I filed a ticket and fixed the problem. Instead of using:
case "minute":
case "second":
case "millisecond":
property = interval.charAt(0).toUpperCase() + interval.substring(1) + "s";
}
if(property){
sum["setUTC"+property](sum["getUTC"+property]()+amount);
}
I changed it to look like this:
case "minute":
case "second":
case "millisecond":
property = "UTC"+interval.charAt(0).toUpperCase() + interval.substring(1) + "s";
}
if(property){
sum["set"+property](sum["get"+property]()+amount);
}
This will use locale for any interval greater than an hour while still correctly adding any interval less than or equal to an hour. Here is some code to test both situations:
dojo.require("dojo.date.locale"); function appendRow(table_name, djDate, jsDate){ var tr = document.createElement("tr"); var dd = document.createElement("td"); var jd = document.createElement("td"); dd.innerHTML = djDate; jd.innerHTML = jsDate; tr.appendChild(dd); tr.appendChild(jd); dojo.byId(table_name).appendChild(tr); } function createCalendarDates(date){ var curDojoDate = new Date(date); var curJSDate = new Date(date); var numberOfDays = dojo.date.getDaysInMonth(date); for(var i=0; iDays
DojoJavaScriptHours
DojoJavaScriptAnd the result:
As you can see, both situations now work. Thanks again for reporting it!
Thank you for your reply
I'm just glad I could help.