From 167c02d7731049a20699ba767cc2783a023bc86f Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Tue, 10 Nov 2015 04:53:42 -0800 Subject: [PATCH 1/3] Timepicker display fixed for now-* --- public/app/core/utils/rangeutil.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/app/core/utils/rangeutil.ts b/public/app/core/utils/rangeutil.ts index 1e64fcc0061..3fc4252ceaf 100644 --- a/public/app/core/utils/rangeutil.ts +++ b/public/app/core/utils/rangeutil.ts @@ -133,6 +133,10 @@ _.each(rangeOptions, function (frame) { return from.fromNow() + ' to ' + formatDate(range.to); } + if (!moment.isMoment(range.from) && !moment.isMoment(range.to)) { + return formatDate(dateMath.parse(range.from, true)) + ' to ' + formatDate(dateMath.parse(range.to, true)); + } + var res = describeTextRange(range.from); return res.display; } From 509c3dc715b89c3599d464cdf353931a0544ffbb Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 11 Nov 2015 01:34:24 -0800 Subject: [PATCH 2/3] Fixed time range when using NOW from and to --- public/app/core/utils/rangeutil.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/app/core/utils/rangeutil.ts b/public/app/core/utils/rangeutil.ts index 3fc4252ceaf..dda67725208 100644 --- a/public/app/core/utils/rangeutil.ts +++ b/public/app/core/utils/rangeutil.ts @@ -133,12 +133,12 @@ _.each(rangeOptions, function (frame) { return from.fromNow() + ' to ' + formatDate(range.to); } - if (!moment.isMoment(range.from) && !moment.isMoment(range.to)) { - return formatDate(dateMath.parse(range.from, true)) + ' to ' + formatDate(dateMath.parse(range.to, true)); + if (range.to.toString() === 'now') { + var res = describeTextRange(range.from); + return res.display; } - var res = describeTextRange(range.from); - return res.display; + return range.from.toString() + ' to ' + range.to.toString(); } export = { From 9f17e4ee2cf1aa34b27395e7d60f928251d576ea Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 11 Nov 2015 01:34:53 -0800 Subject: [PATCH 3/3] Added unit tests to verify time range fix --- public/test/specs/core/utils/rangeutil_specs.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/public/test/specs/core/utils/rangeutil_specs.ts b/public/test/specs/core/utils/rangeutil_specs.ts index 8816a15f73d..32286764c20 100644 --- a/public/test/specs/core/utils/rangeutil_specs.ts +++ b/public/test/specs/core/utils/rangeutil_specs.ts @@ -80,6 +80,22 @@ describe("rangeUtil", () => { var text = rangeUtil.describeTimeRange({from: 'now-13h', to: 'now'}); expect(text).to.be('Last 13 hours') }); + + it('Date range with from and to both are in now-* format', () => { + var text = rangeUtil.describeTimeRange({from: 'now-6h', to: 'now-3h'}); + expect(text).to.be('now-6h to now-3h') + }); + + it('Date range with from and to both are either in now-* or now/* format', () => { + var text = rangeUtil.describeTimeRange({from: 'now/d+6h', to: 'now-3h'}); + expect(text).to.be('now/d+6h to now-3h') + }); + + it('Date range with from and to both are either in now-* or now+* format', () => { + var text = rangeUtil.describeTimeRange({from: 'now-6h', to: 'now+1h'}); + expect(text).to.be('now-6h to now+1h') + }); + }); });