PDA

View Full Version : Ext.util.Format.date Problem or Bug



Kangulo
14 Feb 2010, 9:53 PM
I just want to format a date, i used ext-all-debug.js 3.0, i used ext-lang-es.js to set locale format to all variables.

So, i'd knew the Ext.util.Format.Date function could do this, and when i used it, i did get the following result:



// Fecha: 03 de Febrero de 2010
// d m Y
console.log(Ext.util.Format.date('03/02/2010', 'Y-m-d')); //2010-03-02


I get the same error from the string or datepicker control.(:|

Well, this is can be a problem or a bug, i'm not sure :-?, i tried with the new version 3.1.1 but still the same result, any help would be appreciated

if anybody can me this clear this doubt :)

Thanks

PD: Sorry for my English.

bclinton
14 Feb 2010, 10:43 PM
I'm not sure I understand your error correctly.

Are you expecting the result to be 2010-02-03 because you expect 02/03/2010 to be recognized as February 2nd rather than March 3rd when using the Spanish locale?

Kangulo
15 Feb 2010, 7:03 AM
I'm not sure I understand your error correctly.

Are you expecting the result to be 2010-02-03 because you expect 03/02/2010 to be recognized as February 3rd rather than March 2nd when using the Spanish locale?

The input date is in format d/m/Y (Sapnish Locale), '03/02/2010' this is February 3rd 2010,

when i apply Ext.util.Format.date('03/02/2010', 'Y-m-d') to convert it in MySQL date format, I am expecting the result to be '2010-02-03' (Y-m-d) rather than '2010-03-02' (Y-d-m).



// Fecha: 03 de Febrero de 2010
// d m Y
console.log(Ext.util.Format.date('03/02/2010', 'Y-m-d')); //this is the wrong result 2010-03-02


it should be '2010-02-03', this is should be the right output!

Regards

mystix
17 Feb 2010, 9:19 AM
From the docs for Ext.util.Format#date() (http://extjs.com/docs/?class=Ext.util.Format&member=date)'s value parameter (emphasis added):


value : String/Date
The value to format (Strings must conform to the format expected by the javascript Date object's parse() (http://www.w3schools.com/jsref/jsref_parse.asp) method)


that format for the date string parameter is a reference to the RFC1123 format (see this link (http://stackoverflow.com/questions/1088793/the-correct-javascript-date-parse-format-string/1088823#1088823) for a short discussion), which is used by the built-in javascript Date object's parse() method (this parse() method is built-in to the stock javascript Date object -- it's not added by Ext, neither does it get altered by Ext's locale files) so your code should be something like


Ext.util.Format.date('3 Feb 2010', 'Y-m-d');

or even


Ext.util.Format.date('3 February 2010', 'Y-m-d');

(also see http://www.freesoft.org/CIE/RFC/1945/14.htm for a quick list of RFC 1123 date formats).


if you're just looking to convert non-RFC1123-formatted Date strings from one date format to another, i'd suggest using Ext's augmented Date class methods (specifically Date#parseDate() and Date#format()) like so:


// parse the date string "03/02/2010" into a js Date object using the "d/m/Y" format,
// then format this same Date object for display using the "Y-m-d" format.

Date.parseDate('03/02/2010', d/m/Y'').format('Y-m-d');

note: you do not need to modify the locale files to achieve this.

Kangulo
18 Feb 2010, 7:20 AM
Well Mystix, thank you for you answer and help me to understand, i just thought that thing was more simple. /:)

Thank you very much for take your time to explain me that. =D>

Best Regards.

alexbrina
9 Mar 2010, 5:02 AM
I have run through the same issue for pt_BR.

RFC1123 format is rather English centered and I guess all locales that uses d/m/Y or ISO8601 formats have a hard time figuring out what's wrong.

Ext's augmented Date object has a much more flexible parser which is Date.parseDate and I wonder if locale files should use it instead of Date.parse in Ext.util.Format.date