Fix some problems with dates set with string values - they were parsed as UTC, but server sends user times

This commit is contained in:
Nathan Gray 2012-03-08 00:20:04 +00:00
parent 0effc3a229
commit c09d09a8c1

View File

@ -235,11 +235,15 @@ var et2_date = et2_inputWidget.extend({
return; return;
} }
} else { } else {
_value = Date.parse(_value); var text = new Date(_value);
// Handle timezone offset - times are already in user time
var localOffset = text.getTimezoneOffset() * 60000;
// JS dates use milliseconds // JS dates use milliseconds
this.date.setTime(parseInt(_value)*1000); this.date.setTime(text.valueOf()+localOffset);
} }
} else if (typeof _value == 'integer') { } else if (typeof _value == 'integer') {
// Timestamp
// JS dates use milliseconds // JS dates use milliseconds
this.date.setTime(parseInt(_value)*1000); this.date.setTime(parseInt(_value)*1000);
} else if (typeof _value == 'object' && _value.date) { } else if (typeof _value == 'object' && _value.date) {
@ -611,8 +615,19 @@ var et2_date_ro = et2_valueWidget.extend([et2_IDetachedDOM], {
return; return;
} }
// JS dates use milliseconds if(typeof _value == 'string' && isNaN(_value))
this.date.setTime(parseInt(_value)*1000); {
var text = new Date(_value);
// Handle timezone offset - times are already in user time, but parse does UTC
var localOffset = text.getTimezoneOffset() * 60000;
// JS dates use milliseconds
this.date.setTime(text.valueOf()+localOffset);
}
else
{
// JS dates use milliseconds
this.date.setTime(parseInt(_value)*1000);
}
var display = this.date.toString(); var display = this.date.toString();
switch(this._type) { switch(this._type) {