Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.format('z') doesn't work for 0.5.13 if other dependency uses 0.5.25 #749

Closed
marneborn opened this issue May 11, 2019 · 2 comments
Closed

Comments

@marneborn
Copy link

We are currently using moment-timezone@0.5.13 but we have a dependency on 0.5.25.
The two do not play nicely together.

The .format('z') gives "UTC" when using the @0.5.13 version after the 0.5.25 version has been required. Anything <=0.5.23 seems to have this problem.

To reproduce

mkdir moment-tz-problem
cd moment-tz-problem
npm init --force
yarn add moment-timezone@0.5.13
yarn add ical-generator@1.7.1
$ node -e "const moment = require('moment-timezone'); console.log(moment().tz('US/Eastern').format('z'));"
EDT
$ node -e "require('ical-generator'); const moment = require('moment-timezone'); console.log(moment().tz('US/Eastern').format('z'));"
UTC
yarn list v1.9.4
├─ ical-generator@1.7.1
│  ├─ moment-timezone@^0.5.25
│  └─ moment-timezone@0.5.25
│     └─ moment@>= 2.9.0
├─ moment-timezone@0.5.13
│  └─ moment@>= 2.9.0
└─ moment@2.24.0

The yarn.lock

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


ical-generator@1.7.1:
  version "1.7.1"
  resolved "https://registry.yarnpkg.com/ical-generator/-/ical-generator-1.7.1.tgz#8f994a44d2bb9da7b0f941723557fa6dbbf7c5a8"
  dependencies:
    moment-timezone "^0.5.25"

moment-timezone@0.5.13:
  version "0.5.13"
  resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.13.tgz#99ce5c7d827262eb0f1f702044177f60745d7b90"
  dependencies:
    moment ">= 2.9.0"

moment-timezone@^0.5.25:
  version "0.5.25"
  resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.25.tgz#a11bfa2f74e088327f2cd4c08b3e7bdf55957810"
  dependencies:
    moment ">= 2.9.0"

"moment@>= 2.9.0":
  version "2.24.0"
  resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
@marneborn marneborn changed the title .format('z') doesn't work for 0.5.13 if othere dependency uses 0.5.25 .format('z') doesn't work for 0.5.13 if other dependency uses 0.5.25 May 11, 2019
@naz
Copy link

naz commented Jul 3, 2019

Have found a similar issue when running in Node environment. The problem started from version 0.5.24 and the formatting for dates has now changed. For example, when having moment-timezone @ 0.5.23, the following works:

moment(new Date('2013-10-18T23:58:44.000Z')).format()
-> "2013-10-18T23:58:44Z"

when bumping the version to 0.5.24 the output is:

moment(new Date('2013-10-18T23:58:44.000Z')).format()
"2013-10-19T01:58:44+02:00"

The change, I suspect, that has affected the behavior is this commit - 6b7b558

I wasn't successful to reproduce it in a clean environment though (without other dependencies), but it has happened in Ghost core code after merging this version bump - TryGhost/Ghost#10837, build that failed is https://travis-ci.org/TryGhost/Ghost/jobs/553428813 and the test that is failing is this one - https://github.com/TryGhost/Ghost/blob/cf499c3/core/test/regression/importer/importer_spec.js#L142.

Think it has to do with having moment.tz.setDefault('UTC') not being persisted globally for all moment uses.

naz added a commit to naz/Ghost that referenced this issue Jul 3, 2019
@ichernev
Copy link
Contributor

When you use a Date to feed to moment, it can't possibly know which timezone you're in. I understand the behavior changed, but you don't get any guarantees when you use a Date. Re-open if there is still an issue with later versions, and try to reference the docs (if you think we're doing something wrong).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants