Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment Timezone: UTC offset difference

I use the moment-timezone v.0.5.3-2016c library to calculate the UTC offset for a timezone:

var z = moment().tz("America/Los_Angeles");
z.utcOffset(); // -420 mins or -7 hours

// check if DST is shifted
z.isDSTShifted(); // false

But here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones the UTC offset for the America/Los_Angeles is -8 hours.

Moment uses the tzdb v.2016c and the wikipedia article too.

Well, why there are two different results here? And which result is right?

P.S.: there is the same difference for America/Kentucky/Monticello and Europe/Tiraspol, as well.

like image 959
Sergey Avatar asked Apr 29 '16 13:04

Sergey


2 Answers

Calling the moment creation function, moment() without any arguments returns the current moment in time. Since time zone offsets vary depending on what date and time they are attached to, your results will vary depending on when you call this function.

If you want to know whether or not the time is daylight saving time or not, use isDST. The isDSTShifted function is for dealing with invalid local times, not checking DST. It probably could have been named better.

like image 77
Matt Johnson-Pint Avatar answered Nov 02 '22 17:11

Matt Johnson-Pint


The USA is currently in DST (Daylight Savings Time). Therefore, I'd use the UTC DST Offset column, which shows -07:00.

like image 40
Scratch'N'Purr Avatar answered Nov 02 '22 17:11

Scratch'N'Purr