-
Notifications
You must be signed in to change notification settings - Fork 837
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
Unix timestamps are parsed incorrectly when using 'x' or 'X' with moment.tz #347
Comments
Indeed, changing the time zone, mode, or offset should not change the underlying timestamp. Keep in mind that if the input is numeric, then you can use this form, which works: moment.tz(1464194866106, 'America/New_York') Likewise, the |
It looks like a fairly quick fix would be to alter the
to:
to check the incoming format for those specific values. I believe that's what the While that works, it doesn't seem like the "correct" approach. I'm not familiar enough with the purpose of the
So perhaps the correct approach -- instead of checking
I'm happy to do a PR to fix this, I'm just not entirely sure of the correct approach (because I'm not entirely sure why |
I never write code for moment timezone, only core, so please don't take my word for anything. This code is Tim's territory. That said, what _a is is the initial array of values used to construct a date. var some;
if (Array.prototype.some) {
some = Array.prototype.some;
} else {
some = function (fun) {
var t = Object(this);
var len = t.length >>> 0;
for (var i = 0; i < len; i++) {
if (i in t && fun.call(this, t[i], i, t)) {
return true;
}
}
return false;
};
}
export { some as default }; Then it's invoked this way: var parsedParts = some.call(flags.parsedDateParts, function (i) {
return i != null;
}); Also of note, you could use the value _pf.parsedDateParts that was added to 2.13.0. This is an array of the actual date parts parsed from the initial format (_a is an array that has had default data filled in). |
Thanks @maggiepint -- that's super helpful. Given that, I did some more digging. It sounds like it would be ideal to use The But now I'm thinking the safest approach probably is to simply check explicitly for the 'X' or 'x' format. There doesn't seem to any easier/global way to answer the question: "was this moment initially created using an absolute time?". And relying on the values in |
Hmmm... shouldn't this also then affect ISO input with an explicit moment.tz("2016-05-25T16:47:46.106Z", 'YYYY-MM-DD[T]HH:mm:ss.SSSZ', true, 'America/New_York').toISOString()
// "2016-05-25T16:47:46.106Z" Perhaps because |
@mj1856 The So I believe the current behavior is correct (if I'm understanding correctly):
|
When parsing a unix timestamp (milliseconds since the epoch),
moment.tz
seems to parse the timestamp, then modify it by applying an offset? At least I think that's what is happening. Example:I would expect this to simply output the original timestamp, but it actually outputs
1464209266106
, which is a 240 minute difference (or, the timezone offset for the given timezone).On the other hand, this:
outputs the correct and expected value of
1464194866106
. It's late, so I feel like I must be missing something here. But a timestamp is a timestamp -- so parsing it in the context of a timezone shouldn't change the underlying timestamp value in any way..The text was updated successfully, but these errors were encountered: