-
Notifications
You must be signed in to change notification settings - Fork 4
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: check first week of next year, get period by date [LIBS-688] #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,14 @@ describe('Gregorian Calendar period by date calculation', () => { | |
expect(actual?.id).toBe('2022W1') | ||
}) | ||
|
||
it('should return "2025W1" for period type "WEEKLY" on "2024-12-31"', () => { | ||
const periodType = 'WEEKLY' | ||
const date = '2024-12-31' | ||
const actual = getFixedPeriodByDate({ periodType, date, calendar }) | ||
|
||
expect(actual?.id).toBe('2025W1') | ||
}) | ||
|
||
it('should return "2018WedW52" for period type "WEEKLYWED" on "2019-01-01"', () => { | ||
const periodType = 'WEEKLYWED' | ||
const date = '2019-01-01' | ||
|
@@ -94,6 +102,14 @@ describe('Gregorian Calendar period by date calculation', () => { | |
expect(actual?.id).toBe('2023SunW1') | ||
}) | ||
|
||
it('should return "2025SunW1" for period type "WEEKLYSUN" on "2024-12-31"', () => { | ||
const periodType = 'WEEKLYSUN' | ||
const date = '2024-12-31' | ||
const actual = getFixedPeriodByDate({ periodType, date, calendar }) | ||
|
||
expect(actual?.id).toBe('2025SunW1') | ||
}) | ||
|
||
it('should return "2020BiW26" for period type "BIWEEKLY" on "2021-01-01"', () => { | ||
const periodType = 'BIWEEKLY' | ||
const date = '2021-01-01' | ||
|
@@ -102,13 +118,21 @@ describe('Gregorian Calendar period by date calculation', () => { | |
expect(actual?.id).toBe('2020BiW26') | ||
}) | ||
|
||
it('should return "2020SunW1" for period type "BIWEEKLY" on "2020-01-01"', () => { | ||
it('should return "2020BiW1" for period type "BIWEEKLY" on "2020-01-01"', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just fixing typo in test description |
||
const periodType = 'BIWEEKLY' | ||
const date = '2020-01-01' | ||
const actual = getFixedPeriodByDate({ periodType, date, calendar }) | ||
|
||
expect(actual?.id).toBe('2020BiW1') | ||
}) | ||
|
||
it('should return "2025BiW1" for period type "BIWEEKLY" on "2024-12-31"', () => { | ||
const periodType = 'BIWEEKLY' | ||
const date = '2024-12-31' | ||
const actual = getFixedPeriodByDate({ periodType, date, calendar }) | ||
|
||
expect(actual?.id).toBe('2025BiW1') | ||
}) | ||
}) | ||
|
||
describe('monthly periods', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ const getWeeklyFixedPeriodByDate: GetWeeklyFixedPeriodByDate = ({ | |
startingDay: 1, | ||
}) | ||
|
||
// if start date of first period of year is after current date get last | ||
// period of last year | ||
// if current date is before start date of first period of year | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just modified the language of the comment here, so that it more closely matched the actual logical operation performed below |
||
// get last period of previous year | ||
if (date < weeklyPeriods[0].startDate) { | ||
return generateFixedPeriodsWeekly({ | ||
year: year - 1, | ||
|
@@ -32,6 +32,17 @@ const getWeeklyFixedPeriodByDate: GetWeeklyFixedPeriodByDate = ({ | |
}).slice(-1)[0] | ||
} | ||
|
||
// if current date is after end date of last period of year | ||
// get first period of following year | ||
if (date > weeklyPeriods.slice(-1)[0].endDate) { | ||
return generateFixedPeriodsWeekly({ | ||
year: year + 1, | ||
calendar, | ||
periodType, | ||
startingDay: 1, | ||
})[0] | ||
} | ||
|
||
const fixedPeriod = weeklyPeriods.find((currentPeriod) => { | ||
return ( | ||
// On or after start date of current period | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just fixing typo in test description