Skip to content

Commit

Permalink
Switch from moment to luxon (#5352)
Browse files Browse the repository at this point in the history
Moment is ..deprecated, https://momentjs.com/docs/#/-project-status/

Switching DateComponent to luxon.
  • Loading branch information
himdel authored Dec 13, 2024
1 parent b1265da commit ce35f48
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"file-saver": "^2.0.5",
"js-cookie": "^3.0.5",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"luxon": "^3.5.0",
"monaco-editor": "^0.44.0",
"monaco-yaml": "^5.2.2",
"react": "^18.3.1",
Expand Down
12 changes: 8 additions & 4 deletions src/components/date-component.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as moment from 'moment';
import { DateTime } from 'luxon';
import React from 'react';
import { Tooltip } from 'src/components';
import { language as locale } from 'src/l10n';

const dateFormat = (date) =>
DateTime.fromISO(date, { locale }).toFormat('d MMMM y, HH:mm z');
const relativeFormat = (date) =>
DateTime.fromISO(date, { locale }).toRelative();

export const DateComponent = ({ date }: { date: string }) =>
date && (
<time dateTime={date}>
<Tooltip content={moment(date).format('DD MMMM YYYY, HH:mm Z')}>
{moment(date).fromNow()}
</Tooltip>
<Tooltip content={dateFormat(date)}>{relativeFormat(date)}</Tooltip>
</time>
);
9 changes: 1 addition & 8 deletions src/l10n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { i18n } from '@lingui/core';
import * as moment from 'moment';

// remember to update lingui.config.js as well
export const availableLanguages = [
Expand All @@ -12,6 +11,7 @@ export const availableLanguages = [
'ja',
'zh',
];

export const languageNames = {
en: 'English',
es: 'Español',
Expand All @@ -23,11 +23,6 @@ export const languageNames = {
zh: '中文',
};

// map missing moment locales (node_modules/moment/src/locale/<locale>.js must exist, except for english)
const momentLocales = {
zh: 'zh-cn',
};

async function activate(locale: string, pseudolocalization = false) {
const { messages } = await import(`src/../locale/${locale}.js`);

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

i18n.load(locale, messages);
i18n.activate(locale);

moment.locale(momentLocales[locale] || locale);
}

// Accept-Language
Expand Down

0 comments on commit ce35f48

Please sign in to comment.