Answers to Wrong date value in firefox ( 1 )

  1. 2017-01-07 08:01

    Your issue seems to be with how browsers apply daylight saving time. In Tehran, clocks move forward for daylight saving at midnight at the start of 22 March, 2017. So 2017-03-22 00:00:00 instantly becomes 2017-03-22 01:00:00.

    It seems that Firefox does not apply daylight saving to exactly midnight, whereas Chrome does. It seems to apply the wrong offset (it actually subtracts an hour from standard time) until 01:00:

    new Date(2017,2,22,0,59); // Tue Mar 21 2017 23:59:00 GMT+0330 (IRST)
    new Date(2017,2,22,1,0);  // Wed Mar 22 2017 01:00:00 GMT+0430 (IRST)
    

    And it uses the same time zone name abbreviation for both. Report it as a bug.

    There are many minor such issues with browser Date objects. If you depend on client Date behaviour, be prepared to discover them.

    Edit

    It seems you can work around this using Date.UTC:

    // One minute to midnight in Tehran, daylight saving not applied
    new Date(Date.UTC(2017,2,21,20,29)); // Tue Mar 21 2017 23:59:00 GMT+0330 (IRST)
    // At midnight in Tehran, daylight saving applied
    new Date(Date.UTC(2017,2,21,20,30)); // Wed Mar 22 2017 01:00:00 GMT+0430 (IRST)
    

    which still has the incorrect timezone abbreviation but you should never rely on that anyway, the rest seems correct.

Leave a reply to - Wrong date value in firefox

◀ Go back