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

feat(durationToAbsoluteRange): Utility function for converting duration to begin_time/end_time #32

Open
devfreddy opened this issue Jan 28, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@devfreddy
Copy link
Contributor

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

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.

@devfreddy devfreddy added the enhancement New feature or request label Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant