-
16 Nov 2012 6:14 PM #1
Ext.data.writer.Json doesn't use dateFormat
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:- 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:
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:- yes, see fix
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); } }Roland Schütz
Senior Software Architect
---
Bancha Project - Seamless integrate CakePHP with ExtJS and Sencha Touch
-
19 Nov 2012 11:01 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
Thanks for the report! I have opened a bug in our bug tracker.
You found a bug! We've classified it as
TOUCH-3725
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote