Skip to content

Commit

Permalink
Fix availability of december background (#15378)
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen authored Jan 6, 2025
1 parent 723adce commit 9db5d41
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 24 additions & 2 deletions test/content/schedule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', () => {
Expand Down
5 changes: 4 additions & 1 deletion website/common/script/content/constants/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit 9db5d41

Please sign in to comment.