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

Fixes a couple of bugs related to UTC offsets and day-counting. #569

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

mgwalker
Copy link
Member

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:

  • Code has been formatted with prettier

N/A:

  • The OAuth wiki
    page has been updated if Charlie needs any new OAuth events or scopes
  • The Environment Variables
    wiki page has been updated if new environment variables were introduced
    or existing ones changed
  • The dev wiki has been updated, e.g.:
    • local development processes have changed
    • major development workflows have changed
    • internal utilities or APIs have changed
    • testing or deployment processes have changed
  • If appropriate, the NIST 800-218 documentation has been updated

@mgwalker mgwalker requested a review from a team as a code owner January 16, 2025 15:10

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;
Copy link
Member Author

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.

Comment on lines +30 to +32
jest.setSystemTime(
moment.tz("2020-03-02T00:00:00", "America/New_York").toDate(),
);
Copy link
Member Author

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!

Comment on lines -75 to +116
jest.setSystemTime(Date.parse("2025-09-10T12:00:00Z"));
jest.setSystemTime(
moment.tz("2025-09-10T00:00:00", "America/New_York").toDate(),
);
Copy link
Member Author

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.

Copy link
Member

@Sgtpluck Sgtpluck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ew, time math

@mgwalker mgwalker merged commit 9391f2b into main Jan 16, 2025
7 checks passed
@mgwalker mgwalker deleted the mgwalker/fix-evermarch branch January 16, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants