Skip to content

Commit 20a952d

Browse files
ref(js): No need to pass timezone to moment (#91862)
We already set the default timezone in moment.tz to the user's configured timezone. This is done here https://github.com/getsentry/sentry/blob/20b05fc91a4ad6783bff1875327f4570bcfb5d00/static/app/stores/configStore.tsx#L47 We had two types of moment invocations that did not require us to pass the users timezone: - `moment.tz(myDate, userTimezone)` - `moment(myDate).tz(userTimezone)` Here are some examples showing that these work fine WITHOUT providing the timezone and letting moment fall back to it's default ```tsx // Set timezone to America/New_York. We ALWAYS were doing this const userTz = 'America/New_York'; moment.tz.setDefault(userTz); // A few Example timestamps. All of our server response timestamps will // be at UTC, but for illustration purposes we can also look at dates // specified in other timezones const dateUTC = '2014-06-01T12:00:00-00:00'; const dateNY = '2014-06-01T12:00:00-04:00'; // Calling moment.tz with or without the timezone always localizes to // America/New_York because of the default moment.tz(dateUTC, userTz).format(); // '2014-06-01T08:00:00-04:00' moment(dateUTC).tz(userTz).format(); // '2014-06-01T08:00:00-04:00' moment(dateUTC).format(); // '2014-06-01T08:00:00-04:00' // Passing a date as a different timezone moment.tz(dateLA, userTz).format(); // '2014-06-01T15:00:00-04:00' moment(dateLA).format(); // '2014-06-01T15:00:00-04:00' ```
1 parent f431944 commit 20a952d

File tree

8 files changed

+19
-52
lines changed

8 files changed

+19
-52
lines changed

static/app/components/timeSince.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function TimeSince({
164164
fixed: options?.clock24Hours
165165
? 'November 3, 2020 08:57 UTC'
166166
: 'November 3, 2020 8:58 AM UTC',
167-
value: moment.tz(dateObj, options?.timezone ?? '').format(format),
167+
value: moment(dateObj).format(format),
168168
});
169169

170170
return (

static/app/views/alerts/rules/metric/details/metricChart.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import PanelBody from 'sentry/components/panels/panelBody';
3535
import Placeholder from 'sentry/components/placeholder';
3636
import {IconCheckmark, IconClock, IconFire, IconWarning} from 'sentry/icons';
3737
import {t} from 'sentry/locale';
38-
import ConfigStore from 'sentry/stores/configStore';
3938
import {space} from 'sentry/styles/space';
4039
import type {DateString} from 'sentry/types/core';
4140
import type {Series} from 'sentry/types/echarts';
@@ -93,10 +92,7 @@ interface MetricChartProps {
9392
}
9493

9594
function formatTooltipDate(date: moment.MomentInput, format: string): string {
96-
const {
97-
options: {timezone},
98-
} = ConfigStore.get('user');
99-
return moment.tz(date, timezone).format(format);
95+
return moment(date).format(format);
10096
}
10197

10298
export function getRuleChangeSeries(

static/app/views/alerts/rules/metric/details/metricChartOption.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {AreaChartProps, AreaChartSeries} from 'sentry/components/charts/are
77
import MarkArea from 'sentry/components/charts/components/markArea';
88
import MarkLine from 'sentry/components/charts/components/markLine';
99
import {t} from 'sentry/locale';
10-
import ConfigStore from 'sentry/stores/configStore';
1110
import {space} from 'sentry/styles/space';
1211
import type {Series} from 'sentry/types/echarts';
1312
import type {SessionApiResponse} from 'sentry/types/organization';
@@ -29,10 +28,7 @@ import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
2928
import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
3029

3130
function formatTooltipDate(date: moment.MomentInput, format: string): string {
32-
const {
33-
options: {timezone},
34-
} = ConfigStore.get('user');
35-
return moment.tz(date, timezone).format(format);
31+
return moment(date).format(format);
3632
}
3733

3834
function createStatusAreaSeries(

static/app/views/alerts/rules/metric/utils/anomalyChart.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import moment from 'moment-timezone';
44

55
import type {AreaChartSeries} from 'sentry/components/charts/areaChart';
66
import MarkLine from 'sentry/components/charts/components/markLine';
7-
import ConfigStore from 'sentry/stores/configStore';
87
import type {Anomaly} from 'sentry/views/alerts/types';
98
import {AnomalyType} from 'sentry/views/alerts/types';
109

@@ -156,8 +155,5 @@ function getDateForTimestamp(timestamp: string | number): Date {
156155
}
157156

158157
function formatTooltipDate(date: moment.MomentInput, format: string): string {
159-
const {
160-
options: {timezone},
161-
} = ConfigStore.get('user');
162-
return moment.tz(date, timezone).format(format);
158+
return moment(date).format(format);
163159
}

static/app/views/automations/components/automationHistoryList.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import moment from 'moment-timezone';
22

33
import {DateTime} from 'sentry/components/dateTime';
44
import Link from 'sentry/components/links/link';
5+
import {useTimezone} from 'sentry/components/timezoneProvider';
56
import {defineColumns, SimpleTable} from 'sentry/components/workflowEngine/simpleTable';
67
import {t, tct} from 'sentry/locale';
7-
import ConfigStore from 'sentry/stores/configStore';
88

99
interface AutomationHistoryData {
1010
dateSent: Date;
@@ -37,10 +37,7 @@ const getColumns = (timezone: string) =>
3737
});
3838

3939
export default function AutomationHistoryList({history}: Props) {
40-
const {
41-
options: {timezone},
42-
} = ConfigStore.get('user');
43-
40+
const timezone = useTimezone();
4441
const columns = getColumns(timezone);
4542

4643
return <SimpleTable columns={columns} data={history} />;

static/app/views/issueDetails/groupCheckIns.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,11 @@ function CheckInCell({
160160
{dataRow.expectedTime && (
161161
<Fragment>
162162
<dt>{t('Expected at')}</dt>
163-
<dd>
164-
{moment
165-
.tz(dataRow.expectedTime, userOptions?.timezone ?? '')
166-
.format(format)}
167-
</dd>
163+
<dd>{moment(dataRow.expectedTime).format(format)}</dd>
168164
</Fragment>
169165
)}
170166
<dt>{t('Received at')}</dt>
171-
<dd>
172-
{moment
173-
.tz(dataRow[columnKey], userOptions?.timezone ?? '')
174-
.format(format)}
175-
</dd>
167+
<dd>{moment(dataRow[columnKey]).format(format)}</dd>
176168
</LabelledTooltip>
177169
}
178170
>

static/app/views/releases/list/releaseCard/index.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,11 @@ function ReleaseCard({
166166
<Tooltip
167167
isHoverable
168168
title={tct('This release was finalized on [date]. [docs:Read More].', {
169-
date: moment
170-
.tz(release.dateReleased, options?.timezone ?? '')
171-
.format(
172-
options?.clock24Hours
173-
? 'MMMM D, YYYY HH:mm z'
174-
: 'MMMM D, YYYY h:mm A z'
175-
),
169+
date: moment(release.dateReleased).format(
170+
options?.clock24Hours
171+
? 'MMMM D, YYYY HH:mm z'
172+
: 'MMMM D, YYYY h:mm A z'
173+
),
176174
docs: (
177175
<ExternalLink href="https://docs.sentry.io/cli/releases/#finalizing-releases" />
178176
),
@@ -186,16 +184,11 @@ function ReleaseCard({
186184
title={tct(
187185
'Set release date to [date].[br]Finalizing a release means that we populate a second timestamp on the release record, which is prioritized over [code:date_created] when sorting releases. [docs:Read more].',
188186
{
189-
date: moment
190-
.tz(
191-
release.firstEvent ?? release.dateCreated,
192-
options?.timezone ?? ''
193-
)
194-
.format(
195-
options?.clock24Hours
196-
? 'MMMM D, YYYY HH:mm z'
197-
: 'MMMM D, YYYY h:mm A z'
198-
),
187+
date: moment(release.firstEvent ?? release.dateCreated).format(
188+
options?.clock24Hours
189+
? 'MMMM D, YYYY HH:mm z'
190+
: 'MMMM D, YYYY h:mm A z'
191+
),
199192
br: <br />,
200193
code: <code />,
201194
docs: (

static/gsApp/hooks/firstPartyIntegrationAlertHook.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import moment from 'moment-timezone';
44
import {Alert} from 'sentry/components/core/alert';
55
import {t} from 'sentry/locale';
66
import type {Integration} from 'sentry/types/integrations';
7-
import {getUserTimezone} from 'sentry/utils/dates';
87
import AlertContainer from 'sentry/views/settings/organizationIntegrations/integrationAlertContainer';
98

109
import UpsellButton from 'getsentry/components/upsellButton';
@@ -39,9 +38,7 @@ function FirstPartyIntegrationAlertHook({
3938
t(
4039
'Your %s integration will be disabled after %s',
4140
integration.provider.name,
42-
moment(integration.gracePeriodEnd)
43-
.tz(getUserTimezone())
44-
.format('MMMM Do, YYYY h:mm A z')
41+
moment(integration.gracePeriodEnd).format('MMMM Do, YYYY h:mm A z')
4542
),
4643
'grace-period',
4744
integration.provider.key,

0 commit comments

Comments
 (0)