From 2f927b2b00d6762a7172c91b585b02d3c9af6e32 Mon Sep 17 00:00:00 2001 From: tariqksoliman Date: Thu, 11 Apr 2024 18:32:10 -0700 Subject: [PATCH 1/2] #533 Allow adding relative seconds to initial times --- docs/pages/Configure/Tabs/Time/Time_Tab.md | 8 +- src/essence/Ancillary/TimeUI.js | 101 +++++++++++++++++---- 2 files changed, 86 insertions(+), 23 deletions(-) diff --git a/docs/pages/Configure/Tabs/Time/Time_Tab.md b/docs/pages/Configure/Tabs/Time/Time_Tab.md index 6bb6d04c..dca2ae57 100644 --- a/docs/pages/Configure/Tabs/Time/Time_Tab.md +++ b/docs/pages/Configure/Tabs/Time/Time_Tab.md @@ -30,24 +30,24 @@ Default: `%Y-%m-%dT%H:%M:%SZ` ## Initial Start Time -The initial start time. Should be before `Initial End Time`. +The initial start time. Should be before `Initial End Time`. Can be made relative by appending ` {+/-} {seconds}` - for instance: "2024-03-04T14:05:00Z + 864000". Default: 1 month before `Initial End Time` ## Initial End Time -The initial end time. Should be after `Initial Start Time`. Use `now` to have the end time be the present. +The initial end time. Should be after `Initial Start Time`. Use `now` to have the end time be the present. Can be made relative by appending ` {+/-} {seconds}` - for instance: "2024-03-04T14:05:00Z + 864000". Default: `now` ## Initial Window Start Time -This does not control the time range for queries. This only allows the initial time window of the time line to differ from just being the Start Time to the End Time. A use-case for this would be to set the window times to fit the full extent of the temporal data but only set the Initial Start and End Times as a subset of that so as not to query everything on load. +This does not control the time range for queries. This only allows the initial time window of the time line to differ from just being the Start Time to the End Time. A use-case for this would be to set the window times to fit the full extent of the temporal data but only set the Initial Start and End Times as a subset of that so as not to query everything on load. Can be made relative by appending ` {+/-} {seconds}` - for instance: "2024-03-04T14:05:00Z + 864000". Default: `Initial Start Time` ## Initial Window End Time -This does not control the time range for queries. This only allows the initial time window of the time line to differ from just being the Start Time to the End Time. Should be after `Initial Window End Time` Use `now` to have the end time be the present. +This does not control the time range for queries. This only allows the initial time window of the time line to differ from just being the Start Time to the End Time. Should be after `Initial Window End Time` Use `now` to have the end time be the present. Can be made relative by appending ` {+/-} {seconds}` - for instance: "2024-03-04T14:05:00Z + 864000". Default: `Initial End Time` diff --git a/src/essence/Ancillary/TimeUI.js b/src/essence/Ancillary/TimeUI.js index 65be7d93..a0013e69 100644 --- a/src/essence/Ancillary/TimeUI.js +++ b/src/essence/Ancillary/TimeUI.js @@ -133,6 +133,28 @@ const TimeUI = { return TimeUI }, getElement: function () {}, + getDateAdditionalSeconds: function (d) { + let dateString = d + let opMult = 1 + let additionalSeconds = 0 + if (typeof dateString === 'string') { + const indexPlus = dateString.indexOf(' + ') + const indexMinus = dateString.indexOf(' - ') + if (indexPlus > -1 || indexMinus > -1) { + if (indexMinus > indexPlus) opMult = -1 + const initialendSplit = dateString.split( + ` ${opMult === 1 ? '+' : '-'} ` + ) + dateString = initialendSplit[0] + additionalSeconds = parseInt(initialendSplit[1]) || 0 + additionalSeconds = isNaN(additionalSeconds) + ? 0 + : additionalSeconds + } + additionalSeconds *= opMult + } + return { dateString, additionalSeconds } + }, attachEvents: function (timeChange) { let startingModeIndex = TimeUI.modeIndex // Set modeIndex to 1/Point if a deeplink had an endtime but no starttime @@ -378,10 +400,19 @@ const TimeUI = { TimeUI._refreshIntervals() }) + let dateAddSec = null + // Initial end if (L_.FUTURES.endTime != null) { L_.configData.time.initialend = L_.FUTURES.endTime } + + // parse formats like "2024-03-04T14:05:00Z + 10000000" for relative times + dateAddSec = TimeUI.getDateAdditionalSeconds( + L_.configData.time.initialend + ) + L_.configData.time.initialend = dateAddSec.dateString + if ( L_.configData.time.initialend != null && L_.configData.time.initialend != 'now' @@ -394,19 +425,30 @@ const TimeUI = { ) } else TimeUI._initialEnd = dateStaged } else TimeUI._initialEnd = new Date() + TimeUI._initialEnd.setSeconds( + TimeUI._initialEnd.getSeconds() + dateAddSec.additionalSeconds + ) - // Initial Timeline window end if ( L_.configData.time.initialwindowend != null && L_.configData.time.initialwindowend != 'now' ) { - const dateStaged = new Date(L_.configData.time.initialwindowend) + // parse formats like "2024-03-04T14:05:00Z + 10000000" for relative times + dateAddSec = TimeUI.getDateAdditionalSeconds( + L_.configData.time.initialwindowend + ) + const dateStaged = new Date(dateAddSec.dateString) if (dateStaged == 'Invalid Date') { TimeUI._timelineEndTimestamp = new Date() console.warn( "Invalid 'Initial Window End Time' provided. Defaulting to 'now'." ) - } else TimeUI._timelineEndTimestamp = dateStaged.getTime() + } else { + dateStaged.setSeconds( + dateStaged.getSeconds() + dateAddSec.additionalSeconds + ) + TimeUI._timelineEndTimestamp = dateStaged.getTime() + } } // Initial start @@ -415,12 +457,18 @@ const TimeUI = { if (L_.FUTURES.startTime != null) { L_.configData.time.initialstart = L_.FUTURES.startTime } + if (L_.configData.time.initialstart == null) TimeUI._initialStart.setUTCMonth( TimeUI._initialStart.getUTCMonth() - 1 ) else { - const dateStaged = new Date(L_.configData.time.initialstart) + // parse formats like "2024-03-04T14:05:00Z + 10000000" for relative times + dateAddSec = TimeUI.getDateAdditionalSeconds( + L_.configData.time.initialstart + ) + + const dateStaged = new Date(dateAddSec.dateString) if (dateStaged == 'Invalid Date') { TimeUI._initialStart.setUTCMonth( TimeUI._initialStart.getUTCMonth() - 1 @@ -428,29 +476,44 @@ const TimeUI = { console.warn( "Invalid 'Initial Start Time' provided. Defaulting to 1 month before the end time." ) - } else if (dateStaged.getTime() > TimeUI._initialEnd.getTime()) { - TimeUI._initialStart.setUTCMonth( - TimeUI._initialStart.getUTCMonth() - 1 - ) - console.warn( - "'Initial Start Time' cannot be later than the end time. Defaulting to 1 month before the end time." + } else { + dateStaged.setSeconds( + dateStaged.getSeconds() + dateAddSec.additionalSeconds ) - } else TimeUI._initialStart = dateStaged + if (dateStaged.getTime() > TimeUI._initialEnd.getTime()) { + TimeUI._initialStart.setUTCMonth( + TimeUI._initialStart.getUTCMonth() - 1 + ) + console.warn( + "'Initial Start Time' cannot be later than the end time. Defaulting to 1 month before the end time." + ) + } else TimeUI._initialStart = dateStaged + } } // Initial Timeline window start if (L_.configData.time.initialwindowstart != null) { - const dateStaged = new Date(L_.configData.time.initialwindowstart) + // parse formats like "2024-03-04T14:05:00Z + 10000000" for relative times + dateAddSec = TimeUI.getDateAdditionalSeconds( + L_.configData.time.initialwindowstart + ) + + const dateStaged = new Date(dateAddSec.dateString) if (dateStaged == 'Invalid Date') { console.warn("Invalid 'Initial Window Start Time' provided.") - } else if ( - TimeUI._timelineEndTimestamp == null || - dateStaged.getTime() > TimeUI._timelineEndTimestamp - ) { - console.warn( - "'Initial Window Start Time' cannot be later than the Initial Window End Time." + } else { + dateStaged.setSeconds( + dateStaged.getSeconds() + dateAddSec.additionalSeconds ) - } else TimeUI._timelineStartTimestamp = dateStaged.getTime() + if ( + TimeUI._timelineEndTimestamp == null || + dateStaged.getTime() > TimeUI._timelineEndTimestamp + ) { + console.warn( + "'Initial Window Start Time' cannot be later than the Initial Window End Time." + ) + } else TimeUI._timelineStartTimestamp = dateStaged.getTime() + } } // Initialize the time control times, but don't trigger events From c383c27534a3530746bd037be5f7522c8b4c1b5c Mon Sep 17 00:00:00 2001 From: tariqksoliman Date: Thu, 11 Apr 2024 18:35:57 -0700 Subject: [PATCH 2/2] #533 Make sure not to overwrite config time value for initialend --- src/essence/Ancillary/TimeUI.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/essence/Ancillary/TimeUI.js b/src/essence/Ancillary/TimeUI.js index a0013e69..6c92210a 100644 --- a/src/essence/Ancillary/TimeUI.js +++ b/src/essence/Ancillary/TimeUI.js @@ -411,13 +411,11 @@ const TimeUI = { dateAddSec = TimeUI.getDateAdditionalSeconds( L_.configData.time.initialend ) - L_.configData.time.initialend = dateAddSec.dateString - if ( L_.configData.time.initialend != null && L_.configData.time.initialend != 'now' ) { - const dateStaged = new Date(L_.configData.time.initialend) + const dateStaged = new Date(dateAddSec.dateString) if (dateStaged == 'Invalid Date') { TimeUI._initialEnd = new Date() console.warn(