A given duration does not indicate exact time only an interval. To say "last 30 min" means nothing without knowing when you said "last 30 min" from.
Desired Behaviour
Users will want an ability to "freeze time" by specifying something akin to "last x time from when I made this selection". This utility function will allow us to convert that to an absolute timeRange.
Possible Solution
export const durationToAbsoluteRange = (timeRange) => {
if (!timeRange) {
return durationToAbsoluteRange({
duration: 30 * 60 * 1000
});
} else if (timeRange.begin_time && timeRange.end_time) {
return timeRange;
} else if (timeRange.duration) {
const now = Math.floor(new Date().getTime() / 1000);
return {
begin_time: now - (timeRange.duration / 1000),
end_time: now
};
}
};
Additional context
Unable to find usage of this in any of the current public apps but it seems useful depending on how the TimePicker evolves and is presented in NR1.
Summary
A given duration does not indicate exact time only an interval. To say "last 30 min" means nothing without knowing when you said "last 30 min" from.
Desired Behaviour
Users will want an ability to "freeze time" by specifying something akin to "last x time from when I made this selection". This utility function will allow us to convert that to an absolute timeRange.
Possible Solution
Additional context
Unable to find usage of this in any of the current public apps but it seems useful depending on how the TimePicker evolves and is presented in NR1.