mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-25 04:26:00 -05:00
Fix org page crash for certain time zones
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -35,12 +35,15 @@ export function EventCalendar({
|
||||
</div>
|
||||
))}
|
||||
{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 (
|
||||
<EventCalendarCell
|
||||
@@ -75,7 +78,7 @@ function EventCalendarCell({
|
||||
date?.getFullYear() === new Date().getFullYear(),
|
||||
})}
|
||||
>
|
||||
<div className="org__calendar__day__date">{date?.getDate()}</div>
|
||||
<div className="org__calendar__day__date">{date?.getUTCDate()}</div>
|
||||
{events.length === 1 ? (
|
||||
<img
|
||||
className="org__calendar__day__logo"
|
||||
@@ -98,7 +101,7 @@ const monthYearSearchParams = ({ month, year }: MonthYear) =>
|
||||
["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 (
|
||||
<div className="org__calendar__month-selector">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user