timerange.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ = require('lodash');
  3. import moment = require('moment');
  4. var rangeOptions = [
  5. { from: 'now/d', to: 'now/d', display: 'Today', section: 0 },
  6. { from: 'now/w', to: 'now/w', display: 'This week', section: 0 },
  7. { from: 'now/d', to: 'now', display: 'The day so far', section: 0 },
  8. { from: 'now/w', to: 'now', display: 'Week to date', section: 0 },
  9. // { from: 'now/M', to: 'now/M', display: 'This month', section: 0 },
  10. // { from: 'now/y', to: 'now/y', display: 'This year', section: 0 },
  11. //
  12. // { from: 'now-1d/d', to: 'now-1d/d', display: 'Yesterday', section: 1 },
  13. // { from: 'now-2d/d', to: 'now-2d/d', display: 'Day before yesterday', section: 1 },
  14. // { from: 'now-7d/d', to: 'now-7d/d', display: 'This day last week', section: 1 },
  15. // { from: 'now-1w/w', to: 'now-1w/w', display: 'Previous week', section: 1 },
  16. // { from: 'now-1M/M', to: 'now-1M/M', display: 'Previous month', section: 1 },
  17. // { from: 'now-1y/y', to: 'now-1y/y', display: 'Previous year', section: 1 },
  18. { from: 'now-5m', to: 'now', display: 'Last 5 minutes', section: 2 },
  19. { from: 'now-15m', to: 'now', display: 'Last 15 minutes', section: 2 },
  20. { from: 'now-30m', to: 'now', display: 'Last 30 minutes', section: 2 },
  21. { from: 'now-1h', to: 'now', display: 'Last 1 hour', section: 2 },
  22. { from: 'now-4h', to: 'now', display: 'Last 4 hours', section: 2 },
  23. { from: 'now-12h', to: 'now', display: 'Last 12 hours', section: 2 },
  24. { from: 'now-24h', to: 'now', display: 'Last 24 hours', section: 2 },
  25. { from: 'now-7d', to: 'now', display: 'Last 7 days', section: 2 },
  26. { from: 'now-30d', to: 'now', display: 'Last 30 days', section: 3 },
  27. // { from: 'now-60d', to: 'now', display: 'Last 60 days', section: 3 },
  28. // { from: 'now-90d', to: 'now', display: 'Last 90 days', section: 3 },
  29. // { from: 'now-6M', to: 'now', display: 'Last 6 months', section: 3 },
  30. // { from: 'now-1y', to: 'now', display: 'Last 1 year', section: 3 },
  31. // { from: 'now-2y', to: 'now', display: 'Last 2 years', section: 3 },
  32. // { from: 'now-5y', to: 'now', display: 'Last 5 years', section: 3 },
  33. ];
  34. var rangeIndex = {};
  35. _.each(rangeOptions, function (frame) {
  36. rangeIndex[frame.from + ' to ' + frame.to] = frame;
  37. });
  38. export class TimeRange {
  39. static getRelativeTimesList(timepickerSettings) {
  40. return rangeOptions;
  41. }
  42. static describeRelativeTime(range) {
  43. var option = rangeIndex[range.from.toString() + ' to ' + range.to.toString()];
  44. if (option) {
  45. return option.display;
  46. }
  47. return "NA";
  48. }
  49. }