Skip to content

Commit

Permalink
Merge pull request #561 from m-h-c-t/kga-2024
Browse files Browse the repository at this point in the history
Update KGA end date for 2024
  • Loading branch information
AardWolf authored Jun 7, 2024
2 parents 08bdac7 + 62ac69d commit dc754e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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

0 comments on commit dc754e7

Please sign in to comment.