Skip to content

Commit ced98a8

Browse files
authored
fix(ui): moment deprecated date formatting in getFormattedTimestamp() (#102599)
This fixes the following console.warn that we are getting in prod: ``` Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. Arguments: ``` `getRelativeTime()` is passed 2 `moment` objects that are formatted into a non-standard date string, that is used to re-create another `moment` object. We can use the `moment` arguments directly instead.
1 parent 1eeb5e9 commit ced98a8

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

static/app/utils/date/getFormattedTimestamp.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ import {t} from 'sentry/locale';
44
import getDuration from 'sentry/utils/duration/getDuration';
55

66
const timeFormat = 'HH:mm:ss';
7-
const timeDateFormat = `ll ${timeFormat}`;
87

98
const getRelativeTime = (
109
parsedTime: ReturnType<typeof moment>,
1110
parsedTimeToCompareWith: ReturnType<typeof moment>,
1211
displayRelativeTime?: boolean
1312
) => {
14-
// ll is necessary here, otherwise moment(x).from will throw an error
15-
const formattedTime = moment(parsedTime.format(timeDateFormat));
16-
const formattedTimeToCompareWith = parsedTimeToCompareWith.format(timeDateFormat);
17-
const timeDiff = Math.abs(formattedTime.diff(formattedTimeToCompareWith));
13+
const timeDiff = Math.abs(parsedTime.diff(parsedTimeToCompareWith));
1814

1915
const shortRelativeTime = getDuration(Math.round(timeDiff / 1000), 0, true).replace(
2016
/\s/g,

0 commit comments

Comments
 (0)