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

Strict mode and Unix timestamp. #555

Closed
prototype23 opened this issue Oct 30, 2017 · 5 comments
Closed

Strict mode and Unix timestamp. #555

prototype23 opened this issue Oct 30, 2017 · 5 comments

Comments

@prototype23
Copy link

prototype23 commented Oct 30, 2017

// Correct
moment.tz(1509383108 * 1000, 'America/Caracas').format(); // "2017-10-30T13:05:08-04:00"
moment.tz(1509383108 * 1000, 'Europe/Athens').format(); // "2017-10-30T19:05:08+02:00"

// Wrong
moment.tz(1509383108, 'X', true, 'America/Caracas').format(); // "2017-10-30T17:05:08-04:00"
moment.tz(1509383108, 'X', true, 'Europe/Athens').format(); // "2017-10-30T17:05:08+02:00"

I was expecting a time shift with the last two examples but only tz is changed is that a bug?

moment version: 2.18.1
moment.tz version: 0.5.13

@mattjohnsonpint
Copy link
Contributor

I can't reproduce this. It returns the correct results in both cases. Can you please create a jsFiddle (or similar) to reproduce?

Thanks.

@mattjohnsonpint
Copy link
Contributor

Also, have you changed the default time zone? We have a bug open on that in #338.

@prototype23
Copy link
Author

prototype23 commented Nov 2, 2017

Hi Matt, thanks for the feedback.

No i did not changed the default time zone. Here is a jsbin example https://jsbin.com/yumosen/edit?js,output and here is a screenshot of the results on my computer:

moment-tz_00

Maybe is a misunderstanding, on my part. On the docs i can see now clearly:

"There are two interfaces for using time zones with Moment.js.moment.tz(..., String) is used to create a moment with a time zone, and moment().tz(String) is used to change the time zone on an existing moment."

Maybe i confused by this part:
"Unix timestamps and Date objects refer to specific points in time, thus it doesn't make sense to use the time zone offset when constructing. Using moment.tz(Number|Date, zone) is functionally equivalent to moment(Number|Date).tz(zone)."
Which the later, refers in case of unix timestamps only!

Aris

@prototype23
Copy link
Author

Hmm but wait on both cases (1,2 and 3,4) i'm using the moment.tz() method. On the 1,2 shifts the time and on the (3,4) is not.

@mattjohnsonpint
Copy link
Contributor

Ok, I'm dumb.. This was indeed fixed already in moment-timezone 0.5.14 and missed in the release notes. PR #348 fixed it. Please upgrade.

(Also I note your moment 2.18.1 can upgrade to 2.19.1 also)

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

No branches or pull requests

2 participants