Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix availability of december background #15378

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading