tags:

views:

623

answers:

1

I have following text field with dojo dojo Date text type.

dojoType="dijit.form.DateTextBox" required="true"/>

I use the following code to set the dijit.form.DateTextBox value

dijit.byId('dtinv').attr('value',new Date(tList[i].getAttribute("dtinv"))) ;

tList[i].getAttribute("dtinv") has value 2010-04-02

When the value is set, I see 4/1/2010. Always the date in dojo date box shows one day less. Is there something I should take care?

+1  A: 

(I'm in Boston)

>>> new Date("2010-04-02")
Thu Apr 01 2010 20:00:00 GMT-0400 (EST) {}

You're getting a date back in GMT, which is how FF must interpret ISO times without a time or a "Z" (seems counter-intuitive, but it's probably correct... I should check the ES5 spec)

whereas Dijit deals in local time. This object would work as expected:

>>> new Date(2010, 3, 2)
Fri Apr 02 2010 00:00:00 GMT-0400 (EST) {}

Dojo and Dijit deal in local times, not GMT, which itself may have been a poor design choice, but given this, if you use dojo.date.stamp.fromISOString() you will get April 2 at midnight in your local time. Pass that to the Dijit and it will be happy.

Also, Javascript's new Date constructor is poorly defined when it comes to taking Strings. I'm not sure if the result you're getting is consistent across all browsers. You are advised to use dojo.date.stamp.fromISOString("2010-04-02") to get the corresponding Date object, or ES5 ISO date methods, where available in newer browsers.

peller