From ca88ac609359e8d104efcae47558cda56dcecaa6 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 6 Jan 2025 22:48:47 +0100 Subject: [PATCH] Fix availability of december background --- test/content/schedule.test.js | 26 +++++++++++++++++-- .../script/content/constants/schedule.js | 5 +++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/test/content/schedule.test.js b/test/content/schedule.test.js index da7c403804b..79038073866 100644 --- a/test/content/schedule.test.js +++ b/test/content/schedule.test.js @@ -272,6 +272,21 @@ describe('Content Schedule', () => { expect(matcher.match('backgroundkey072024')).to.be.true; }); + it('allows background matching the month for new backgrounds from multiple years', () => { + const date = new Date('2026-07-08'); + const matcher = getAllScheduleMatchingGroups(date).backgrounds; + expect(matcher.match('backgroundkey072024')).to.be.true; + expect(matcher.match('backgroundkey072025')).to.be.true; + expect(matcher.match('backgroundkey072026')).to.be.true; + }); + + it('allows background matching the previous month in the first week for new backgrounds', () => { + const date = new Date('2024-09-02'); + const matcher = getAllScheduleMatchingGroups(date).backgrounds; + expect(matcher.match('backgroundkey082024')).to.be.true; + expect(matcher.match('backgroundkey092024')).to.be.false; + }); + it('disallows background in the future', () => { const date = new Date('2024-07-08'); const matcher = getAllScheduleMatchingGroups(date).backgrounds; @@ -291,19 +306,26 @@ describe('Content Schedule', () => { expect(matcher.match('backgroundkey022021')).to.be.true; }); - it('allows background even yeared backgrounds in first half of year', () => { + it('allows even yeared backgrounds in first half of year', () => { const date = new Date('2025-02-08'); const matcher = getAllScheduleMatchingGroups(date).backgrounds; expect(matcher.match('backgroundkey022024')).to.be.true; expect(matcher.match('backgroundkey082022')).to.be.true; }); - it('allows background odd yeared backgrounds in second half of year', () => { + it('allows odd yeared backgrounds in second half of year', () => { const date = new Date('2024-08-08'); const matcher = getAllScheduleMatchingGroups(date).backgrounds; expect(matcher.match('backgroundkey022023')).to.be.true; expect(matcher.match('backgroundkey082021')).to.be.true; }); + + it('allows odd yeared backgrounds in beginning of january', () => { + const date = new Date('2025-01-06'); + const matcher = getAllScheduleMatchingGroups(date).backgrounds; + expect(matcher.match('backgroundkey122024'), 'backgroundkey122024').to.be.true; + expect(matcher.match('backgroundkey062023'), 'backgroundkey062022').to.be.true; + }); }); describe('timeTravelers matcher', () => { diff --git a/website/common/script/content/constants/schedule.js b/website/common/script/content/constants/schedule.js index c5ba2a72e07..37612ad71ea 100644 --- a/website/common/script/content/constants/schedule.js +++ b/website/common/script/content/constants/schedule.js @@ -18,7 +18,10 @@ function backgroundMatcher (month1, month2, oddYear) { const month = parseInt(key.substring(keyLength - 6, keyLength - 4), 10); const year = parseInt(key.substring(keyLength - 4, keyLength), 10); if (isAfterNewSchedule(year, month)) { - return month === month1 && date.getFullYear() >= year && (date.getMonth() + 1) >= month; + if (date.getMonth() === 0 && month1 === 12) { + return month === month1 && (date.getFullYear() - 1) >= year; + } + return month === month1 && date.getFullYear() >= year; } return (month === month1 || month === month2) && year % 2 === (oddYear ? 1 : 0); };