Skip to content

Commit ce35f48

Browse files
authored
Switch from moment to luxon (#5352)
Moment is ..deprecated, https://momentjs.com/docs/#/-project-status/ Switching DateComponent to luxon.
1 parent b1265da commit ce35f48

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

package-lock.json

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"file-saver": "^2.0.5",
2121
"js-cookie": "^3.0.5",
2222
"lodash": "^4.17.21",
23-
"moment": "^2.30.1",
23+
"luxon": "^3.5.0",
2424
"monaco-editor": "^0.44.0",
2525
"monaco-yaml": "^5.2.2",
2626
"react": "^18.3.1",

src/components/date-component.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import * as moment from 'moment';
1+
import { DateTime } from 'luxon';
22
import React from 'react';
33
import { Tooltip } from 'src/components';
4+
import { language as locale } from 'src/l10n';
5+
6+
const dateFormat = (date) =>
7+
DateTime.fromISO(date, { locale }).toFormat('d MMMM y, HH:mm z');
8+
const relativeFormat = (date) =>
9+
DateTime.fromISO(date, { locale }).toRelative();
410

511
export const DateComponent = ({ date }: { date: string }) =>
612
date && (
713
<time dateTime={date}>
8-
<Tooltip content={moment(date).format('DD MMMM YYYY, HH:mm Z')}>
9-
{moment(date).fromNow()}
10-
</Tooltip>
14+
<Tooltip content={dateFormat(date)}>{relativeFormat(date)}</Tooltip>
1115
</time>
1216
);

src/l10n.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { i18n } from '@lingui/core';
2-
import * as moment from 'moment';
32

43
// remember to update lingui.config.js as well
54
export const availableLanguages = [
@@ -12,6 +11,7 @@ export const availableLanguages = [
1211
'ja',
1312
'zh',
1413
];
14+
1515
export const languageNames = {
1616
en: 'English',
1717
es: 'Español',
@@ -23,11 +23,6 @@ export const languageNames = {
2323
zh: '中文',
2424
};
2525

26-
// map missing moment locales (node_modules/moment/src/locale/<locale>.js must exist, except for english)
27-
const momentLocales = {
28-
zh: 'zh-cn',
29-
};
30-
3126
async function activate(locale: string, pseudolocalization = false) {
3227
const { messages } = await import(`src/../locale/${locale}.js`);
3328

@@ -45,8 +40,6 @@ async function activate(locale: string, pseudolocalization = false) {
4540

4641
i18n.load(locale, messages);
4742
i18n.activate(locale);
48-
49-
moment.locale(momentLocales[locale] || locale);
5043
}
5144

5245
// Accept-Language

0 commit comments

Comments
 (0)