From 0a64d70ae392b9a3451b8b22463f90ee06109e48 Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Mon, 1 Jun 2020 04:29:30 -0700 Subject: [PATCH] isSundaySchedule method --- src/js/components/root.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/js/components/root.js b/src/js/components/root.js index be835f6..47792e1 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -3,6 +3,15 @@ import { BrowserRouter, Route, Link } from "react-router-dom"; import _ from 'lodash'; import { HeaderBar } from "./lib/header-bar.js" +function isSundaySchedule(curTime) { + // Deliberately switch over the effective day in the middle of the + // night. + const dayOfWeek = curTime.getDay(); + const hour = curTime.getHours(); + const isSunday = (dayOfWeek === 0 && hour > 4) || (dayOfWeek === 1 && hour < 4); + return isSunday; +} + class ElevatorWidget extends Component { statuses() { @@ -48,7 +57,7 @@ class TimeScheduleWidget extends Component { render() { const curTime = this.state.curTime; const timeStr = curTime.toLocaleTimeString(); - const serviceStr = curTime.getDay() === 0 ? "Sunday service" : "Weekday / Saturday service"; + const serviceStr = isSundaySchedule(curTime) ? "Sunday service" : "Weekday / Saturday service"; return (
Current time: {timeStr}
{serviceStr}
@@ -104,6 +113,10 @@ class RoutePlanner extends Component { } render() { + const curTime = this.props.curTime; + const mapFilename = isSundaySchedule(curTime) ? "BART-Map-Sunday.png" : "BART-Map-Weekday-Saturday.png"; + const mapPath=`/~bartinfo/img/${mapFilename}`; + return (