3

I am using nodejs and recently started using moment.timezone to get the timezone offset. I have the following code:

console.log(moment.tz(new Date(), 'Europe/Athens').zone()); // Prints -120

The timezone for 'Europe/Athens' is GMT+2 so i would expect getting '120' and not '-120' and thats what other timezone libraries do.

This issue caused me a serious head scratching bug. It was really easy to fix it once found the problem by just inverting the timezone offset.

Is this a bug on the specific library, or is there a different way to think of zones and offsets? Is there a standard about zone offsets?

SamT
  • 10,374
  • 2
  • 31
  • 39
gtsouk
  • 5,208
  • 1
  • 28
  • 35

1 Answers1

1

This is expected behavior. zone() returns the offset to UTC relative to the selected timezone.

http://momentjs.com/timezone/docs/#/how-to/mutator/

SamT
  • 10,374
  • 2
  • 31
  • 39
  • It makes sense, though this is not documented at all. Is anyone else using this notation? – gtsouk Mar 08 '14 at 21:44
  • 1
    This is the convention for JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset – SamT Mar 08 '14 at 21:49
  • Not at all: "returns the time-zone offset from UTC, in minutes, for the current locale". – gtsouk Mar 08 '14 at 21:54
  • It also explains in there what it means if the number is negative. In the example, they show that `UTC+10` (Austria Eastern Standard Time) is `-600`. – SamT Mar 08 '14 at 22:02
  • See also: [Why does JavaScript Date.getTimezoneOffset() consider “-05:00” as a positive offset?](http://stackoverflow.com/q/21102435/634824) – Matt Johnson-Pint Mar 10 '14 at 16:00