-
11 Dec 2012 11:40 AM #1
[2.1] Ext.util.Format.date returning wrong date (one day off)
[2.1] Ext.util.Format.date returning wrong date (one day off)
On Samsung Galaxy S3 Android 4.0.4,
(Update: This can be reproduced on any browser, see second post below)
Ext.util.Format.date is returning the wrong date (one day off).
Test case:
Actual Result:Code:<!DOCTYPE HTML> <html manifest="" lang="en-US"> <head> <meta charset="UTF-8"> <title>Date</title> <script type="text/javascript" src="http://docs.sencha.com/touch/2-1/touch-build/sencha-touch-all.js"></script> <script> Ext.onReady(function () { document.write(Ext.util.Format.date('2012-12-01', 'F d, Y')); document.write('<br><br>'); document.write(new Date()); }); </script> </head> <body></body> </html>
Expected Result:Code:November 30, 2012 Mon Dec 10 2012 08:55:53 GMT - 0500 (EST)
This is not reproducible with ST 1's Ext.util.Format.date.Code:December 01, 2012 Mon Dec 10 2012 08:55:53 GMT - 0500 (EST)
Owner of 360releases Ltd. - Sencha Touch & Ext JS consulting
twitter.com/steffenhiller
extjswithrails.com, senchatouchbits.com
-
11 Dec 2012 12:28 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,682
- Vote Rating
- 435
Thanks for the report! I have opened a bug in our bug tracker.
-
13 Dec 2012 5:22 AM #3
Fyi,
I was able to reproduce this issue on an HTC Sensation 4.0.3 as well as on my desktop Chrome.
Simply set the timezone to EST or any < GMT timezone.
The native Date.parse method isn't parsing '2012-12-01' as expected, see below:
The Ext.util.Format.date code is first trying to parse the '2012-12-01' date,Code:new Date(Date.parse('2012-12-01')); // returns "Fri Nov 30 2012 00:00:00 GMT-0500 (EST)" new Date(Date.parse('2012/12/01')); // returns "Sat Dec 01 2012 00:00:00 GMT-0500 (EST)"
and only if it fails, it replaces the dashes and parses it again.
So what I did is replacing the dashing before.
Here's my override:
SeeCode:Ext.define('App.override.util.Format', { }, function () { var date_without_override = Ext.util.Format.date; // Ext.util.Format.date = function (value, format) { value = value.replace(this.dashesRe, "/"); return date_without_override(value, format); }; });
http://www.sencha.com/forum/showthre...101#post921101
on why I'm not using the override pre-processor.Owner of 360releases Ltd. - Sencha Touch & Ext JS consulting
twitter.com/steffenhiller
extjswithrails.com, senchatouchbits.com
-
29 Dec 2012 9:20 AM #4
I can confirm that this bug affects ExtJS as well... not only Sencha Touch.
-
22 Jan 2013 7:39 AM #5
I Solved it this way

function date_renderer(v,index, rec) {
var returnVal='';
returnVal=Ext.util.Format.date(v,'Y-m-d');
if( returnVal=='NaN-NaN-NaN'){ returnVal=v; }//for IE
else {//Other Browser
returnVal=new String(v);//alert(returnVal);
var x= new Date(returnVal);
x.setDate(x.getDate()+1);
x=Ext.util.Format.date(x,'Y-m-d');
if(x==v){ returnVal= x;} else {x= new Date(v); x.setDate(x.getDate()+0); x= Ext.util.Format.date(x,'Y-m-d');}
returnVal= x;
}
return returnVal;
}
-
22 Jan 2013 8:30 AM #6
I Solved this in a better way. i Just set type and dataFormat in my Model:
Code:{ name: dateField, type: 'date', dateFormat: 'Y-m-d' }
-
15 Apr 2013 1:05 PM #7Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,652
- Vote Rating
- 14
This uses the native Javascript Date.parse() method and is therefore subject to its idiosyncrasies.
Most formats assume the local timezone unless specified. One notable exception is 'YYYY-MM-DD' (note the dashes) which is typically interpreted in UTC and can cause date shifting.
Using 'YYYY/MM/DD' should fix his issue.
Documentation has been updated to reflect this issue.
You found a bug! We've classified it as
TOUCH-3816
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote