Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Added custom default time offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Dec 28, 2022
1 parent d4473d7 commit 25c681b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/history-explorer-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class HistoryCardState {
this.pconfig.axisAddMarginMin = true;
this.pconfig.axisAddMarginMax = true;
this.pconfig.defaultTimeRange = '24';
this.pconfig.defaultTimeOffset = undefined;
this.pconfig.timeTickDensity = 'high';
this.pconfig.exportSeparator = undefined;
this.pconfig.exportTimeFormat = undefined;
Expand Down Expand Up @@ -284,7 +285,17 @@ class HistoryCardState {

if( resetRange ) this.setTimeRange(24, false);

this.endTime = moment().format('YYYY-MM-DDTHH:mm[:00]');
let endTime = moment();
if( this.pconfig.defaultTimeOffset ) {
const s = this.pconfig.defaultTimeOffset.slice(0, -1);
switch( this.pconfig.defaultTimeOffset.slice(-1)[0] ) {
case 'm': endTime = endTime.add(s, 'minute'); break;
case 'h': endTime = endTime.add(s, 'hour'); break;
case 'd': endTime = endTime.add(s, 'day'); break;
}
}

this.endTime = endTime.format('YYYY-MM-DDTHH:mm[:00]');
this.startTime = moment(this.endTime).subtract(this.activeRange.timeRangeHours, "hour").subtract(this.activeRange.timeRangeMinutes, "minute").format('YYYY-MM-DDTHH:mm[:00]');

this.updateHistory();
Expand Down Expand Up @@ -2830,6 +2841,7 @@ class HistoryExplorerCard extends HTMLElement
this.instance.pconfig.filterEntities = config.filterEntities;
this.instance.pconfig.combineSameUnits = config.combineSameUnits === true;
this.instance.pconfig.defaultTimeRange = config.defaultTimeRange ?? '24';
this.instance.pconfig.defaultTimeOffset = config.defaultTimeOffset ?? undefined;
this.instance.pconfig.timeTickDensity = config.timeTickDensity ?? 'high';
this.instance.pconfig.lineGraphHeight = ( config.lineGraphHeight ?? 250 ) * 1;
this.instance.pconfig.barGraphHeight = ( config.barGraphHeight ?? 150 ) * 1;
Expand Down
1 change: 1 addition & 0 deletions src/history-info-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function hecHookInfoPanel()
instance.pconfig.filterEntities = null;
instance.pconfig.combineSameUnits = false;
instance.pconfig.defaultTimeRange = config.defaultTimeRange ?? '24';
instance.pconfig.defaultTimeOffset = config.defaultTimeOffset ?? undefined;
instance.pconfig.timeTickDensity = config.timeTickDensity ?? 'high';
instance.pconfig.lineGraphHeight = ( config.lineGraphHeight ?? 250 ) * 1;
instance.pconfig.barGraphHeight = ( config.barGraphHeight ?? 150 ) * 1;
Expand Down

0 comments on commit 25c681b

Please sign in to comment.