Git Product home page Git Product logo

Comments (1)

gilmoreorless avatar gilmoreorless commented on June 16, 2024 2

This is looking like a bug to me. Kazakhstan is unifying to a single time zone at that exact time (see #1095), so Asia/Almaty moves from UTC+6 to UTC+5 at the very start of March.

However, the way this should play out is:

  • 2023-02-29 23:59:59+06:00 is followed one second later by 2023-02-29 23:00:00+05:00 (so midnight hasn't actually happened).
  • One hour later, the zone hits 2023-03-01 00:00:00+05:00.
  • When you ask for 2023-03-01 00:00:00 you should be getting that later time ^.

Moment Timezone has a way of handling ambiguous times (e.g. when the same time happens twice), but that shouldn't be applying here. For Almaty, the times 23:00:00 to 23:59:59 will happen twice on Feb 29, but Mar 1 00:00:00 only happens once.

The curious thing is that other time zones that have had DST transitions at midnight (like Brazil) are handled correctly:

moment.tz('2019-02-16 23:00:00', 'America/Sao_Paulo').format(); // '2019-02-16T23:00:00-02:00'
moment.tz('2019-02-16 23:59:59', 'America/Sao_Paulo').format(); // '2019-02-16T23:59:59-02:00'
moment.tz('2019-02-17 00:00:00', 'America/Sao_Paulo').format(); // '2019-02-17T00:00:00-03:00'
// This last one is actually one hour later than the time above, due to ambiguities listed earlier

There's a poorly-documented data property to assist with the times that happen twice due to clock changes: moment.tz.moveAmbiguousForward. By default it's false (so the first instance of the duplicate time will be chosen), but setting it to true makes the library choose the later instance of the time. What's weird is that it does affect this Almaty time, even though midnight only happens once. 🤔

moment.tz.moveAmbiguousForward = false; // the default
moment.tz('2024-03-01 00:00:00', 'Asia/Almaty').format(); // '2024-02-29T23:00:00+05:00'

moment.tz.moveAmbiguousForward = true;
moment.tz('2024-03-01 00:00:00', 'Asia/Almaty').format(); // '2024-03-01T00:00:00+05:00'

I'll have to dig further to work out why this is happening only in this one case.

from moment-timezone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.