PDA

View Full Version : Question re: Paging grid example and dateFormat



gnosis
20 Jul 2007, 9:03 AM
In the paging grid example, the reader is set up to map

{name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'}

The example goes on to create a column model that calls a renderer and all is well.

Unfortunately, the docs for Record.create() seem to be hosed up (looks like the doc creator got stuck in a loop or something...) and the options for dateFormat aren't listed anywhere that I can find. What options are there other than 'timestamp' for defining the format of data to be read?

Thanks,
G

tryanDLS
20 Jul 2007, 9:20 AM
dateFormat can be any valid format string that (e.g. y/m/d) in addition to 'timestamp'. These are the standard formats as outlined in the Date class.

gnosis
20 Jul 2007, 9:56 AM
Ok, that's what I assumed, but when I tried it (with Y-m-d H:i:s, the MySQL datetime format), it didn't work. The value passed to my renderer had no properties.

But I figured out why.

It was because one of the rows in the db was returning default "0000-00-00 00:00:00". It appears that the Ext Date class doesn't know how to deal with that. I would expect a 1969 default or something, but instead it comes back null.


...
reader: new Ext.data.JsonReader({
root: 'Groups',
totalProperty: 'Total',
id: 'id'
}, [
{name: 'id'},
{name: 'name'},
{name: 'description'},
{name: 'end_date', type:'date', dateFormat: 'Y-m-d H:i:s'},
]),
...

function renderDate(value){
return value.dateFormat('Y-m-d');
}

cm = new Ext.grid.ColumnModel([
...
{
header: "End Date",
dataIndex: 'end_date',
width: 150,
sortable:true,
renderer:renderDate
},
...


Will cause error "value has no properties" if the record is "0000-00-00 00:00:00".

mystix
20 Jul 2007, 11:54 AM
Hmmm... "Y-m-d H:i:s" is actually ISO8601Long format (which is in the suggested Date.patterns object in the Date docs)...

i tried the following with extremely weird return results
Date.parseDate('0000-00-00 00:00:00', 'Y-m-d H:i:s'); // returns null
Date.parseDate('0001-00-00 00:00:00', 'Y-m-d H:i:s'); // returns "Thu Jan 01 1970 08:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0010-00-00 00:00:00', 'Y-m-d H:i:s'); // returns "Thu Jan 01 1970 08:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0100-00-00 00:00:00', 'Y-m-d H:i:s'); // returns "Thu Jan 01 1970 08:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('1000-00-00 00:00:00', 'Y-m-d H:i:s'); // returns "Thu Jan 01 1970 08:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0100-01-00 00:00:00', 'Y-m-d H:i:s'); // returns "Fri Jan 01 0100 00:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0100-01-01 00:00:00', 'Y-m-d H:i:s'); // returns "Fri Jan 01 0100 00:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0099-01-00 00:00:00', 'Y-m-d H:i:s'); // returns "Fri Jan 01 1999 00:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0099-01-01 00:00:00', 'Y-m-d H:i:s'); // returns "Fri Jan 01 1999 00:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0099-00-00 00:00:00', 'Y-m-d H:i:s'); // returns "Fri Jan 01 1999 00:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('1970-00-00 00:00:00', 'Y-m-d H:i:s'); // returns "Thu Jan 01 1970 08:00:01 GMT+0800 (Malay Peninsula Standard Time)"note that the above values are returned with respect to my GMT timezone offset.

the lowest value i managed to take it down to, via trial and error, was
// returns "Tue Apr 20 -271821 08:00:00 GMT+0800 (Malay Peninsula Standard Time)"
Date.parseDate('0100-01-01 00:00:00', 'Y-m-d H:i:s').add(Date.YEAR, -271920).add(Date.MONTH, -8).add(Date.DAY, -10).add(Date.HOUR, -16);

// returns "Invalid Date"
Date.parseDate('0100-01-01 00:00:00', 'Y-m-d H:i:s').add(Date.YEAR, -271920).add(Date.MONTH, -8).add(Date.DAY, -10).add(Date.HOUR, -16).add(Date.MILLI, -1);
which means, and correct me if i'm wrong, that the earliest possible date you may set the javascript Date object to will be "Tue Apr 20 -271821 00:00:00" at GMT.

could you post this in bugs with a link to this thread (you can quote me if u want to too) and bump it after a few days if you don't get a response? i'll look into it when i've got some time. thanks.

Wolfgang
20 Jul 2007, 12:06 PM
I had a similiar Issue. Maybe this helps you:
http://extjs.com/forum/showthread.php?t=9649

Regards

Wolfgang

mystix
22 Jul 2007, 11:50 AM
Ok, that's what I assumed, but when I tried it (with Y-m-d H:i:s, the MySQL datetime format), it didn't work. The value passed to my renderer had no properties.

But I figured out why.

It was because one of the rows in the db was returning default "0000-00-00 00:00:00". It appears that the Ext Date class doesn't know how to deal with that. I would expect a 1969 default or something, but instead it comes back null.


...
reader: new Ext.data.JsonReader({
root: 'Groups',
totalProperty: 'Total',
id: 'id'
}, [
{name: 'id'},
{name: 'name'},
{name: 'description'},
{name: 'end_date', type:'date', dateFormat: 'Y-m-d H:i:s'},
]),
...

function renderDate(value){
return value.dateFormat('Y-m-d');
}

cm = new Ext.grid.ColumnModel([
...
{
header: "End Date",
dataIndex: 'end_date',
width: 150,
sortable:true,
renderer:renderDate
},
...


Will cause error "value has no properties" if the record is "0000-00-00 00:00:00".

just fixed this in SVN.


Date.parseDate("0000-00-00 00:00:00", "Y-m-d H:i:s") // should now return the unix epoch, adjusted to your timezone