From 62e6fbef61d21c981aac458d8383ae2cd955cc2e Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 2 Jan 2025 18:15:04 +0100 Subject: [PATCH] Fix content end date if already in new year (#15376) * Fix content end date if already in new year * fix test --- test/api/v3/integration/debug/POST-debug_jumpTime.test.js | 2 +- test/content/schedule.test.js | 6 ++++++ website/common/script/content/constants/schedule.js | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/api/v3/integration/debug/POST-debug_jumpTime.test.js b/test/api/v3/integration/debug/POST-debug_jumpTime.test.js index f4326fd972..ba15f9eaba 100644 --- a/test/api/v3/integration/debug/POST-debug_jumpTime.test.js +++ b/test/api/v3/integration/debug/POST-debug_jumpTime.test.js @@ -59,7 +59,7 @@ describe('POST /debug/jump-time', () => { expect(resultDate.getDate()).to.eql(today.getDate()); expect(resultDate.getMonth()).to.eql(today.getMonth()); expect(resultDate.getFullYear()).to.eql(today.getFullYear()); - const newResultDate = new Date((await user.post('/debug/jump-time', { offsetDays: 355 })).time); + const newResultDate = new Date((await user.post('/debug/jump-time', { offsetDays: 365 })).time); expect(newResultDate.getFullYear()).to.eql(today.getFullYear() + 1); }); diff --git a/test/content/schedule.test.js b/test/content/schedule.test.js index de44938126..da7c403804 100644 --- a/test/content/schedule.test.js +++ b/test/content/schedule.test.js @@ -144,6 +144,12 @@ describe('Content Schedule', () => { expect(matchers.seasonalGear.end).to.eql(moment.utc(`2025-03-21T${String(switchoverTime).padStart(2, '0')}:00:00.000Z`).toDate()); }); + it('sets the end date in new year for a winter gala', () => { + const date = new Date('2025-01-04'); + const matchers = getAllScheduleMatchingGroups(date); + expect(matchers.seasonalGear.end).to.eql(moment.utc(`2025-03-21T${String(switchoverTime).padStart(2, '0')}:00:00.000Z`).toDate()); + }); + it('uses correct date for first hours of the month', () => { // if the date is checked before CONTENT_SWITCHOVER_TIME_OFFSET, // it should be considered the previous month diff --git a/website/common/script/content/constants/schedule.js b/website/common/script/content/constants/schedule.js index 99c0eb3a58..c5ba2a72e0 100644 --- a/website/common/script/content/constants/schedule.js +++ b/website/common/script/content/constants/schedule.js @@ -895,7 +895,9 @@ function makeEndDate (checkedDate, matcher) { end.minute(0); end.second(0); if (matcher.endMonth !== undefined) { - if (matcher.startMonth && matcher.startMonth > matcher.endMonth) { + if (matcher.startMonth + && matcher.startMonth > matcher.endMonth + && checkedDate.getMonth() > matcher.endMonth) { end.year(checkedDate.getFullYear() + 1); } end.month(matcher.endMonth);