Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
fix: getSpecificWeekday bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sircharlo committed Oct 14, 2024
1 parent 6147036 commit 720dee7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ function getSpecificWeekday(lookupDate: Date, desiredWeekday: number): Date {
// Get the day of the week for the lookupDate (0 = Sunday, 6 = Saturday)
const currentWeekday = lookupDate.getDay();

// If Sunday, subtract one week
if (currentWeekday === 0) {
lookupDate.setDate(lookupDate.getDate() - 7);
}

// Calculate difference between current day and desired day in the same week
const difference = desiredWeekday - currentWeekday;

Expand Down Expand Up @@ -130,6 +135,16 @@ function isCoWeek(lookupDate: Date) {
const coWeekTuesday = dateFromString(currentSettings.value?.coWeek);
const coMonday = getSpecificWeekday(coWeekTuesday, 1);
const lookupWeekMonday = getSpecificWeekday(lookupDate, 1);
console.debug(
'lookupDate',
lookupDate,
'coWeekTuesday',
coWeekTuesday,
'coMonday',
coMonday,
'lookupWeekMonday',
lookupWeekMonday,
);
return datesAreSame(coMonday, lookupWeekMonday);
} catch (error) {
errorCatcher(error);
Expand Down

0 comments on commit 720dee7

Please sign in to comment.