diff --git a/public/app/core/utils/rangeutil.ts b/public/app/core/utils/rangeutil.ts index a75e1e777f3..89dba7b01a4 100644 --- a/public/app/core/utils/rangeutil.ts +++ b/public/app/core/utils/rangeutil.ts @@ -2,7 +2,7 @@ import moment = require('moment'); import _ = require('lodash'); -import dateMath = require('./datemath'); +import dateMath = require('app/core/utils/datemath'); import angular = require('angular'); var spans = { @@ -112,6 +112,10 @@ _.each(rangeOptions, function (frame) { return option.display; } + if (moment.isMoment(range.from) && moment.isMoment(range.to)) { + return formatDate(range.from) + ' to ' + formatDate(range.to); + } + if (moment.isMoment(range.from)) { var toMoment = dateMath.parse(range.to, true); return formatDate(range.from) + ' to ' + toMoment.fromNow(); diff --git a/public/app/features/dashboard/timepicker/timepicker.html b/public/app/features/dashboard/timepicker/timepicker.html index 322f456c146..264669a2050 100644 --- a/public/app/features/dashboard/timepicker/timepicker.html +++ b/public/app/features/dashboard/timepicker/timepicker.html @@ -15,7 +15,7 @@     - Refreshed every {{ctrl.dashboard.refresh}} + Refresh every {{ctrl.dashboard.refresh}} diff --git a/public/app/features/panel/panelHelper.js b/public/app/features/panel/panelHelper.js index 199434e6d1f..c7473692a43 100644 --- a/public/app/features/panel/panelHelper.js +++ b/public/app/features/panel/panelHelper.js @@ -83,7 +83,7 @@ function (angular, dateMath, rangeUtil, _, kbn, $) { } if (scope.panel.timeShift) { - var timeShiftInfo = rangeUtil.describeTextRange(scope.panel.timeFrom); + var timeShiftInfo = rangeUtil.describeTextRange(scope.panel.timeShift); if (timeShiftInfo.invalid) { scope.panelMeta.timeInfo = 'invalid timeshift'; return; diff --git a/public/app/panels/graph/graph.js b/public/app/panels/graph/graph.js index 29fa913c9c4..dce30643205 100755 --- a/public/app/panels/graph/graph.js +++ b/public/app/panels/graph/graph.js @@ -530,8 +530,8 @@ function (angular, $, kbn, moment, _, GraphTooltip) { elem.bind("plotselected", function (event, ranges) { scope.$apply(function() { timeSrv.setTime({ - from : moment.utc(ranges.xaxis.from).toDate(), - to : moment.utc(ranges.xaxis.to).toDate(), + from : moment.utc(ranges.xaxis.from), + to : moment.utc(ranges.xaxis.to), }); }); }); diff --git a/public/app/plugins/datasource/graphite/datasource.js b/public/app/plugins/datasource/graphite/datasource.js index fc2fd18cf5f..d51f9a93280 100644 --- a/public/app/plugins/datasource/graphite/datasource.js +++ b/public/app/plugins/datasource/graphite/datasource.js @@ -4,13 +4,12 @@ define([ 'jquery', 'config', 'app/core/utils/datemath', - 'moment', './directives', './queryCtrl', './funcEditor', './addGraphiteFunc', ], -function (angular, _, $, config, dateMath, moment) { +function (angular, _, $, config, dateMath) { 'use strict'; var module = angular.module('grafana.services'); @@ -145,11 +144,11 @@ function (angular, _, $, config, dateMath, moment) { }; GraphiteDatasource.prototype.translateTime = function(date, roundUp) { - if (_.isString(date) && date.indexOf('/') === 0) { + if (_.isString(date)) { if (date === 'now') { return 'now'; } - else if (date.indexOf('now-') >= 0) { + else if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) { date = date.substring(3); date = date.replace('m', 'min'); date = date.replace('M', 'mon'); @@ -158,8 +157,6 @@ function (angular, _, $, config, dateMath, moment) { date = dateMath.parse(date, roundUp); } - date = moment.utc(date); - // graphite' s from filter is exclusive // here we step back one minute in order // to guarantee that we get all the data that diff --git a/public/app/plugins/datasource/influxdb/datasource.js b/public/app/plugins/datasource/influxdb/datasource.js index 36cc80a15a0..b9ae9069323 100644 --- a/public/app/plugins/datasource/influxdb/datasource.js +++ b/public/app/plugins/datasource/influxdb/datasource.js @@ -176,8 +176,8 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) { }; function getTimeFilter(options) { - var from = getInfluxTime(options.rangeRaw.from); - var until = getInfluxTime(options.rangeRaw.to); + var from = getInfluxTime(options.rangeRaw.from, false); + var until = getInfluxTime(options.rangeRaw.to, true); var fromIsAbsolute = from[from.length-1] === 's'; if (until === 'now()' && !fromIsAbsolute) { @@ -187,15 +187,15 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) { return 'time > ' + from + ' and time < ' + until; } - function getInfluxTime(date) { + function getInfluxTime(date, roundUp) { if (_.isString(date)) { if (date === 'now') { return 'now()'; } - if (date.indexOf('now-') >= 0) { + if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) { return date.replace('now', 'now()').replace('-', ' - '); } - date = dateMath.parse(date); + date = dateMath.parse(date, roundUp); } return (date.valueOf() / 1000).toFixed(0) + 's'; } diff --git a/public/app/plugins/datasource/influxdb_08/datasource.js b/public/app/plugins/datasource/influxdb_08/datasource.js index 1c3c5688b67..5dabc93efa0 100644 --- a/public/app/plugins/datasource/influxdb_08/datasource.js +++ b/public/app/plugins/datasource/influxdb_08/datasource.js @@ -254,8 +254,8 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) { } function getTimeFilter(options) { - var from = getInfluxTime(options.rangeRaw.from); - var until = getInfluxTime(options.rangeRaw.to); + var from = getInfluxTime(options.rangeRaw.from, false); + var until = getInfluxTime(options.rangeRaw.to, true); var fromIsAbsolute = from[from.length-1] === 's'; if (until === 'now()' && !fromIsAbsolute) { @@ -265,15 +265,15 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) { return 'time > ' + from + ' and time < ' + until; } - function getInfluxTime(date) { - if (_.isString(date)) { + function getInfluxTime(date, roundUp) { + if (_.isString(date) && date.indexOf('/') === -1) { if (date === 'now') { return 'now()'; } if (date.indexOf('now-') >= 0) { return date.replace('now', 'now()'); } - date = dateMath.parse(date); + date = dateMath.parse(date, roundUp); } return (date.valueOf() / 1000).toFixed(0) + 's'; } diff --git a/public/app/plugins/datasource/kairosdb/datasource.js b/public/app/plugins/datasource/kairosdb/datasource.js index 6db99f5a244..80507f060eb 100644 --- a/public/app/plugins/datasource/kairosdb/datasource.js +++ b/public/app/plugins/datasource/kairosdb/datasource.js @@ -1,11 +1,12 @@ define([ 'angular', 'lodash', + 'app/core/utils/datemath', 'kbn', './queryCtrl', './directives', ], -function (angular, _, kbn) { +function (angular, _, dateMath, kbn) { 'use strict'; var module = angular.module('grafana.services'); @@ -21,8 +22,8 @@ function (angular, _, kbn) { // Called once per panel (graph) KairosDBDatasource.prototype.query = function(options) { - var start = options.range.from; - var end = options.range.to; + var start = options.rangeRaw.from; + var end = options.rangeRaw.to; var queries = _.compact(_.map(options.targets, _.partial(convertTargetToQuery, options))); var plotParams = _.compact(_.map(options.targets, function(target) { @@ -394,7 +395,7 @@ function (angular, _, kbn) { if (date === 'now') { return; } - else if (date.indexOf('now-') >= 0) { + else if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) { date = date.substring(4); name = start_stop_name + "_relative"; var re_date = /(\d+)\s*(\D+)/; @@ -414,16 +415,11 @@ function (angular, _, kbn) { return; } - date = kbn.parseDate(date); + date = dateMath.parse(date, start_stop_name === 'end'); } - if (_.isDate(date)) { - name = start_stop_name + "_absolute"; - response_obj[name] = date.getTime(); - return; - } - - console.log("Date is neither string nor date"); + name = start_stop_name + "_absolute"; + response_obj[name] = date.valueOf(); } function convertToKairosDBTimeUnit(unit) { diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index 612324e7543..c4fd7dc5f77 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -1,12 +1,12 @@ define([ 'angular', 'lodash', - 'kbn', + 'app/core/utils/datemath', 'moment', './directives', './queryCtrl', ], -function (angular, _, kbn) { +function (angular, _, dateMath) { 'use strict'; var module = angular.module('grafana.services'); @@ -22,8 +22,8 @@ function (angular, _, kbn) { // Called once per panel (graph) OpenTSDBDatasource.prototype.query = function(options) { - var start = convertToTSDBTime(options.range.from); - var end = convertToTSDBTime(options.range.to); + var start = convertToTSDBTime(options.rangeRaw.from, false); + var end = convertToTSDBTime(options.rangeRaw.to, true); var qs = []; _.each(options.targets, function(target) { @@ -277,14 +277,13 @@ function (angular, _, kbn) { }); } - function convertToTSDBTime(date) { + function convertToTSDBTime(date, roundUp) { if (date === 'now') { return null; } - date = kbn.parseDate(date); - - return date.getTime(); + date = dateMath.parse(date, roundUp); + return date.valueOf(); } return OpenTSDBDatasource; diff --git a/public/test/specs/core/utils/rangeutil_specs.ts b/public/test/specs/core/utils/rangeutil_specs.ts index 2ea2b6c348f..8dd407f8f3d 100644 --- a/public/test/specs/core/utils/rangeutil_specs.ts +++ b/public/test/specs/core/utils/rangeutil_specs.ts @@ -4,7 +4,7 @@ import rangeUtil = require('app/core/utils/rangeutil') import _ = require('lodash') import moment = require('moment') -describe.only("rangeUtil", () => { +describe("rangeUtil", () => { describe("Can get range text described", () => { it('should handle simple old expression with only amount and unit', () => { diff --git a/public/test/specs/kairosdb-datasource-specs.js b/public/test/specs/kairosdb-datasource-specs.js index e50e07a9373..edee99752f7 100644 --- a/public/test/specs/kairosdb-datasource-specs.js +++ b/public/test/specs/kairosdb-datasource-specs.js @@ -27,7 +27,7 @@ define([ }; var query = { - range: { from: 'now-1h', to: 'now' }, + rangeRaw: { from: 'now-1h', to: 'now' }, targets: [{ metric: 'test', downsampling: '(NONE)'}] };