From 2c5c47e3c5343419a6efa618b9d6549394da2e9f Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 19 Apr 2021 15:29:33 +0300 Subject: Fix date logic --- src/sheets.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/sheets.ts') 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; }; -- cgit v1.3