diff --git a/src/data/splash-messages.ts b/src/data/splash-messages.ts index 0147c39541b..086a55189d0 100644 --- a/src/data/splash-messages.ts +++ b/src/data/splash-messages.ts @@ -61,7 +61,7 @@ const seasonalSplashMessages: Season[] = [ end: "12-31" }, { - name: "newyears", + name: "newYears", start: "12-31", end: "01-14" }, @@ -71,10 +71,9 @@ const seasonalSplashMessages: Season[] = [ export function getSplashMessages(): string[] { const existingKeys = i18next.getResourceBundle(i18next.language, "splashMessages"); - console.log(existingKeys); const splashMessages: string[] = [ ...Object.keys(existingKeys["common"]) ].map((message) => `common.${message}`); if (splashMessages.includes("common.battlesWon")) { - splashMessages.push(...Array(BATTLES_WON_WEIGHT_MULTIPLIER).fill("common.battlesWon")); + splashMessages.push(...Array(Math.max(BATTLES_WON_WEIGHT_MULTIPLIER - 1, 1)).fill("common.battlesWon")); } console.log("use seasonal splash messages", USE_SEASONAL_SPLASH_MESSAGES); @@ -85,8 +84,13 @@ export function getSplashMessages(): string[] { const startDate = new Date(`${start}-${now.getFullYear()}`); const endDate = new Date(`${end}-${now.getFullYear()}`); if (endDate < startDate) { // If the end date is earlier in the year, that means it's next year - endDate.setFullYear(endDate.getFullYear() + 1); + if (now >= startDate) { + endDate.setFullYear(endDate.getFullYear() + 1); //Ends next year + } else if (now <= endDate) { + startDate.setFullYear(startDate.getFullYear() - 1); //Started last year + } } + console.log(`${name} event starts ${startDate} and ends ${endDate}`); if (existingKeys.hasOwnProperty(name) && now >= startDate && now <= endDate) { const existingMessages: string[] = [ ...Object.keys(existingKeys[name]) ].map(m=>`${name}.${m}`); diff --git a/src/test/data/splash_messages.test.ts b/src/test/data/splash_messages.test.ts index b9ed5b9d365..e4ad547b704 100644 --- a/src/test/data/splash_messages.test.ts +++ b/src/test/data/splash_messages.test.ts @@ -9,7 +9,7 @@ describe("Data - Splash Messages", () => { // make sure to adjust this test if the weight it changed! it("should add contain 10 `battlesWon` splash messages", () => { - const battlesWonMessages = getSplashMessages().filter((message) => message === "splashMessages:battlesWon"); + const battlesWonMessages = getSplashMessages().filter((message) => message === "splashMessages:common.battlesWon"); expect(battlesWonMessages).toHaveLength(10); }); @@ -22,16 +22,16 @@ describe("Data - Splash Messages", () => { vi.useRealTimers(); // reset system time }); - it("should contain halloween messages from Sep 15 to Oct 31", () => { - testSeason(new Date("2024-09-15"), new Date("2024-10-31"), "halloween"); + it("should contain halloween messages from Oct 15 to Oct 31", () => { + testSeason(new Date("2024-10-15"), new Date("2024-10-31"), "halloween"); }); - it("should contain xmas messages from Dec 1 to Dec 26", () => { - testSeason(new Date("2024-12-01"), new Date("2024-12-26"), "xmas"); + it("should contain xmas messages from Dec 16 to Dec 31", () => { + testSeason(new Date("2024-12-16"), new Date("2024-12-31"), "xmas"); }); - it("should contain new years messages frm Jan 1 to Jan 31", () => { - testSeason(new Date("2024-01-01"), new Date("2024-01-31"), "newYears"); + it("should contain new years messages from Dec 31 '24 to Jan 14 '25", () => { + testSeason(new Date("2024-12-31"), new Date("2025-01-14"), "newYears"); }); }); }); @@ -60,7 +60,7 @@ function testSeason(startDate: Date, endDate: Date, prefix: string) { }); expect(before).toBe(0); - expect(start).toBeGreaterThanOrEqual(10); // make sure to adjust if weight is changed! - expect(end).toBeGreaterThanOrEqual(10); // make sure to adjust if weight is changed! + expect(start).toBeGreaterThanOrEqual(20); // make sure to adjust if weight is changed! + expect(end).toBeGreaterThanOrEqual(20); // make sure to adjust if weight is changed! expect(after).toBe(0); }