Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using both moment and moment tz

Tags:

I have recently added moment-timezone to my project. Now that I've started using it, I notice I have replaced nearly all my

import * as moment from "moment"  

with

import * as moment from "moment-timezone"  

I don't see any reason to keep moment around. Is there any limitation I should be aware of before removing it?

like image 413
Scipion Avatar asked Apr 09 '18 09:04

Scipion


People also ask

Do I need both moment and moment-timezone?

Moment-timezone is a separate npm module from moment, but moment-timezone depends on moment under the hood. So you can install moment-timezone by itself, or both moment and moment-timezone. Once you install moment-timezone, you can require() it in and use it like you would use moment.

What is difference between moment and moment-timezone?

The moment.tz constructor takes all the same arguments as the moment constructor, but uses the last argument as a time zone identifier. while tz() is to convert a moment object to a given timezone.

Is moment-timezone deprecated?

This format is deprecated and will be removed in future.


1 Answers

Remove moment as a separate package in your package.json and reference moment-timezone whenever you need an instance of the moment object. In fact, if you don't and you're referencing both packages separately, you'll be loading two largely identical versions of moment.

The documentation referenced by @RobG in his comment is correct, it's just that the moment-timezone package itself loads moment as a dependency.

like image 184
ajbeaven Avatar answered Sep 20 '22 17:09

ajbeaven