Possible bug with wrong "today" date being highlighted in datetime field

Possible bug with wrong "today" date being highlighted in datetime field

hisservanthisservant Posts: 5Questions: 3Answers: 0
edited May 2016 in Editor

Background:
- Using Editor 1.5.6 (both local install and on the example page)
- Issue appearing in US Eastern time zone at 8:30PM (UTC has entered next day when bug appears)

Details:
When using the default datetime field, the a new date appears properly but the wrong day is highlighted for 'today' - specifically, the next day is being highlighted. I have created an annotated screenshot that shows this issue appearing on the examples page:

https://i.imgur.com/3SXIbW2.jpg

Provisional fix:
The problem appears to be that day is UTC, while now is localized in dataTables.editor.js:7357. I seem to be able to solve this by editing dataTables.editor.js:7357 as follows:

[old line]:

today    = this._compareDates(day, now),

[new line]:

today    = this._compareDates(day, this._dateToUtc(now)),

Final notes:
I noticed some other threads that mentioned issues with the datetime, but couldn't find anything specifically mentioning this issue. Can you please confirm if this is an appropriate fix? If not, what change should be made?

Thank you for an excellent plugin.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,810Questions: 1Answers: 10,122 Site admin

    Hi,

    Thanks for posting this. Interestingly, this was an issue in 1.5.5 (with negative UTC offsets), which should have been fixed in 1.5.6. Specifically the _compareDates method you mentioned uses

    return this._dateToUtcString(a) === this._dateToUtcString(b);
    

    However, it sounds like there might be a double conversion happening with day (since it is UTC already), but not the now parameter.

    Let me dig into what exactly is going wrong here and get back to you.

    Allan

  • allanallan Posts: 61,810Questions: 1Answers: 10,122 Site admin
    Answer ✓

    I've just committed a fix to address this and it will be included in the next version of Editor.

    The change required was to change the now value to be UTC:

    now    = this._dateToUtc( new Date() ),
    

    rather than now = new Date() as it was before.

    Thanks for letting me know about this!

    Regards,
    Allan

  • hisservanthisservant Posts: 5Questions: 3Answers: 0

    Great, thanks!

This discussion has been closed.