PDA

View Full Version : Date render problem



Fredric Berling
9 Sep 2009, 1:05 AM
Ive been banging my head for a while now about a simple date format issue.

date comes in from a json i cant control in this format example : "20090909T085300,78Z"

This doesnt seem to be able to work using the Ext.util.Format.dateRenderer

so question is... WHat do i put in my reader fields section. ?

{
name: 'rdate',
type:'date',
dateFormat: '???????????',
mapping: 'entrydata[4].datetime[0]'
}

to be able to use this columnmodel:



{
header: "date",
width: 100,
sortable: 'true',
resizable: false,
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
dataIndex: 'rdate'
}

mystix
9 Sep 2009, 1:15 AM
{
name: 'rdate',
type: 'date',
dateFormat: 'Ymd\\THis,u\\Z',
mapping: 'entrydata[4].datetime[0]'
}


[edit]
you should really try to convince the guy at the other end of the line to send dates in standard ISO8601 format...

p.s. Ext.util.Format.dateRenderer() will only format valid dates.

mystix
9 Sep 2009, 1:38 AM
scratch that... with the previous solution i suggested, the UTC timezone delimiter Z in the date string sent by your server is not automatically handled.

include this override (in an override file immediately after ext-all-debug.js / ext-all.js):


Date.parseCodes.c = function() {
var $f = Date.formatCodeToRegex,
calc = [],
arr = [
$f("Y", 1), // year
$f("m", 2), // month
$f("d", 3), // day
$f("h", 4), // hour
$f("i", 5), // minute
$f("s", 6), // second
{c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
{c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
"if(results[8]) {", // timezone specified
"if(results[8] == 'Z'){",
"zz = 0;", // UTC
"}else if (results[8].indexOf(':') > -1){",
$f("P", 8).c, // timezone offset with colon separator
"}else{",
$f("O", 8).c, // timezone offset without colon separator
"}",
"}"
].join('\n')}
];

for (var i = 0, l = arr.length; i < l; ++i) {
calc.push(arr[i].c);
}

return {
g:1,
c:calc.join(""),
s:[
// custom override -- allow omission of dashes and colons in ISO8601 format
arr[0].s, // year (required)
"(?:", "-?", arr[1].s, // month (optional)
"(?:", "-?", arr[2].s, // day (optional)
"(?:",
"(?:T| )?", // time delimiter -- either a "T" or a single blank space
arr[3].s, ":?", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
"(?::?", arr[5].s, ")?", // seconds (optional)
"(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
"(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
")?",
")?",
")?"
].join("")
}
}();


then use this data.Field definition instead:


{
name: 'rdate',
type: 'date',
dateFormat: 'c',
mapping: 'entrydata[4].datetime[0]'
}

Fredric Berling
9 Sep 2009, 2:49 AM
Thanks alot for the quick response. Sorry to say i cant do much about the output JSON from the other side, but ill try your solution.

Fredric Berling
9 Sep 2009, 3:07 AM
Worked like a charm !! thanks!