PDA

View Full Version : Model Date Format



danvega
25 Jul 2010, 8:32 PM
I have a model with some fields setup. I have date with a dateFormat



fields:[
{name:'date',type:'date',dateFormat:'m/d/Y'},
{name:'starttime',type:'string'},
{name:'endtime',type:'string'},
{name:'location',type:'string'},
{name:'seats',type:'int'}
]


When I output the date in a template though it shows up as the original date.



'<strong>When:</strong>',
'<tpl for="schedule">',
' {date} {starttime} - {endtime}<br/>',
'</tpl>',


Am I doing something wrong? How can I format the date in the template?

evant
25 Jul 2010, 8:33 PM
The dateFormat is for reading the date, if your server returns it as a string. Your field definition indicates that it expects a string in the format of m/d/Y.

danvega
25 Jul 2010, 8:35 PM
Ohh I thought that was to format the output... The server is returning "2010/07/28". How can i format the output?

evant
25 Jul 2010, 9:54 PM
{val:date("m/d/Y")}

danvega
26 Jul 2010, 6:08 AM
Ok this is just weird. That worked fine for me on my local machine but when I pushed it into production there were issues. It was causing errors on iphone,ipad and a buddies browser. He told me that he was getting the following error.

TypeError: Result of expression 'Date.dayNames[c]' [undefined] is not an object.

gbfriends90
29 Sep 2011, 12:57 AM
Hi,

Where {val : date("m/d/Y")} should be given?

wilzdezign
2 Nov 2011, 8:54 AM
An example of output would be in the itemTpl output of the values.

Instead of saying something like..
itemTpl: '<h2>{eventdate} - {eventtitle}</h2>'

change to...
itemTpl: '<h2>{eventdate:date("m/d/Y")} - {eventtitle}</h2>'

Check out the date formatting (similar to PHP) at http://docs.sencha.com/touch/1-1/#!/api/Date (http://docs.sencha.com/touch/1-1/#%21/api/Date)

wilzdezign
8 Nov 2011, 1:32 PM
Ok this is just weird. That worked fine for me on my local machine but when I pushed it into production there were issues. It was causing errors on iphone,ipad and a buddies browser. He told me that he was getting the following error.

TypeError: Result of expression 'Date.dayNames[c]' [undefined] is not an object.

Same like error. Using the Date object with .format("D. F j, g:ia") in JS works fine when I set it within the onItemDisclosure to change the toolbar title with the date. However, when I try to use the same data inside the List 'tpl' as... {timestart:date("l, F j, g:ia")} -- iOS starts giving issues and will not display the panel. I have been developing in Chrome, so when I switched to an iPad to test.. it was not working. Tested in iPhone, same thing. I brought up Safari on my Windows machine with developer console open, and sure enough the error pops up.

Here is the piece of code:


onItemDisclosure: function(record){
var dt = new Date();
dt = Date.parseDate(record.data.timestart, "Y-m-d G:i");
if(record.data.showtime == true || record.data.showtime == "true"){
var topTitle = dt.format("D. F j, g:ia");
}else{
var topTitle = dt.format("D. F j");
}
EventsDescToolbar.setTitle(topTitle); // set title from template data
EventsPanel.setActiveItem('panel-events-desc');
},

store: EventsStore,
// THIS IS WHERE THE ERROR OCCURS. If taken out, the above Date still works
itemTpl: '<div><h2>{title} {timestart:date("D. n/j, g:ia")}</h2></div>'

This works in Chrome and on Android mobile device, but no iOS devices as Safari kicks the error

wilzdezign
9 Nov 2011, 3:21 PM
It does state on the Ext.util.Format method 'date' "Strings must conform to the format expected by the javascript Date object's parse() (http://www.w3schools.com/jsref/jsref_parse.asp) method" -- so I set my output as "ddd m, yyyy HH:mm" .. as I suspect having time in it is still OK as what the PHP date() function allows.

This time I used the default format 'm/d/Y' by calling just {timestart:date} .. Result? Chrome again works fine, but in Safari it shows the result as "NaN/NaN/NaN" -- Not sure where to go if the default format does not work either in the iOS browsers29198

*Update: in the 'itemTpl' still using the value {timestart:date}, but up in the regModel Field, I changed the value {name: 'timestart', type: 'string'} to {name: 'timestart', type: 'date'}, the output becomes now blank (instead of NaN) in iOS browser, but Chrome still shows the date. Is this a bug in iOS parsing of the date?

timbellomo
23 Nov 2011, 2:42 PM
I'm experiencing the NaN issue with my date, but only on some Android devices. I'm formatting my datetime as as "H:i" (hour:minute). I'm using {response_date:date("H:i")} in my XTemplate.

Works
iPhone 4S
Motorola Droid X (running Cyanogenmod/AOSP)

Fails with "NaN:NaN"
HTC EVO 4G
Motorola Droid
Motorola Droid X (stock)

banditknight
13 Jan 2012, 2:18 AM
hello everybody,
there is a working solution on this thread :

Strange problem on iPad with displaying a Date property inside a Xtemplate
(http://www.sencha.com/forum/showthread.php?148715-Strange-problem-on-iPad-with-displaying-a-Date-property-inside-a-Xtemplate&p=714209)