Merge branch 'ctide-day_rounding2'

This commit is contained in:
Torkel Ödegaard 2017-10-02 16:45:44 +02:00
commit fa79be1f2d
5 changed files with 23 additions and 7 deletions

View File

@ -19,6 +19,7 @@
* **Prometheus**: Add support for instant queries [#5765](https://github.com/grafana/grafana/issues/5765), thx [@mtanda](https://github.com/mtanda) * **Prometheus**: Add support for instant queries [#5765](https://github.com/grafana/grafana/issues/5765), thx [@mtanda](https://github.com/mtanda)
* **Cloudwatch**: Add support for alerting using the cloudwatch datasource [#8050](https://github.com/grafana/grafana/pull/8050), thx [@mtanda](https://github.com/mtanda) * **Cloudwatch**: Add support for alerting using the cloudwatch datasource [#8050](https://github.com/grafana/grafana/pull/8050), thx [@mtanda](https://github.com/mtanda)
* **Pagerduty**: Include triggering series in pagerduty notification [#8479](https://github.com/grafana/grafana/issues/8479), thx [@rickymoorhouse](https://github.com/rickymoorhouse) * **Pagerduty**: Include triggering series in pagerduty notification [#8479](https://github.com/grafana/grafana/issues/8479), thx [@rickymoorhouse](https://github.com/rickymoorhouse)
* **Timezone**: Time ranges like Today & Yesterday now work correctly when timezone setting is set to UTC [#8916](https://github.com/grafana/grafana/issues/8916), thx [@ctide](https://github.com/ctide)
## Minor ## Minor
* **SMTP**: Make it possible to set specific EHLO for smtp client. [#9319](https://github.com/grafana/grafana/issues/9319) * **SMTP**: Make it possible to set specific EHLO for smtp client. [#9319](https://github.com/grafana/grafana/issues/9319)

View File

@ -5,7 +5,7 @@ import moment from 'moment';
var units = ['y', 'M', 'w', 'd', 'h', 'm', 's']; var units = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
export function parse(text, roundUp?) { export function parse(text, roundUp?, timezone?) {
if (!text) { return undefined; } if (!text) { return undefined; }
if (moment.isMoment(text)) { return text; } if (moment.isMoment(text)) { return text; }
if (_.isDate(text)) { return moment(text); } if (_.isDate(text)) { return moment(text); }
@ -16,7 +16,11 @@ export function parse(text, roundUp?) {
var parseString; var parseString;
if (text.substring(0, 3) === 'now') { if (text.substring(0, 3) === 'now') {
if (timezone === 'utc') {
time = moment.utc();
} else {
time = moment(); time = moment();
}
mathString = text.substring('now'.length); mathString = text.substring('now'.length);
} else { } else {
index = text.indexOf('||'); index = text.indexOf('||');

View File

@ -196,9 +196,11 @@ class TimeSrv {
to: moment.isMoment(this.time.to) ? moment(this.time.to) : this.time.to, to: moment.isMoment(this.time.to) ? moment(this.time.to) : this.time.to,
}; };
var timezone = this.dashboard && this.dashboard.getTimezone();
return { return {
from: dateMath.parse(raw.from, false), from: dateMath.parse(raw.from, false, timezone),
to: dateMath.parse(raw.to, true), to: dateMath.parse(raw.to, true, timezone),
raw: raw raw: raw
}; };
} }

View File

@ -218,6 +218,7 @@ class MetricsPanelCtrl extends PanelCtrl {
}); });
var metricsQuery = { var metricsQuery = {
timezone: this.dashboard.getTimezone(),
panelId: this.panel.id, panelId: this.panel.id,
range: this.range, range: this.range,
rangeRaw: this.range.raw, rangeRaw: this.range.raw,

View File

@ -46,6 +46,14 @@ describe("DateMath", () => {
expect(startOfDay).to.be(expected.getTime()); expect(startOfDay).to.be(expected.getTime());
}); });
it("now/d on a utc dashboard should be start of the current day in UTC time", () => {
var today = new Date();
var expected = new Date(Date.UTC(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0, 0));
var startOfDay = dateMath.parse('now/d', false, 'utc').valueOf();
expect(startOfDay).to.be(expected.getTime());
});
describe('subtraction', () => { describe('subtraction', () => {
var now; var now;
var anchored; var anchored;