Fix last day of month handling logic in tests (#3605)

* Fix last day of month handling logic

* Update apps/web/test/lib/getSchedule.test.ts

Co-authored-by: Omar López <zomars@me.com>

* Update apps/web/test/lib/getSchedule.test.ts

* Update apps/web/test/lib/getSchedule.test.ts

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
pull/3606/head^2
Hariom Balhara 2022-07-30 21:03:32 +05:30 committed by GitHub
parent a4e91a0666
commit 0bca141b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -46,8 +46,10 @@ const getDate = (param: { dateIncrement?: number; monthIncrement?: number; yearI
let _month = new Date().getMonth() + monthIncrement + 1;
// If last day of the month(As _month is plus 1 already it is going to be the 0th day of next month which is the last day of current month)
if (_date === new Date(year, _month, 0).getDate()) {
_date = 1;
const lastDayOfMonth = new Date(year, _month, 0).getDate();
const numberOfDaysForNextMonth = +_date - +lastDayOfMonth;
if (numberOfDaysForNextMonth > 0) {
_date = numberOfDaysForNextMonth;
_month = _month + 1;
}