From 38bf25701d2002b602f842b7be49d114bbd2d0db Mon Sep 17 00:00:00 2001 From: Madeline Hart Date: Mon, 8 Feb 2021 16:19:24 +0000 Subject: [PATCH] set all time and date methods to UTC --- frontend/src/components/SiteContainer.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/SiteContainer.tsx b/frontend/src/components/SiteContainer.tsx index d3a11102..180311a4 100644 --- a/frontend/src/components/SiteContainer.tsx +++ b/frontend/src/components/SiteContainer.tsx @@ -137,7 +137,7 @@ export default class SiteContainer extends Component { */ forwardOrRewindToDay(d: Date, goTo: GregorianDay, forwardList: number[]) { const dhere = new Date(d); - const day = dhere.getDay(); + const day = dhere.getUTCDay(); // Sunday is day 0 // Sat is Day 6 // If Sun or Sat go to next week @@ -148,8 +148,8 @@ export default class SiteContainer extends Component { * - Go forward by goTo days to the day we want (works as goTo is effectivly a "Sunday offset") * - BUT if the current date is in the forward list, add 7 as well to go forward 1 week */ - const diff = dhere.getDate() - day + goTo + (forwardList.includes(day) ? 7 : 0); // adjust when day is saturday -> add 6 to bring us back to Saturday, then add 2 to go to Monday - return new Date(dhere.setDate(diff)); + const diff = dhere.getUTCDate() - day + goTo + (forwardList.includes(day) ? 7 : 0); // adjust when day is saturday -> add 6 to bring us back to Saturday, then add 2 to go to Monday + return new Date(dhere.setUTCDate(diff)); } /** @@ -164,11 +164,11 @@ export default class SiteContainer extends Component { const weekStart = this.forwardOrRewindToDay(inputDate, this.props.weekMarkerDate, [0, 6]); weekStart.setUTCHours(0, 0, 0, 0); // Set to start of day const weekEnd = new Date(weekStart); - weekEnd.setDate(weekEnd.getDate() + 1); + weekEnd.setUTCDate(weekEnd.getUTCDate() + 1); weekEnd.setUTCHours(0, 0, 0, 0); // Set to start of day // Tell us if weekend! - const dayNow = inputDate.getDay(); + const dayNow = inputDate.getUTCDay(); if (dayNow === 6 || dayNow === 0) { // 0 is Sunday, 6 is Saturday this.setState({ isWeekend: true,