1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default Answered: Dates being set back by 1 day

    Answered: Dates being set back by 1 day


    I stumbled on this post: http://stackoverflow.com/questions/9...matting-a-date

    Unfortunately, I can't go through and put in a specific parsing algorithm for every single grid/form I have.

    Why is it forcing a time zone on the date fields, and how can I get it to stop?

    I have a datecolumn, my time zone is -6 (CST), and it always pushes it back a day. For instance, if ExtJS receives "2012-02-02" from the server, it shows "2012-02-01".

  2. I think I found the problem; you specified format instead of dateFormat in your 'fields' declaration. Here's your code sample with the correction made, where it now gives the desired effect:

    Code:
    Ext.onReady(function() {
    
        store = new Ext.data.Store({
            fields: [ 
             {name: 'testId', type: 'int'}, 
             {name: 'received_on', type: 'date', dateFormat: 'Y-m-d'} 
            ],
            data: [ {testId: 1, received_on: '2012-02-04'} ]
        });
        
        console.log( Ext.util.Format.date(store.getAt(0).get('received_on')) );
    });

  3. #2
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default


    src/core/src/util/Format.js:

    Code:
    date: function (v, format) {  if (!v) {
        return "";
      }
      if (!Ext.isDate(v)) {
        v = new Date(Date.parse(v));
      }
      return Ext.Date.dateFormat(v, format || Ext.Date.defaultFormat);
    }
    This is kind of horrific.

    Code:
    Ext.util.Format.date('2012-02-02')
    "02/01/2012"

  4. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default


    This is really insane:

    Code:
    Ext.util.Format.date('02/04/2012')
    "02/04/2012"
    Code:
    Ext.util.Format.date('2012-02-04')
    "02/03/2012"

  5. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default


    bump

  6. #5
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    According to the API docs, what you're trying to do should work, so it looks to be a bug.

    However, when parsing String dates, I use Ext.Date.parse(), then Ext.util.Format.date() for formatting:

    Code:
    var javascriptDateObject = Ext.Date.parse('2012-02-04', 'Y-m-d');
    var stringDateFormatted = Ext.util.Format.date(javascriptDateObject, 'm/d/Y');

  7. #6
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default


    Well, the problem isn't that I'm parsing them incorrectly, it's that a datecolumn uses Ext.util.Format.date, which parses the dates incorrectly.

    Code:
    Ext.util.Format.date('2012-02-04')
    "02/03/2012"
    Code:
    Ext.util.Format.date('02-04-2012')
    "02/04/2012"
    This may be a bug, but I definitely can't wait fix a fix. Can I override Ext.util.Format the same way I would any other class? Or should I use Ext.apply?

  8. #7
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    Be sure that the Model which backs your grid's Store declares the incoming date format correctly:

    Code:
    Ext.define('MyApp.model.MyModel', {
      extend: 'Ext.data.Model',
      fields: [
         {name: 'someDateField', type: 'date', dateFormat: 'Y-m-d'}
      ]
    });

  9. #8
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default


    Ahh! I was desperately hoping the solution would be so simple. Unfortunately, it didn't change anything. Thank you for the suggestion.

    Programmers in Iceland that only write Icelandic apps are lucky - they don't deal with time zones ever.

  10. #9
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    If you would, please post a sample of the JSON used to populate your Store.

    Thx.

  11. #10
    Sencha User
    Join Date
    Feb 2011
    Posts
    35
    Answers
    2
    Vote Rating
    0
    nkezhaya is on a distinguished road

      0  

    Default


    Sure. Thank you again for taking the time to look at it.

    http://jsfiddle.net/AG9KM/1/

    Check the console. For me it shows, "02/03/2012". I'm CST (-0600).

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar