From 0bca141b74c04b5487cc2f1799abcfd450d79858 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Sat, 30 Jul 2022 21:03:32 +0530 Subject: [PATCH] Fix last day of month handling logic in tests (#3605) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix last day of month handling logic * Update apps/web/test/lib/getSchedule.test.ts Co-authored-by: Omar López * 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 Co-authored-by: Omar López --- apps/web/test/lib/getSchedule.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.ts index f549430945..7c6cf03b8a 100644 --- a/apps/web/test/lib/getSchedule.test.ts +++ b/apps/web/test/lib/getSchedule.test.ts @@ -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; }