Giter Site home page Giter Site logo

Comments (1)

timrwood avatar timrwood commented on May 24, 2024

This is unfortunately a feature.

When moment#zone was first added in version 1.2.0, it was just a wrapper for Date.prototype.getTimezoneOffset, which actually has some weirdness to it.

The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead. For example, if your time zone is UTC+10 (Australian Eastern Standard Time), -600 will be returned.

via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

Then, in version 2.1.0, the ability to set the offset using moment#zone was added. https://gist.github.com/timrwood/b8c2d90d528eddb53ab5#added-ability-to-set-offset-with-momentzone

In order to keep compatibility with the output of moment#zone, a numeric input to moment#zone actually needs to be the negative of the string input.

moment().zone(240).format();      // 2014-06-24T12:41:16-04:00
moment().zone('-04:00').format(); // 2014-06-24T12:41:16-04:00

In hindsight, it would have been better to invert the output from Date.prototype.getTimezoneOffset, but I didn't realize it was backwards until it was far too late.

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.