From 87788a4f5219a2aeeaa0f80755998f3ddf00ac25 Mon Sep 17 00:00:00 2001 From: realwhyjay Date: Tue, 30 May 2023 00:46:35 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=BA=98=EB=A6=B0=EB=8D=94=20=EB=B7=B0?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/v1/character/character.service.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/modules/v1/character/character.service.ts b/src/modules/v1/character/character.service.ts index 5c53784..6741347 100644 --- a/src/modules/v1/character/character.service.ts +++ b/src/modules/v1/character/character.service.ts @@ -252,20 +252,32 @@ export class CharacterService { const end = DateUtil.toDate(endDate); const daysByMonth = {}; - let currMonth = dayjs(start).clone().startOf('month'); + let currMonth = dayjs(start).date(1); + while (currMonth.isBefore(end)) { const monthDays = currMonth.daysInMonth(); - const daysInRange = Math.min( - monthDays, - dayjs(end).diff(currMonth, 'day') + 1, - ); - daysByMonth[currMonth.format('M')] = daysInRange; + const startDateOfMonth = currMonth.startOf('month').toDate(); + const endDateOfMonth = currMonth.endOf('month').toDate(); + + const startDay = dayjs(startDateOfMonth).isAfter(start) + ? dayjs(startDateOfMonth) + : dayjs(start); + const endDay = dayjs(endDateOfMonth).isBefore(end) + ? dayjs(endDateOfMonth) + : dayjs(end); + + const daysInRange = Math.max(endDay.diff(startDay, 'day') + 1, 0); + + daysByMonth[currMonth.format('M')] = Math.min(monthDays, daysInRange); currMonth = currMonth.add(1, 'month').startOf('month'); } const mainMonth = +Object.keys(daysByMonth).reduce((a, b) => daysByMonth[a] > daysByMonth[b] ? a : b, ); + // console.info('daysByMonth', daysByMonth); + // console.info('mainMonth', mainMonth); + const activity = await this.activityRepository.findAllBetweenDateAndDate( userId, start,