Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#533 Allow adding relative seconds to initial times #534

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/pages/Configure/Tabs/Time/Time_Tab.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
101 changes: 81 additions & 20 deletions src/essence/Ancillary/TimeUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -378,35 +400,53 @@ 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
)
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(
"Invalid 'Initial End Time' provided. Defaulting to 'now'."
)
} 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
Expand All @@ -415,42 +455,63 @@ 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
)
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
Expand Down
Loading