diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-04-19 15:29:33 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-04-19 15:29:33 +0300 |
| commit | 2c5c47e3c5343419a6efa618b9d6549394da2e9f (patch) | |
| tree | 103498479f2fa5d7995b7bf529124c733343439c /src/sheets.ts | |
| parent | 7f3a70c396b498a8b10553d11cf78c3ea9a872b1 (diff) | |
Fix date logic
Diffstat (limited to 'src/sheets.ts')
| -rw-r--r-- | src/sheets.ts | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/sheets.ts b/src/sheets.ts index e99f089..d3d97e5 100644 --- a/src/sheets.ts +++ b/src/sheets.ts @@ -1,5 +1,5 @@ import { google } from "googleapis"; -import { add, Duration, parse, format, getDay, subDays, addDays } from "date-fns"; +import { add, set, Duration, parse, format, getDay, subDays, addDays } from "date-fns"; import config from "./config"; @@ -88,10 +88,12 @@ const processRow = (row: SheetsRawEntry) => { const isThisWeek = (entry: SheetsProcessedEntry): boolean => { const nextDate = entry.nextDate; - const today = new Date(); + const currentDateTime = new Date(); + const today = set(currentDateTime, { hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }); const dayOfWeek = (getDay(today) + 7 - 1) % 7; // getDay returns sunday = 0 const currentWeekStart = subDays(today, dayOfWeek); const currentWeekEnd = addDays(currentWeekStart, 7); + return nextDate >= currentWeekStart && nextDate < currentWeekEnd; }; |
