mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 13:45:27 -05:00
Fix wrong year used for calendar week 1
This commit is contained in:
@@ -25,6 +25,7 @@ import { joinListToNaturalString } from "~/utils/arrays";
|
||||
import {
|
||||
databaseTimestampToDate,
|
||||
dateToThisWeeksMonday,
|
||||
dateToThisWeeksSunday,
|
||||
dateToWeekNumber,
|
||||
dayToWeekStartsAtMondayDay,
|
||||
getWeekStartsAtMondayDay,
|
||||
@@ -116,6 +117,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
});
|
||||
|
||||
const mondayDate = dateToThisWeeksMonday(new Date());
|
||||
const sundayDate = dateToThisWeeksSunday(new Date());
|
||||
const currentWeek = dateToWeekNumber(mondayDate);
|
||||
|
||||
const displayedWeek = parsedWeekParams.success
|
||||
@@ -123,7 +125,9 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
: currentWeek;
|
||||
const displayedYear = parsedWeekParams.success
|
||||
? parsedWeekParams.data.year
|
||||
: mondayDate.getFullYear();
|
||||
: currentWeek === 1 // handle first week of the year special case
|
||||
? sundayDate.getFullYear()
|
||||
: mondayDate.getFullYear();
|
||||
const tagsToFilterBy = parsedFilterParams.success
|
||||
? (parsedFilterParams.data.tags as PersistedCalendarEventTag[])
|
||||
: [];
|
||||
|
||||
@@ -32,6 +32,16 @@ export function dateToThisWeeksMonday(date: Date) {
|
||||
return copiedDate;
|
||||
}
|
||||
|
||||
export function dateToThisWeeksSunday(date: Date) {
|
||||
const copiedDate = new Date(date.getTime());
|
||||
|
||||
while (copiedDate.getDay() !== 0) {
|
||||
copiedDate.setDate(copiedDate.getDate() + 1);
|
||||
}
|
||||
|
||||
return copiedDate;
|
||||
}
|
||||
|
||||
export function getWeekStartsAtMondayDay(date: Date) {
|
||||
const currentDay = date.getDay();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user