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

Update KGA end date for 2024 #561

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scripts/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class CustomConvertibleIds {
*/
export class EventDates {
// KGA
public static readonly KingsGiveawayEndDate: Date = new Date("2023-10-03T15:00:00Z");
public static readonly KingsGiveawayEndDate: Date = new Date("2024-07-09T15:00:00Z");

// GWH
public static readonly GreatWinterHuntEndDate: Date = new Date("2024-01-16T16:00:00Z");
Expand Down
14 changes: 14 additions & 0 deletions src/scripts/util/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ export function getUnixTimestamp(): number {
export function hasEventEnded(eventEndDate: Date) {
return Date.now() > eventEndDate.getTime();
}


/**
* Adds the specified number of days to a given date.
*
* @param date - The date to which the days will be added.
* @param days - The number of days to add.
* @returns A new Date object representing the updated date.
*/
export function addDays(date: Date, days: number): Date {
const result = new Date(date);
result.setDate(date.getDate() + days);
return result;
}
7 changes: 4 additions & 3 deletions tests/scripts/modules/ajax-handlers/kingsGiveaway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {KingsGiveawayAjaxHandler} from "@scripts/modules/ajax-handlers/kingsGive
import {KingsGiveawayResponse} from "@scripts/modules/ajax-handlers/kingsGiveaway.types";
import {HgResponse} from "@scripts/types/hg";
import {HgItem} from "@scripts/types/mhct";
import {CustomConvertibleIds} from "@scripts/util/constants";
import {CustomConvertibleIds, EventDates} from "@scripts/util/constants";
import {addDays} from "@scripts/util/time";

jest.mock("@scripts/util/logger");
import {ConsoleLogger} from "@scripts/util/logger";
Expand All @@ -25,13 +26,13 @@ describe("KingsGiveawayAjaxHandler", () => {

it("is false when KGA has vanished", () => {
// return the day after our filter
Date.now = jest.fn(() => new Date("2023-10-04T05:00:00Z").getTime());
Date.now = jest.fn(() => addDays(EventDates.KingsGiveawayEndDate, 1).getTime());

expect(handler.match(kga_url)).toBe(false);
});

it("is true when url matches", () => {
Date.now = jest.fn(() => new Date("2023-09-12T05:00:00Z").getTime());
Date.now = jest.fn(() => addDays(EventDates.KingsGiveawayEndDate, -5).getTime());

expect(handler.match(kga_url)).toBe(true);
});
Expand Down