From 121502a0a82a900058644ac3f147ff3a928dcd2e Mon Sep 17 00:00:00 2001 From: John Bodley Date: Thu, 24 Oct 2019 16:44:35 -0700 Subject: [PATCH] [fix] Making client time UTC --- UPDATING.md | 3 +++ .../components/controls/DateFilterControl.jsx | 23 +++++++++++++++---- superset/assets/src/explore/controls.jsx | 8 +++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/UPDATING.md b/UPDATING.md index b4aa9e56e31f7..0669447429a85 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -23,6 +23,9 @@ assists people when migrating to a new version. ## Next Version +* [8450](https://github.com/apache/incubator-superset/pull/8450): The time ranger picker +now uses UTC for the tooltips and default placeholder timestamps (san timezone). + * [8370](https://github.com/apache/incubator-superset/pull/8370): Deprecates the `HTTP_HEADERS` variable in favor of `DEFAULT_HTTP_HEADERS` and `OVERRIDE_HTTP_HEADERS`. To retain the same behavior you should use diff --git a/superset/assets/src/explore/components/controls/DateFilterControl.jsx b/superset/assets/src/explore/components/controls/DateFilterControl.jsx index 1f5fbf9822c35..eb16064ac8694 100644 --- a/superset/assets/src/explore/components/controls/DateFilterControl.jsx +++ b/superset/assets/src/explore/components/controls/DateFilterControl.jsx @@ -67,8 +67,15 @@ const COMMON_TIME_FRAMES = [ const TIME_GRAIN_OPTIONS = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years']; const MOMENT_FORMAT = 'YYYY-MM-DD[T]HH:mm:ss'; -const DEFAULT_SINCE = moment().startOf('day').subtract(7, 'days').format(MOMENT_FORMAT); -const DEFAULT_UNTIL = moment().startOf('day').format(MOMENT_FORMAT); +const DEFAULT_SINCE = moment() + .utc() + .startOf('day') + .subtract(7, 'days') + .format(MOMENT_FORMAT); +const DEFAULT_UNTIL = moment() + .utc() + .startOf('day') + .format(MOMENT_FORMAT); const SEPARATOR = ' : '; const FREEFORM_TOOLTIP = t( 'Superset supports smart date parsing. Strings like `last sunday` or ' + @@ -116,8 +123,12 @@ function getStateFromCommonTimeFrame(value) { tab: TABS.DEFAULTS, type: TYPES.DEFAULTS, common: value, - since: moment().startOf('day').subtract(1, units).format(MOMENT_FORMAT), - until: moment().startOf('day').format(MOMENT_FORMAT), + since: moment() + .utc() + .startOf('day') + .subtract(1, units) + .format(MOMENT_FORMAT), + until: moment().utc().startOf('day').format(MOMENT_FORMAT), }; } @@ -126,13 +137,15 @@ function getStateFromCustomRange(value) { let since; let until; if (rel === RELATIVE_TIME_OPTIONS.LAST) { - until = moment().startOf('day').format(MOMENT_FORMAT); + until = moment().utc().startOf('day').format(MOMENT_FORMAT); since = moment() + .utc() .startOf('day') .subtract(num, grain) .format(MOMENT_FORMAT); } else { until = moment() + .utc() .startOf('day') .add(num, grain) .format(MOMENT_FORMAT); diff --git a/superset/assets/src/explore/controls.jsx b/superset/assets/src/explore/controls.jsx index 8f06ae6171468..bfa8586891bf0 100644 --- a/superset/assets/src/explore/controls.jsx +++ b/superset/assets/src/explore/controls.jsx @@ -951,6 +951,14 @@ export const controls = { freeForm: true, label: t('Time range'), default: t('Last week'), + description: t( + 'The time range for the visualization. All relative times, e.g. "Last month", ' + + '"Last 7 days", "now", etc. are evaluated on the server using the server\'s ' + + 'local time (sans timezone). All tooltips and placeholder times are expressed ' + + 'in UTC (sans timezone). The timestamps are then evaluated by the database ' + + 'using the engine\'s local timezone. Note one can explicitly set the timezone ' + + 'per the ISO 8601 format if specifying either the start and/or end time.', + ), }, max_bubble_size: {