PDA

View Full Version : [CLOSED] dateFormat undefined



dsportes
19 Oct 2011, 3:28 AM
At line 15087 of sencha-touch-debug.js, the dateFormat method of a Date object is not defined.
It was OK in sencha 1

Jamie Avins
31 Oct 2011, 1:03 PM
Can you please provide more details on what youa re trying to do?

dsportes
1 Nov 2011, 9:27 AM
In sencha-touch-all-debug.js of sencha-touch-2.0.0.pr1 line 15087 the call of the method dateFormat failed because not defined for the date Object. This issue did not appear in sencha 1.
Just look at the text below:


Ext.define('Ext.util.Format', {
singleton: true,
defaultDateFormat: 'm/d/Y',
escapeRe: /('|\\)/g,
trimRe:

// LINES CUT HERE

date: function(v, format) {
if (!v) {
return "";
}
if (!Ext.isDate(v)) {
v = new Date(Date.parse(v));
}
return v.dateFormat(format || Ext.util.Format.defaultDateFormat);
}
});

In fact the issue is of course not here, the code is correct, but I came to dateFormat through this path.

Jamie Avins
1 Nov 2011, 10:50 AM
Sure, but we need a test case which can reproduce the issue so we can resolve it. What are you doing that causes the problem?

dsportes
2 Nov 2011, 1:15 AM
This the (quite) shortest case:
index.html:


<!DOCTYPE html>
<html>
<head>
<title>Test Sencha</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="sencha-touch.css" type="text/css">
<script type="text/javascript" src="sencha-touch-all-debug.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>

app.js (cut from your example)
Ext.require([
'Ext.Panel',
'Ext.Button',
'Ext.Toolbar',
'Ext.util.Format'
]);


Ext.application({
name: 'Test Sencha',
glossOnIcon: false,


launch: function() {

var f1 = function() {
var t = Ext.util.Format.date(new Date(), "Y-m-d H:i:s");
Ext.getCmp('result').setValue(t);
};

new Ext.Panel({
fullscreen: true,
id: 'content',
scroll: 'vertical',
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
text: 'XMLHTTP',
handler: f1
}]
},{
id: 'status',
xtype: 'toolbar',
dock: 'bottom',
title: "Tap a button above."
}],
items: [
{
xtype: 'textareafield',
label: 'Result',
id: 'result',
maxRows: 4,
name: 'Result'
}
]
});

var t = Ext.util.Format.date(new Date(), "Y-m-d H:i:s");
Ext.getCmp('result').setValue(t);
}
});
/*
function dateFormat(format, date) {
if (date == undefined) {
date = new Date();
}
if (typeof date == 'number') {
time = new Date();
time.setTime(date);
date = time;
} else if (typeof date == 'string') {
date = new Date(date);
}
var fullYear = date.getYear();
if (fullYear < 1000) {
fullYear = fullYear + 1900;
}
var hour = date.getHours();
var day = date.getDate();
var month = date.getMonth() + 1;
var minute = date.getMinutes();
var seconde = date.getSeconds();
var milliSeconde = date.getMilliseconds();
var reg = new RegExp('(d|m|Y|H|i|s)', 'g');
var replacement = new Array();
replacement['d'] = day < 10 ? '0' + day : day;
replacement['m'] = month < 10 ? '0' + month : month;
replacement['Y'] = fullYear;
replacement['Y'] = fullYear;
replacement['H'] = hour < 10 ? '0' + hour : hour;
replacement['i'] = minute < 10 ? '0' + minute : minute;
replacement['s'] = seconde < 10 ? '0' + seconde : seconde;
return format.replace(reg, function($0) {
return ($0 in replacement) ? replacement[$0] : $0.slice(1,
$0.length - 1);
});
}


Date.prototype.dateFormat = function (format) {
return dateFormat(format, this);
}
*/

Running this example throw an exception:
Uncaught TypeError: Object Wed Nov 02 2011 10:12:12 GMT+0100 (Paris, Madrid) has no method 'dateFormat'

Now just uncomment the dateFormat function and the prototype definition of dateFormat on Date: it works.
So the issue (at least in this release) is the lack of the dateFormat method on the prototype of Date.

NickT
4 Nov 2011, 11:33 AM
It looks as though you were internally converting to an Ext.Date in 1.1, whereas, now its just a JS Date...



I have a calendar field ux control that extends Ext.field.Field, and when I access the value (which i set as a js Date) in 1.1, its an Ext.Date, whereas, in 2.0, its a javascript Date...

In 1.1...

return this.value.format(this.dateFormat);

In 2.0

return Ext.Date.format(this.value, this.dateFormat)

dsportes
5 Nov 2011, 12:03 AM
Thanks for your help, it wasn't so obvious for me to find that.
Regards.