This has been beating me up way longer than it should, and I'm sure I'm doing something stupidly obviously wrong, but am just not seeing it. 🙂
Below is the source for a test dashboard. On it, there are 2 input fields. The first is a time picker, where the user can pick a time range (e.g. last 15 minutes, yesterday). This defines "range 1". The second is an input field where the user can specify the number of days to offset range 2 from range 1. So, for example, if the user picks "yesterday" from the time picker, and "7" days for the offset, then range 1 should be 4/13/2017 00:00:00 - 4/13/2017 23:59:59 (assuming today is 4/14/2017), and range 2 should be 4/6/2017 00:00:00 - 4/6/2017 23:59:59.
Likewise, if it is currently 4/14/2017 at 9:00am, then picking "last 15 minutes" and "2 days" should result in range 1 being 4/14/2017 8:45:00 - 4/14/2017 9:00:00 (now), and range 2 should then be 2 days prior: 4/12/2017 8:45:00 - 4/12/2017 9:00:00.
However, this isn't working. 🙂
When changing either value, the block of text below it is updated, but it appears that it is using 'old' values. For example, the default when the dashboard is opened is "last 4 hours" and "7 days". If you change the time picker to "last 60 minutes", the values are recalculated, but using "last 4 hours". If you then change the offset to 2 days, the values are recalculated (notice the minutes change to reflect a new 'now'), but the offset is still 7 days.
This is driving me nuts, and no one so far has been able to explain why it is doing this, or how to get it to work the way I'd like. Again, I'm sure it is something obvious that I'm just not seeing. Any help would be appreciated!!!
Here's the code. Just create a new dashboard, edit the source, replace it with the below, save it, then play around and you should see the problem. 🙂
Thanks,
Karl
<form>
<init></init>
<label>Range Calculation Test</label>
<fieldset autoRun="true" submitButton="true">
<input type="time" token="time_range" searchWhenChanged="false">
<label>Range 1</label>
<default>
<earliest>-4h@m</earliest>
<latest>now</latest>
</default>
<change>
<eval token="start1_epoch">if(isnum($time_range.earliest$), $time_range.earliest$, relative_time(now(), $time_range.earliest$))</eval>
<eval token="end1_epoch">if(isnum($time_range.latest$), $time_range.latest$, relative_time(now(), $time_range.latest$))</eval>
<eval token="start2_epoch">relative_time($start1_epoch$, $offset$)</eval>
<eval token="end2_epoch">relative_time($end1_epoch$, $offset$)</eval>
<eval token="start1_str">strftime($start1_epoch$, "%c")</eval>
<eval token="end1_str">strftime($end1_epoch$, "%c")</eval>
<eval token="start2_str">strftime($start2_epoch$, "%c")</eval>
<eval token="end2_str">strftime($end2_epoch$, "%c")</eval>
<eval token="earliest1">strftime($start1_epoch$, "%m/%d/%Y:%T")</eval>
<eval token="latest1">strftime($end1_epoch$, "%m/%d/%Y:%T")</eval>
<eval token="earliest2">strftime($start2_epoch$, "%m/%d/%Y:%T")</eval>
<eval token="latest2">strftime($end2_epoch$, "%m/%d/%Y:%T")</eval>
</change>
</input>
<input type="text" token="offset" searchWhenChanged="false">
<label>Offset for range 2 (days prior)</label>
<initialValue>7</initialValue>
<default>7</default>
<prefix>-</prefix>
<suffix>d</suffix>
<change>
<eval token="start1_epoch">if(isnum($time_range.earliest$), $time_range.earliest$, relative_time(now(), $time_range.earliest$))</eval>
<eval token="end1_epoch">if(isnum($time_range.latest$), $time_range.latest$, relative_time(now(), $time_range.latest$))</eval>
<eval token="start2_epoch">relative_time($start1_epoch$, $offset$)</eval>
<eval token="end2_epoch">relative_time($end1_epoch$, $offset$)</eval>
<eval token="start1_str">strftime($start1_epoch$, "%c")</eval>
<eval token="end1_str">strftime($end1_epoch$, "%c")</eval>
<eval token="start2_str">strftime($start2_epoch$, "%c")</eval>
<eval token="end2_str">strftime($end2_epoch$, "%c")</eval>
<eval token="earliest1">strftime($start1_epoch$, "%m/%d/%Y:%T")</eval>
<eval token="latest1">strftime($end1_epoch$, "%m/%d/%Y:%T")</eval>
<eval token="earliest2">strftime($start2_epoch$, "%m/%d/%Y:%T")</eval>
<eval token="latest2">strftime($end2_epoch$, "%m/%d/%Y:%T")</eval>
</change>
</input>
</fieldset>
<row>
<panel>
<html>
<b>Input fields:</b><br/>
time_range.earliest = $time_range.earliest$ <br/>
time_range.latest = $time_range.latest$ <br/>
offset = $offset$ <br/>
<br/>
<b>Range 1:</b><br/>
start1_epoch = $start1_epoch$ <br/>
end1_epoch = $end1_epoch$ <br/>
start1_str = $start1_str$ <br/>
end1_str = $end1_str$ <br/>
earliest1 = $earliest1$ <br/>
latest1 = $latest1$ <br/>
<br/>
<b>Range2:</b><br/>
start2_epoch = $start2_epoch$ <br/>
end2_epoch = $end2_epoch$ <br/>
start2_str = $start2_str$ <br/>
end2_str = $end2_str$ <br/>
earliest2 = $earliest2$ <br/>
latest2 = $latest2$ <br/>
</html>
</panel>
</row>
</form>
... View more