-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fixes a couple of bugs related to UTC offsets and day-counting. #569
Conversation
|
||
module.exports = (robot) => { | ||
robot.message(/evermarch/i, ({ message, say }) => { | ||
const now = moment.tz("America/New_York"); | ||
|
||
const days = Math.ceil(moment.duration(now.diff(march1)).as("days")); | ||
const days = now.diff(march1, "days") + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculate the diff as days instead of as milliseconds. This will take leap years and stuff into account. Then add one because the diff between March 1 and March 1 is 0 days, but it's the 1st of March.
jest.setSystemTime( | ||
moment.tz("2020-03-02T00:00:00", "America/New_York").toDate(), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests should be in eastern time too. And once we switch to calculating whole day diffs, we don't need the little offset to make things work. They just work!
jest.setSystemTime(Date.parse("2025-09-10T12:00:00Z")); | ||
jest.setSystemTime( | ||
moment.tz("2025-09-10T00:00:00", "America/New_York").toDate(), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this one used to have to be at noon in order to pass is, I think, because of issues with DST. The old millisecond-based diff was bound to drift over time, which we don't really want. So now we don't do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ew, time math
The Evermarch script mistakenly calculated time from March 1, 2020, midnight UTC, instead of midnight America/New_York as intended. Additionally, it was calculating the time difference in milliseconds and then dividing that into a number of days, which meant it was not accounting for leap years or DST.
Checklist:
N/A:
page has been updated if Charlie needs any new OAuth events or scopes
wiki page has been updated if new environment variables were introduced
or existing ones changed