Skip to content

Commit

Permalink
Merge pull request #239 from beakerandjake/238-puzzle-unlock-time-is-…
Browse files Browse the repository at this point in the history
…wrong

238 puzzle unlock time is wrong
  • Loading branch information
beakerandjake authored Dec 1, 2023
2 parents 387102c + ff35240 commit f877685
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fixed issue with puzzle unlock time being 2pm EST instead of midnight EST ([#238](https://github.com/beakerandjake/advent-of-code-runner/issues/238))

## [1.6.0] - 2023-11-17
### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/validation/validatePuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const puzzleIsInFuture = (year, day) => {
if (year !== new Date().getFullYear()) {
return year > new Date().getFullYear();
}
const puzzleUnlockTimeUTC = Date.UTC(year, 11, day, 19);
const puzzleUnlockTimeUTC = Date.UTC(year, 11, day, 5);
return Date.now() < puzzleUnlockTimeUTC;
};

Expand Down
10 changes: 5 additions & 5 deletions tests/validation/validatePuzzle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ describe('validatePuzzle', () => {
expect(result).toBe(true);
});

// test literally every minute from midnight until unlock time.
[...Array(60 * 19).keys()].forEach((minutes) => {
// test literally every minute from UTC midnight until unlock time.
[...Array(60 * 5).keys()].forEach((minutes) => {
const year = 2022;
const day = 22;
const utcMidnightMs = new Date(year, 11, day).setUTCHours(0, 0, 0, 0);
const systemTime = new Date(utcMidnightMs + minutes * 60000);

test(`returns false - same day time is: ${systemTime.toISOString()}`, () => {
test(`returns true - same day time is: ${systemTime.toISOString()}`, () => {
jest.setSystemTime(systemTime);
expect(puzzleIsInFuture(year, day)).toBe(true);
});
});

// test literally every minute from unlock time until midnight.
[...Array(60 * 5).keys()].forEach((minutes) => {
[...Array(60 * 7).keys()].forEach((minutes) => {
const year = 2022;
const day = 22;
const utcUnlockTimeMs = new Date(year, 11, day).setUTCHours(19, 0, 0, 0);
const utcUnlockTimeMs = new Date(year, 11, day).setUTCHours(5, 0, 0, 0);
const systemTime = new Date(utcUnlockTimeMs + minutes * 60000);

test(`returns false - same day time is: ${systemTime.toISOString()}`, () => {
Expand Down

0 comments on commit f877685

Please sign in to comment.