diff --git a/app/features/tournament-organization/TournamentOrganizationRepository.server.ts b/app/features/tournament-organization/TournamentOrganizationRepository.server.ts index 656458d6f..77ab883cb 100644 --- a/app/features/tournament-organization/TournamentOrganizationRepository.server.ts +++ b/app/features/tournament-organization/TournamentOrganizationRepository.server.ts @@ -234,8 +234,12 @@ export async function findEventsByMonth({ year, organizationId, }: FindEventsByMonthArgs) { - const firstDayOfTheMonth = new Date(year, month, 1); - const lastDayOfTheMonth = new Date(year, month + 1, 0); + const firstDayOfTheMonth = new Date(Date.UTC(year, month, 1)); + const lastDayOfTheMonth = new Date(Date.UTC(year, month + 1, 0)); + + // a bit of margin for timezones, filtered in the frontend code + firstDayOfTheMonth.setUTCDate(firstDayOfTheMonth.getUTCDate() - 1); + lastDayOfTheMonth.setUTCDate(lastDayOfTheMonth.getUTCDate() + 1); const events = await findEventsBaseQuery(organizationId) .where( diff --git a/app/features/tournament-organization/components/EventCalendar.tsx b/app/features/tournament-organization/components/EventCalendar.tsx index 45fba91ac..e6bf751b9 100644 --- a/app/features/tournament-organization/components/EventCalendar.tsx +++ b/app/features/tournament-organization/components/EventCalendar.tsx @@ -35,12 +35,15 @@ export function EventCalendar({ ))} {dates.map((date, i) => { - const daysEvents = events.filter( - (event) => + const daysEvents = events.filter((event) => { + const startTimeDate = databaseTimestampToDate(event.startTime); + + return ( isMounted && - databaseTimestampToDate(event.startTime).getDate() === - date?.getDate(), - ); + startTimeDate.getDate() === date?.getDate() && + startTimeDate.getMonth() === date.getMonth() + ); + }); return ( -
{date?.getDate()}
+
{date?.getUTCDate()}
{events.length === 1 ? ( ["year", String(year)], ]).toString(); function MonthSelector({ month, year }: { month: number; year: number }) { - const date = new Date(Date.UTC(year, month, 1)); + const date = new Date(Date.UTC(year, month, 15)); return (
diff --git a/app/utils/dates.ts b/app/utils/dates.ts index 44a0c06e2..479938a7f 100644 --- a/app/utils/dates.ts +++ b/app/utils/dates.ts @@ -142,7 +142,7 @@ export function dateToYYYYMMDD(date: Date) { // same as datesOfMonth but contains null at the start to start with monday export function nullPaddedDatesOfMonth({ month, year }: MonthYear) { const dates = datesOfMonth({ month, year }); - const firstDay = dates[0].getDay(); + const firstDay = dates[0].getUTCDate(); const nulls = Array.from( { length: firstDay === 0 ? 6 : firstDay - 1 }, () => null, @@ -153,9 +153,9 @@ export function nullPaddedDatesOfMonth({ month, year }: MonthYear) { function datesOfMonth({ month, year }: MonthYear) { const dates = []; const date = new Date(Date.UTC(year, month, 1)); - while (date.getMonth() === month) { + while (date.getUTCMonth() === month) { dates.push(new Date(date)); - date.setDate(date.getDate() + 1); + date.setUTCDate(date.getUTCDate() + 1); } return dates; }