-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Bump moment-timezone #12201
Bump moment-timezone #12201
Conversation
issue TryGhost#10870 The cause of the problem: there were 2 installations of moment-timezone. And moment-timezone overrides updateOffset function of moment. And the moment was calling the wrong one because there were 2 of them. I fixed yarn.lock to install only one of them.
@sainthkh moment-timezone is intentionally held back due to buggy behaviour when upgrading that is not picked up by tests. There needs to be a deeper investigation and heavily verified behaviour because those bugs cause invalid date/time data to be stored in the database with a lot of knock-on effects and difficult recovery.
Only 1 version is currently installed by forcing the older version in package.json |
Thanks for telling me about When After reading the Now, we have only one moment-timezone. Lines 6197 to 6202 in 308e2c5
|
@sainthkh having two versions is not the source of the problem. There are changes in moment-timezone and moment in the higher versions that cause bugs due to global timezone setting not being respected |
Actually, it is. Let me explain in more detail.
Ghost/core/server/overrides.js Lines 18 to 25 in 8aac74b
To prove this, let's experiment this:
This 2 experiments tell us that the bug has nothing to do with the version of the Now, let's check what happens when we change the version number from 0.5.23 to 0.5.31 in the Then, there's an another copy of This happens a lot in nodejs projects and it is not a problem in most cases. But In momentjs constructor code below, there is a function called // Moment prototype object
export function Moment(config) {
copyConfig(this, config);
this._d = new Date(config._d != null ? config._d.getTime() : NaN);
if (!this.isValid()) {
this._d = new Date(NaN);
}
// Prevent infinite loop in case updateOffset creates new moment
// objects.
if (updateInProgress === false) {
updateInProgress = true;
hooks.updateOffset(this);
updateInProgress = false;
}
} This is defined as empty in momentjs like below: // This function will be called whenever a moment is mutated.
// It is intended to keep the offset in sync with the timezone.
hooks.updateOffset = function () {}; But it is defined in moment.updateOffset = function (mom, keepTime) {
var zone = moment.defaultZone,
offset;
if (mom._z === undefined) {
if (zone && needsOffset(mom) && !mom._isUTC) {
mom._d = moment.utc(mom._a)._d;
mom.utc().add(zone.parse(mom), 'minutes');
}
mom._z = zone;
}
if (mom._z) {
offset = mom._z.utcOffset(mom);
if (Math.abs(offset) < 16) {
offset = offset / 60;
}
if (mom.utcOffset !== undefined) {
var z = mom._z;
mom.utcOffset(-offset, keepTime);
mom._z = z;
} else {
mom.zone(offset, keepTime);
}
}
}; This function overrides the momentjs's Note: The problem with these 2 copies of Because of this, the global setting was ignored. And I fixed this by reorganizing As you might have noticed, this PR passed all the tests. It means this PR bumps This PR meets all 4 conditions of the issue:
After writing all this, I realized that my summaries in the original comment of this PR and the commit message were too brief to explain why it solves the problem. I hope this explains why this is the solution to the problem. And thank you for the review. If there's anything I missed, please tell me. Let's fix it together. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Closes #10870.
It happened because there were 2 versions of
moment-timezone
installed in the project.yarn test
andyarn lint
)More info can be found by clicking the "guidelines for contributing" link above.