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.
  1. #1
    Sencha User Dumas's Avatar
    Join Date
    Dec 2008
    Location
    Vienna, Austria
    Posts
    583
    Vote Rating
    9
    Dumas will become famous soon enough

      0  

    Default 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);
            }
        }

  2. #2
    Sencha - Senior Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,218
    Vote Rating
    1046
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default

    Thanks for the report! I have opened a bug in our bug tracker.

Thread Participants: 1