From 5ad38ee9f82cd6c1cee74ce73170f71952a07fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 17 Sep 2015 09:57:59 +0200 Subject: [PATCH] feat(timepicker2): fixed timesrv specs --- public/app/features/dashboard/timeSrv.js | 8 ++++---- public/test/specs/timeSrv-specs.js | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/public/app/features/dashboard/timeSrv.js b/public/app/features/dashboard/timeSrv.js index 9bf9512966f..7bca4a51790 100644 --- a/public/app/features/dashboard/timeSrv.js +++ b/public/app/features/dashboard/timeSrv.js @@ -30,10 +30,10 @@ define([ this._parseTime = function() { // when absolute time is saved in json it is turned to a string if (_.isString(this.time.from) && this.time.from.indexOf('Z') >= 0) { - this.time.from = new Date(this.time.from); + this.time.from = moment(this.time.from); } if (_.isString(this.time.to) && this.time.to.indexOf('Z') >= 0) { - this.time.to = new Date(this.time.to); + this.time.to = moment(this.time.to); } }; @@ -113,8 +113,8 @@ define([ range = this.timeRange(); } - if (_.isDate(range.from)) { range.from = range.from.getTime(); } - if (_.isDate(range.to)) { range.to = range.to.getTime(); } + if (moment.isMoment(range.from)) { range.from = range.from.valueOf(); } + if (moment.isMoment(range.to)) { range.to = range.to.valueOf(); } return range; }; diff --git a/public/test/specs/timeSrv-specs.js b/public/test/specs/timeSrv-specs.js index 316a784f3ed..e4ba27d379b 100644 --- a/public/test/specs/timeSrv-specs.js +++ b/public/test/specs/timeSrv-specs.js @@ -2,9 +2,10 @@ define([ '../mocks/dashboard-mock', './helpers', 'lodash', + 'moment', 'app/services/timer', 'app/features/dashboard/timeSrv' -], function(dashboardMock, helpers, _) { +], function(dashboardMock, helpers, _, moment) { 'use strict'; describe('timeSrv', function() { @@ -31,8 +32,8 @@ define([ it('should return parsed when parse is true', function() { ctx.service.setTime({from: 'now', to: 'now-1h' }); var time = ctx.service.timeRange(true); - expect(_.isDate(time.from)).to.be(true); - expect(_.isDate(time.to)).to.be(true); + expect(moment.isMoment(time.from)).to.be(true); + expect(moment.isMoment(time.to)).to.be(true); }); }); @@ -51,8 +52,8 @@ define([ ctx.$routeParams.to = '20140520T031022'; ctx.service.init(_dashboard); var time = ctx.service.timeRange(true); - expect(time.from.getTime()).to.equal(new Date("2014-04-10T05:20:10Z").getTime()); - expect(time.to.getTime()).to.equal(new Date("2014-05-20T03:10:22Z").getTime()); + expect(time.from.valueOf()).to.equal(new Date("2014-04-10T05:20:10Z").getTime()); + expect(time.to.valueOf()).to.equal(new Date("2014-05-20T03:10:22Z").getTime()); }); it('should handle formated dates without time', function() { @@ -60,8 +61,8 @@ define([ ctx.$routeParams.to = '20140520'; ctx.service.init(_dashboard); var time = ctx.service.timeRange(true); - expect(time.from.getTime()).to.equal(new Date("2014-04-10T00:00:00Z").getTime()); - expect(time.to.getTime()).to.equal(new Date("2014-05-20T00:00:00Z").getTime()); + expect(time.from.valueOf()).to.equal(new Date("2014-04-10T00:00:00Z").getTime()); + expect(time.to.valueOf()).to.equal(new Date("2014-05-20T00:00:00Z").getTime()); }); it('should handle epochs', function() { @@ -69,8 +70,8 @@ define([ ctx.$routeParams.to = '1410337665699'; ctx.service.init(_dashboard); var time = ctx.service.timeRange(true); - expect(time.from.getTime()).to.equal(1410337646373); - expect(time.to.getTime()).to.equal(1410337665699); + expect(time.from.valueOf()).to.equal(1410337646373); + expect(time.to.valueOf()).to.equal(1410337665699); }); });