Skip to content

Commit

Permalink
handle ignore daylight time correctly and fix shift problem
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Jan 19, 2022
1 parent d2a8bb9 commit c51565b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class TimeseriesVisualization extends Component {
legend={Boolean(model.show_legend)}
legendPosition={model.legend_position}
truncateLegend={Boolean(model.truncate_legend)}
ignoreDaylightTime={Boolean(model.ignore_daylight_time)}
maxLegendLines={model.max_lines_legend}
tooltipMode={model.tooltip_mode}
xAxisFormatter={this.xAxisFormatter(interval)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const TimeSeries = ({
interval,
isLastBucketDropped,
useLegacyTimeAxis,
ignoreDaylightTime,
}) => {
// If the color isn't configured by the user, use the color mapping service
// to assign a color from the Kibana palette. Colors will be shared across the
Expand Down Expand Up @@ -152,7 +153,9 @@ export const TimeSeries = ({
const shouldUseNewTimeAxis =
series.every(
({ stack, bars, lines }) => (bars?.show && stack !== STACKED_OPTIONS.NONE) || lines?.show
) && !useLegacyTimeAxis;
) &&
!useLegacyTimeAxis &&
!ignoreDaylightTime;

return (
<Chart ref={chartRef} renderer="canvas" className={classes}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@
*/

import { startsWith } from 'lodash';
import moment from 'moment';
import moment from 'moment-timezone';

export function timeShift(resp, panel, series) {
export function timeShift(
resp,
panel,
series,
meta,
extractFields,
fieldFormatService,
cachedIndexPatternFetcher,
timezone
) {
return (next) => (results) => {
if (/^([+-]?[\d]+)([shmdwMy]|ms)$/.test(series.offset_time)) {
const matches = series.offset_time.match(/^([+-]?[\d]+)([shmdwMy]|ms)$/);
Expand All @@ -18,14 +27,29 @@ export function timeShift(resp, panel, series) {
const offsetValue = matches[1];
const offsetUnit = matches[2];

let defaultTimezone;
if (!panel.ignore_daylight_time) {
// the datemath plugin always parses dates by using the current default moment time zone.
// to use the configured time zone, we are switching just for the bounds calculation.
defaultTimezone = moment().zoneName();
moment.tz.setDefault(timezone);
}

results.forEach((item) => {
if (startsWith(item.id, series.id)) {
item.data = item.data.map((row) => [
moment.utc(row[0]).add(offsetValue, offsetUnit).valueOf(),
(panel.ignore_daylight_time ? moment.utc : moment)(row[0])
.add(offsetValue, offsetUnit)
.valueOf(),
row[1],
]);
}
});

if (!panel.ignore_daylight_time) {
// reset default moment timezone
moment.tz.setDefault(defaultTimezone);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function handleResponseBody(
meta,
extractFields,
fieldFormatService,
services.cachedIndexPatternFetcher
services.cachedIndexPatternFetcher,
req.body.timerange.timezone
);

return await processor([]);
Expand Down

0 comments on commit c51565b

Please sign in to comment.