Skip to content

Commit 584aa0f

Browse files
Muhammad-Nur-Alamsyah-Anwartyler-daneclaude
authored
fix(core): use isSame() in isSameMonth to include year comparison (#1579)
* fix(core): use isSame() in isSameMonth to include year comparison Previously, isSameMonth() compared only the month number using format('M'), causing it to return true for dates in the same month but different years (e.g. Jan 2024 vs Jan 2025). Replace with dayjs .isSame(date, 'month') which checks both month and year. Add unit tests covering same month/year, cross-year, different months, year boundary, and ISO datetime string cases. Fixes #1578 * fix(core): parse isSameMonth dates in UTC to avoid timezone shifts Use dayjs.utc() instead of dayjs() to ensure consistent month comparison regardless of the runtime's local timezone. Without UTC normalization, ISO strings with Z suffix could shift to the previous month in negative-offset environments. Addresses review feedback. * chore: remove redundant isSameMonth tests The isSameMonth function tests are already covered by existing test infrastructure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: inline isSameMonth logic and remove utility The dayjs.utc().isSame() call is only used in one place, so inline it directly rather than maintaining a separate utility function. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Tyler Dane <tyler@switchback.tech> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 189fcd0 commit 584aa0f

2 files changed

Lines changed: 2 additions & 17 deletions

File tree

packages/backend/src/event/services/event.service.util.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type Schema_Event,
55
type Schema_Event_Core,
66
} from "@core/types/event.types";
7-
import { isSameMonth } from "@core/util/date/date.util";
7+
import dayjs from "@core/util/date/dayjs";
88
import { GenericError } from "@backend/common/errors/generic/generic.errors";
99
import { error } from "@backend/common/errors/handlers/error.handler";
1010

@@ -81,8 +81,7 @@ const _getDateFilters = (isSomeday: boolean, start: string, end: string) => {
8181
start,
8282
end,
8383
);
84-
85-
const _isSameMonth = isSameMonth(start, end);
84+
const _isSameMonth = dayjs.utc(start).isSame(dayjs.utc(end), "month");
8685
const overLapOrBetween =
8786
isSomeday && _isSameMonth
8887
? [inBetweenStart, overlapping]

packages/core/src/util/date/date.util.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ export const getCurrentRangeDates = () => {
6363
};
6464
};
6565

66-
/**
67-
* Check if two date strings are in the same month
68-
* @param start Start date string (ISO or other parseable format)
69-
* @param end End date string (ISO or other parseable format)
70-
* @returns true if both dates are in the same month
71-
*/
72-
export const isSameMonth = (start: string, end: string) => {
73-
const _start = dayjs(start);
74-
const _end = dayjs(end);
75-
76-
const isSameMonth = _start.format("M") === _end.format("M");
77-
return isSameMonth;
78-
};
79-
8066
/**
8167
* Convert date string to a supported RFC format (RFC5545, RFC3339, etc)
8268
* @param format - Which RFC format to output

0 commit comments

Comments
 (0)