Inverted zone in moment.timezone - node.js

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?

This is expected behavior. zone() returns the offset to UTC relative to the selected timezone.
http://momentjs.com/timezone/docs/#/how-to/mutator/

Related

Dialogflow console returning different result to when sent through the API (Where the wrong timezone is used)

I have a DialogFlow agent set up where one intent is used to schedule reminders. I can say something like:
"At 5pm remind me to go for a run"
And it returns the sentence to remind (in this case 'go for a run') as well as the time to set the reminder using #sys.date-time.
This works as intended, I am able to get the correct time because it just sends the time without a timezone attached.
When I use a command such as:
"In 15 minutes remind me to go for a run"
it sends the result as the time using the timezone, in this case, the incorrect one.
So right now, a result for the date-time using the API was:
2020-11-09T14:20:33+01:00
which is an hour more than it should be.
I have checked the DialogFlow agent's default time zone where it is set to:
(GMT0:00) Africa/Casablanca
Which I am fairly certain is the correct one for London time. However moving to a different timezone changes it and actually gives the correct one for the timezone (Just not my timezone)
Leaving me to wonder if this time zone is broken?
Regardless though, the Dialogflow console on the webpage returns the correct date-time but in a different format using 'startDateTime' and 'endDateTime', something that the agent does not do when sent using the API.
I have checked all configurations within the program and cannot find any evidence of any code giving a new timezone and in fact have tried to add the London timezone when a query is sent but this does not resolve the issue.
Does anyone have any advice on how to solve this?
EDIT:
After receiving a good suggestion from a user I am reminded of the most puzzling part of this issue. Chaning the timezone to GMT -1:00 vs 0:00 actually having a difference of two hours.
Around 1pm I queried it to get the time in 15 minutes.
When it was set to GMT-1:00 Atlantiv/Cape_Verde the time returned is:
2020-11-10T12:21:15-01:00
When it was set to GMT0:00 Africa/Casablanca the time returned is:
2020-11-10T14:22:07+01:00
Neither is the correct time and despite the timezone suggesting a 1 hour difference, it is actually 2 hours apart.
For London the correct timezone should be GMT -1, Casablanca Africa is GMT+1, I used this web page to determine this.
If you are in London is recommended to configure your agent to sue the correct time zone (GMT-1).

momentjs endOf('month') does not deliver last day of month

When I invoke the following code
moment('2020-01-01T00:00:00Z').endOf('month').utc().format()
I get the result
'2020-01-01T07:59:59Z'
when I would have expected to see
'2020-01-31T23:59:59Z'
Is this a bug or am I not using the API correctly?
I think the problem is you used endOf before you convert the Date in UTC.
You pass this Date : 2020-01-01T00:00:00Z but the browser understand it with your timezone so the "real date" is 2019-12-31T15:00:00Z.
So you must convert it to UTC first and then proceed your change/call/etc.
So, I tried that and it worked ! Tell me if the problem persist.
moment('2020-01-01T00:00:00Z').utc().endOf('month').format()

TZD database missing transitions?

I'm using version 'TZDB: 2018c (mapping: 13290)' of the TZD db however when I ask for Pacific/Auckland timezone information using either
VTimeZone.FromTzId(tzdbId);
or
VTimeZone.FromTzId(tzdbId, earliestDateTimeToSupport, true);
If I use 2008-01-01 as earliestDateTimeToSupport I'll get the current daylight saving details and recurrence rules. If however I use any date after that or NO date I'll get UTC -11 (WHEN was that rule last in play??? not while I've been alive.) and the recurrence rule looks all wrong. Can anyone advise if this is the DB or something I'm likely to be doing?
Australia/Sydney seems to behave properly... they've had a timezone change during 2008 and that rule comes through... and I'm not going to test them all but I think this is just a fault with NZDST for dates post (ish) 2009-1-1.

why is output of date function on node.js server wrong?

When date was 2018-03-21 19:40, i tried following code
var date = new Date();
console.log(date);
Output :
2018-03-21T16:40:53.755Z
Server is missing for 3 hours as you see. I fixed it by adding 3 hours but I think it's not a good way. How can i fix this problem with better way ?
I don't think the date is incorrect, if you look closely at the format it is being printed, it has a Z at the end, which means:
A suffix which, when applied to a time, denotes a UTC offset of 00:00;
often spoken "Zulu" from the ICAO phonetic alphabet representation of
the letter "Z".
I guess you are in a place separated by 3 hours from UTC.
Node.js uses this format to print Date objects by default, but you can print your local time using toLocaleString():
console.log(date.toLocaleString());
Your server is most likely in another time zone.

Timex - Getting the timezone information from DateTime

I am looking for a way to get the timezone information back from a date time.
iex(13)> t = Timex.now("America/Los_Angeles")
#<DateTime(2016-10-23T12:45:34.697369-07:00 America/Los_Angeles)>
iex(14)> Timex.<given_t_return_timezone>??
Given t, I want back "America/Los_Angeles" again.
I knew it had to be easy. Rather than looking at Timex for this, we can simply do:
t.time_zone
This is part of Elixir itself since t is a DateTime.

Resources