Ext.data.writer.Json doesn't use dateFormat
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:
Browser versions tested against:
DOCTYPE tested against:
Description:
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:
Code:
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:
Possible fix:
Code:
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);
}
}