From 7eed1dd25c70ed1af3f14f18257ed1fd96917c27 Mon Sep 17 00:00:00 2001 From: Tristan Timblin Date: Fri, 2 Jun 2023 11:07:12 -0400 Subject: [PATCH] CEC-4455: Add GMT conversion (#345) adds a checkbox to show time/date in GMT+0 regardless of the users timezone. --- .../__snapshots__/index.test.jsx.snap | 41 +++++++++++++++++++ .../CANSelfServe/SelfServe/index.jsx | 28 ++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/components/CANSelfServe/SelfServe/__snapshots__/index.test.jsx.snap b/src/components/CANSelfServe/SelfServe/__snapshots__/index.test.jsx.snap index 862780e..7c0453b 100644 --- a/src/components/CANSelfServe/SelfServe/__snapshots__/index.test.jsx.snap +++ b/src/components/CANSelfServe/SelfServe/__snapshots__/index.test.jsx.snap @@ -292,6 +292,47 @@ exports[`Render Render 1`] = ` +
+ +
{ const [selectedEndDate, setSelectedEndDate] = useState(new Date()); const [selectedCanSignals, setSelectedCanSignals] = useState([]); const [selectAllCanSignals, setSelectAllCanSignals] = useState(false); + const [gmtTimezone, setGmtTimezone] = useState(false); const { token: { @@ -86,6 +87,12 @@ const MainForm = ({ id }) => { } }; + const displayTimeAsGMT = (date) => { + return gmtTimezone + ? date.toLocaleString("en-US", {timeZone: "Etc/GMT"}) + : date; + } + return (
@@ -102,7 +109,7 @@ const MainForm = ({ id }) => { margin="normal" id="date-picker-inline" label="Date From" - value={selectedStartDate} + value={displayTimeAsGMT(selectedStartDate)} onChange={(value) => handleDateChange(value, "start")} KeyboardButtonProps={{ 'aria-label': 'change date', @@ -116,7 +123,7 @@ const MainForm = ({ id }) => { variant="inline" id="time-picker" label="Time From" - value={selectedStartDate} + value={displayTimeAsGMT(selectedStartDate)} onChange={handleTimeFromChange} KeyboardButtonProps={{ 'aria-label': 'change time', @@ -132,7 +139,7 @@ const MainForm = ({ id }) => { margin="normal" id="date-picker-inline" label="Date To" - value={selectedEndDate} + value={displayTimeAsGMT(selectedEndDate)} onChange={(value) => handleDateChange(value, "end")} KeyboardButtonProps={{ 'aria-label': 'change date', @@ -146,13 +153,24 @@ const MainForm = ({ id }) => { id="time-picker" variant="inline" label="Time To" - value={selectedEndDate} + value={displayTimeAsGMT(selectedEndDate)} onChange={handleTimeToChange} KeyboardButtonProps={{ 'aria-label': 'change time', }} /> + + setGmtTimezone((current) => !current)} + /> + } + /> +