-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
const moment = require("moment-timezone"); | ||
const { getApp } = require("../utils/test"); | ||
const evermarch = require("./evermarch"); | ||
|
||
|
@@ -26,11 +27,30 @@ describe("The Evermarch", () => { | |
}); | ||
|
||
it("is correct starting March 2, 2020", () => { | ||
// Go very slightly ahead of midnight because at exactly midnight, the diff | ||
// rounds to exactly one day, so the ceil() logic doesn't yet count it as an | ||
// extra day. But a millisecond later, it will. This seems fine. Millisecond | ||
// precision is plenty. | ||
jest.setSystemTime(Date.parse("2020-03-02T00:00:01Z")); | ||
jest.setSystemTime( | ||
moment.tz("2020-03-02T00:00:00", "America/New_York").toDate(), | ||
); | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
|
||
const message = { | ||
message: { thread_ts: "thread timestamp" }, | ||
say: jest.fn(), | ||
}; | ||
|
||
evermarch(app); | ||
const handler = app.getHandler(); | ||
handler(message); | ||
|
||
expect(message.say).toHaveBeenCalledWith({ | ||
icon_emoji: ":calendar-this-is-fine:", | ||
text: "Today is March 2, 2020, in the Evermarch reckoning.", | ||
thread_ts: "thread timestamp", | ||
}); | ||
}); | ||
|
||
it("is correct at the very end of March 2, 2020", () => { | ||
jest.setSystemTime( | ||
moment.tz("2020-03-02T23:59:59", "America/New_York").toDate(), | ||
); | ||
|
||
const message = { | ||
message: { thread_ts: "thread timestamp" }, | ||
|
@@ -48,12 +68,31 @@ describe("The Evermarch", () => { | |
}); | ||
}); | ||
|
||
it("is correct at the very start of March 3, 2020", () => { | ||
jest.setSystemTime( | ||
moment.tz("2020-03-03T00:00:00", "America/New_York").toDate(), | ||
); | ||
|
||
const message = { | ||
message: { thread_ts: "thread timestamp" }, | ||
say: jest.fn(), | ||
}; | ||
|
||
evermarch(app); | ||
const handler = app.getHandler(); | ||
handler(message); | ||
|
||
expect(message.say).toHaveBeenCalledWith({ | ||
icon_emoji: ":calendar-this-is-fine:", | ||
text: "Today is March 3, 2020, in the Evermarch reckoning.", | ||
thread_ts: "thread timestamp", | ||
}); | ||
}); | ||
|
||
it("is correct in the further future from March 1, 2020", () => { | ||
// Go very slightly ahead of midnight because at exactly midnight, the diff | ||
// rounds to exactly one day, so the ceil() logic doesn't yet count it as an | ||
// extra day. But a millisecond later, it will. This seems fine. Millisecond | ||
// precision is plenty. | ||
jest.setSystemTime(Date.parse("2024-10-15T00:00:01Z")); | ||
jest.setSystemTime( | ||
moment.tz("2024-10-15T01:00:00", "America/New_York").toDate(), | ||
); | ||
|
||
const message = { | ||
message: { thread_ts: "thread timestamp" }, | ||
|
@@ -72,7 +111,9 @@ describe("The Evermarch", () => { | |
}); | ||
|
||
it("is gets to March 2020, 2020, on the expected date", () => { | ||
jest.setSystemTime(Date.parse("2025-09-10T12:00:00Z")); | ||
jest.setSystemTime( | ||
moment.tz("2025-09-10T00:00:00", "America/New_York").toDate(), | ||
); | ||
Comment on lines
-75
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
const message = { | ||
message: { thread_ts: "thread timestamp" }, | ||
|
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.