Skip to content

setDate() returns wrong value in a DST scenario #56

@dogusyildiz

Description

@dogusyildiz

The result of the setDate() method returns the wrong value in the following Daylight Saving Time (DST) scenario.

For Eastern Time Zone, DST happens at 2022-03-13 02:00 and the time immediately becomes 2022-03-13 03:00 https://www.timeanddate.com/time/change/usa

In this case, we have a Date instance of '2022-03-12T02:30:00.000-05:00' and add 1 day to the date. The expected result is '2022-03-13T03:30:00.000-04:00' because there is no 02:30 AM on the 13th. But instead, the result is '2022-03-13T01:30:00.000-05:00'

Please see below the outputs from the native Date class and from timezone-mock

new Date(new Date('2022-03-12T02:30:00.000-05:00').setDate(13));
// > Sun Mar 13 2022 03:30:00 GMT-0400 (Eastern Daylight Time)

timezoneMock.register('US/Eastern');
new Date(new Date('2022-03-12T02:30:00.000-05:00').setDate(13));
// > MockDate {d: Sun Mar 13 2022 01:30:00 GMT-0500 (Eastern Standard Time)}
timezoneMock.unregister();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions