Dumas
16 Nov 2012, 6:14 PM
The writeDate function tries to read the dateFormat with field.dateFormat instead of field.getDateFormat(), and there is no support for null
REQUIRED INFORMATION
Ext version tested:
Sencha Touch 2.1.1
Browser versions tested against:
-
DOCTYPE tested against:
-
Description:
See provided solution
Steps to reproduce the problem:
Input a date with a dateFormat config.
Try saving of date values null/undefined.
The result that was expected:
Format according to dateFormat
The result that occurs instead:
All dates are formated as timestamps, null and undefined results in an error.
Test Case:
Ext.define('Bancha.model.JsonWithDateTimeTestModel', {
extend: 'Ext.data.Model',
config: {
idProperty:'id',
fields:[
{
name:'id',
type:'int'
},{
name:'datetime',
type:'date',
dateFormat:'Y-m-d H:i:s'
},{
name:'date',
type:'date',
dateFormat:'Y-m-d'
},{
name:'nulldate',
type:'date',
dateFormat:'Y-m-d'
}
]
}
});
// create a writer for testing
var writer = Ext.create('Bancha.data.writer.Json');
// sample record
var record = Ext.create('Bancha.model.JsonWithDateTimeTestModel', {
id : 1,
date : '2012-11-30',
datetime : '2012-11-30 10:00:05',
nulldate : null
});
// test
expect(writer.getRecordData(record).date).toEqual('2012-11-30');
expect(writer.getRecordData(record).datetime).toEqual('2012-11-30 10:00:05');
expect(writer.getRecordData(record).nulldate).toBeNull();
HELPFUL INFORMATION
Debugging already done:
yes, see fix
Possible fix:
writeDate: function(field, date) {
var dateFormat = field.getDateFormat() || 'timestamp'; // <-- fixed this line
switch (dateFormat) {
case 'timestamp':
return date.getTime()/1000;
case 'time':
return date.getTime();
default:
if(date===null || !Ext.isDefined(date)) { // <-- added support for null and undefined
return date;
}
return Ext.Date.format(date, dateFormat);
}
}
REQUIRED INFORMATION
Ext version tested:
Sencha Touch 2.1.1
Browser versions tested against:
-
DOCTYPE tested against:
-
Description:
See provided solution
Steps to reproduce the problem:
Input a date with a dateFormat config.
Try saving of date values null/undefined.
The result that was expected:
Format according to dateFormat
The result that occurs instead:
All dates are formated as timestamps, null and undefined results in an error.
Test Case:
Ext.define('Bancha.model.JsonWithDateTimeTestModel', {
extend: 'Ext.data.Model',
config: {
idProperty:'id',
fields:[
{
name:'id',
type:'int'
},{
name:'datetime',
type:'date',
dateFormat:'Y-m-d H:i:s'
},{
name:'date',
type:'date',
dateFormat:'Y-m-d'
},{
name:'nulldate',
type:'date',
dateFormat:'Y-m-d'
}
]
}
});
// create a writer for testing
var writer = Ext.create('Bancha.data.writer.Json');
// sample record
var record = Ext.create('Bancha.model.JsonWithDateTimeTestModel', {
id : 1,
date : '2012-11-30',
datetime : '2012-11-30 10:00:05',
nulldate : null
});
// test
expect(writer.getRecordData(record).date).toEqual('2012-11-30');
expect(writer.getRecordData(record).datetime).toEqual('2012-11-30 10:00:05');
expect(writer.getRecordData(record).nulldate).toBeNull();
HELPFUL INFORMATION
Debugging already done:
yes, see fix
Possible fix:
writeDate: function(field, date) {
var dateFormat = field.getDateFormat() || 'timestamp'; // <-- fixed this line
switch (dateFormat) {
case 'timestamp':
return date.getTime()/1000;
case 'time':
return date.getTime();
default:
if(date===null || !Ext.isDefined(date)) { // <-- added support for null and undefined
return date;
}
return Ext.Date.format(date, dateFormat);
}
}