mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-26 21:26:01 -05:00
WeekLinkTitle with date ranges
This commit is contained in:
@@ -16,15 +16,22 @@ export function dateToWeekNumber(date: Date) {
|
||||
export function weekNumberToDate({
|
||||
week,
|
||||
year,
|
||||
position = "start",
|
||||
}: {
|
||||
week: number;
|
||||
year: number;
|
||||
/** start = Date of Monday, end = Date of Sunday */
|
||||
position?: "start" | "end";
|
||||
}) {
|
||||
// xxx: possible problem of mismatch when server time and local time don't match
|
||||
// gotta make sure events which belong to monday are still shown for sunday
|
||||
const result = new Date(Date.UTC(year, 0, 4));
|
||||
|
||||
result.setDate(
|
||||
result.getDate() - (result.getDay() || 7) + 1 + 7 * (week - 1)
|
||||
);
|
||||
if (position === "end") {
|
||||
result.setDate(result.getDate() + 6);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user