Skip to content

Cannot select the day on which daylight savings starts #219

Closed
@davideaves

Description

@davideaves

Daylight savings starts on 27-Sep-2015 this year in New Zealand. When attempting to select this date by clicking on it in the datepicker the previous day is selected and highlighted instead. Selecting any other date works fine. The same behaviour is exhibited on the demo page.

The problem occurs in this code in the setTime() function:

var newDate = new Date(tempDate.getTime() + (tempDate.getTimezoneOffset() * 60000));

Replacing this with the following code resolves the issue for us:

var newDate = new Date(tempDate.getUTCFullYear(), tempDate.getUTCMonth(), tempDate.getUTCDate(), tempDate.getUTCHours(), tempDate.getUTCMinutes(), tempDate.getUTCSeconds(), tempDate.getUTCMilliseconds());

I note that getUTCTime() also uses Date.getTimezoneOffset() to adjust a date to UTC, but I'm unsure if this is a problem in that context. I haven't got my head around what it is doing and the picker seems to be behaving correctly without modifying getUTCTime().

Additional background:

New Zealand is +12 hours from UTC, or +13 hours during daylight savings. When selecting 27-Sep-2015 in the unmodified setTime():
unixDate is 1443312000000
tempDate is Sun Sep 27 2015 13:00:00 GMT+1300 (New Zealand Daylight Time)
newDate is Sat Sep 26 2015 23:00:00 GMT+1200 (New Zealand Standard Time)

newDate should instead be Sun Sep 27 2015 00:00:00 GMT+1200 (New Zealand Standard Time)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions