[Editor 1.5.4] TimeZone bug with Date Picker

[Editor 1.5.4] TimeZone bug with Date Picker

mtl-purchasingmtl-purchasing Posts: 2Questions: 1Answers: 0

Hello, it looks like there is a bug with the date picker when the client's browser is in certain time zones (i.e. UTC-5, UTC-8).

Here are the repro steps:

  1. Change your timezone to UTC-5 (Eastern Standard Time) or any time zone before UTC (UTC-X)
  2. Restart browser (so timezone changes take place)
  3. Go to the DatePicker Example
  4. Select 'New' and edit one of the date fields
  5. Select February 1st, 2016
  6. Edit the field again, and press the 'back one month' button
  7. The problem is that the month changes to January 2015 instead of January 2016

A similar problem occurs if you select December 1st, 2016. If you move one month ahead, it moves to January 2016 and not January 2017.

Note that if you select any day other than the first day of the month, there is no problem.

I think the bug is when Editor is converting dates to UTC. If you convert Feburary 1st, 2016 00h00 to UTC, it ends up being January 31st 19h00, 2016. The datepicker converts this back to Feb 1st. However if you subtract a month, you get Dec 31st 2015, and the datepicker takes that year even if it converts the day to Jan 1st.

Please let me know if you can repro, and if there are any workarounds that I could implement. Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin

    Thanks for letting me know about this. I'll dig into this issue and post back first thing tomorrow.

    Allan

  • mtl-purchasingmtl-purchasing Posts: 2Questions: 1Answers: 0
    edited February 2016

    Hi Allan,

    I spent some more time with the code after I posted this and made 3 small edits that seem to fix the issue for me.

    In dataTables.editor.js I changed lines 7040-7041 from:

    that.s.d.setFullYear( button.data('year') );
    that.s.d.setUTCMonth( button.data('month') );
    

    to:

    that.s.d.setUTCMonth( button.data('month') );
    that.s.d.setUTCFullYear( button.data('year') );
    

    And I also changed the this.s.display.getFullYear() to this.s.display.getUTCFullYear() in the _setCalander and _setTitle functions.

    This works for me, but I'm not 100% sure if it works completely. I'd be interested to see if you come to the same solution. Thanks!

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Answer ✓

    Hi,

    Thanks for the update! I concur on all points. There was also one other setFullYear which needed to be updated to use UTC time.

    The fixes will be in Editor 1.5.5 which I expect to drop tomorrow.

    Regards,
    Allan

This discussion has been closed.