PDA

View Full Version : Dealing with Java Timestamps in Data.Store



el-tio
10 Aug 2010, 2:06 AM
Hi,

I am loading a JSON web service into a data.Store and i have the following Model:


Ext.regModel('Video', {
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'shortDescription',
type: 'string'
}, {
name: 'thumbnailURL',
type: 'string'
},{
name: 'publishedDate',
type: 'date',
dateFormat: 'timestamp'
},{
name: 'tags',
type: 'string'
}]
});However the JSON is returning timestamps in milliseconds [Java] rather than seconds, so using the dateFormat: timestamp gives me strange results.

Do I need to provide a different dateFormat in my model, or can I maniuplate/format the timestamp when rendering it in my XTemplate [if its possible to do this]?

Many Thanks

el-tio
10 Aug 2010, 2:12 AM
Doh - as usual post the question - find the answer directly in the Docs - Apologies

dateFormat (http://dev.sencha.com/deploy/dev/docs/source/DataField.html#cfg-Ext.data.Field-dateFormat) : String(Optional) Used when converting received data into a Date when the type is specified as "date". A format string for t...
(Optional) Used when converting received data into a Date when the type (http://dev.sencha.com/deploy/dev/docs/output/Ext.data.Field.html#Ext.data.Field-type) is specified as "date".
A format string for the Date.parseDate (http://dev.sencha.com/deploy/dev/docs/output/Date.html#Date-parseDate) function, or "timestamp" if the value provided by the Reader is a UNIX timestamp, or "time" if the value provided by the Reader is a javascript millisecond timestamp. See Date (http://dev.sencha.com/deploy/dev/docs/output/Date.html)

evant
10 Aug 2010, 2:15 AM
You can specify any date format listed here: http://dev.sencha.com/deploy/touch/docs/?class=Date

el-tio
10 Aug 2010, 3:54 AM
Thanks Evant.

Could you tell me where i format the date on the Model of the template?

I have the following model

Ext.regModel('Video', {
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'shortDescription',
type: 'string'
}, {
name: 'thumbnailURL',
type: 'string'
},{
name: 'publishedDate',
type: 'date',
dateFormat: 'time'
},{
name: 'tags',
type: 'string'
}]
});
and the following template

tpl: ['<tpl for=".">',
'<div class="VideoList" id="{id}">',
'<tpl if="thumbnailURL"><img src="{thumbnailURL}" width="120px" height="67px" /><h1>{name}</h1></tpl>',
'<tpl if="!thumbnailURL"><img src="img/no-video-thumb.gif" width="120px" height="67px" /><h1>{name}</h1></tpl>',
'<div class="videoText">',
'<div class="video-content">',
'<p>{shortDescription}</p><strong></strong>',
'<span class="posted">{publishedDate}</span>',
'<span class="tags"><hr />{tags}</span>',
'</div>',
'</div>',
'</div>',
'</tpl>',
'<div class="x-clear"></div>',
].join(''),
and the time stamps currently look like this
Mon Aug 09 2010 09:40:18 GMT+0100 (GMT Daylight Time)

where do i apply the formatting rules

el-tio
10 Aug 2010, 4:07 AM
I had the right idea just the wrong syntax (dam you colons :-) )

for any one who is interestd here is the syntax


tpl: ['<tpl for=".">',
'<div class="VideoList" id="{id}">',
'<tpl if="thumbnailURL"><img src="{thumbnailURL}" width="120px" height="67px" /><h1>{name}</h1></tpl>',
'<tpl if="!thumbnailURL"><img src="img/no-video-thumb.gif" width="120px" height="67px" /><h1>{name}</h1></tpl>',
'<div class="videoText">',
'<div class="video-content">',
'<p>{shortDescription}</p><strong></strong>',
'<span class="posted">{publishedDate:date("d/m/Y")}</span>',
'<span class="tags"><hr />{tags}</span>',
'</div>',
'</div>',
'</div>',
'</tpl>',
'<div class="x-clear"></div>',
].join(''),