Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
chore(deps): replace moment.js with day.js for locale handling (#15875)
Oğuzhan Selim Temiz85fe5cf31e7a
diff --git a/package-lock.json b/package-lock.jsonindex cf4a21ad7f..a13502e0c3 100644--- a/package-lock.json+++ b/package-lock.json@@ -48,6 +48,7 @@"bc-css-flags": "3.0.0","clipboard-copy": "4.0.1","clsx": "1.1.1",+ "dayjs": "1.11.13","dropbox": "10.7.0","focus-visible": "5.1.0","grapheme-splitter": "1.0.4",@@ -63,8 +64,6 @@"jwt-decode": "2.2.0","lib-jitsi-meet": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v1991.0.0+80c2686a/lib-jitsi-meet.tgz","lodash-es": "4.17.21",- "moment": "2.29.4",- "moment-duration-format": "2.2.2","null-loader": "4.0.1","optional-require": "1.0.3","pixelmatch": "5.3.0",@@ -135,7 +134,6 @@"@types/lodash-es": "4.17.12","@types/minimatch": "5.1.2","@types/mocha": "10.0.10",- "@types/moment-duration-format": "2.2.6","@types/offscreencanvas": "2019.7.2","@types/pixelmatch": "5.2.5","@types/pretty": "2.0.3",@@ -7369,15 +7367,6 @@"dev": true,"license": "MIT"},- "node_modules/@types/moment-duration-format": {- "version": "2.2.6",- "resolved": "https://registry.npmjs.org/@types/moment-duration-format/-/moment-duration-format-2.2.6.tgz",- "integrity": "sha512-Qw+6ys3sQCatqukjoIBsL1UJq6S7ep4ixrNvDkdViSgzw2ZG3neArXNu3ww7mEG8kwP32ZDoON/esWb7OUckRQ==",- "dev": true,- "dependencies": {- "moment": ">=2.14.0"- }- },"node_modules/@types/mute-stream": {"version": "0.0.4","resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz",@@ -18710,19 +18699,6 @@"node": ">=10"}},- "node_modules/moment": {- "version": "2.29.4",- "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",- "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",- "engines": {- "node": "*"- }- },- "node_modules/moment-duration-format": {- "version": "2.2.2",- "resolved": "https://registry.npmjs.org/moment-duration-format/-/moment-duration-format-2.2.2.tgz",- "integrity": "sha1-uVdhLeJgFsmtnrYIfAVFc+USd3k="- },"node_modules/mrmime": {"version": "1.0.0","resolved": "https://registry.npmjs.org/mrmime/-/mrmime-1.0.0.tgz",@@ -30742,15 +30718,6 @@"integrity": "sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q==","dev": true},- "@types/moment-duration-format": {- "version": "2.2.6",- "resolved": "https://registry.npmjs.org/@types/moment-duration-format/-/moment-duration-format-2.2.6.tgz",- "integrity": "sha512-Qw+6ys3sQCatqukjoIBsL1UJq6S7ep4ixrNvDkdViSgzw2ZG3neArXNu3ww7mEG8kwP32ZDoON/esWb7OUckRQ==",- "dev": true,- "requires": {- "moment": ">=2.14.0"- }- },"@types/mute-stream": {"version": "0.0.4","resolved": "https://registry.npmjs.org/@types/mute-stream/-/mute-stream-0.0.4.tgz",@@ -38940,16 +38907,6 @@}}},- "moment": {- "version": "2.29.4",- "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",- "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="- },- "moment-duration-format": {- "version": "2.2.2",- "resolved": "https://registry.npmjs.org/moment-duration-format/-/moment-duration-format-2.2.2.tgz",- "integrity": "sha1-uVdhLeJgFsmtnrYIfAVFc+USd3k="- },"mrmime": {"version": "1.0.0","resolved": "https://registry.npmjs.org/mrmime/-/mrmime-1.0.0.tgz",diff --git a/package.json b/package.jsonindex 06480a4e4f..fdf5c0d6c5 100644--- a/package.json+++ b/package.json@@ -54,6 +54,7 @@"bc-css-flags": "3.0.0","clipboard-copy": "4.0.1","clsx": "1.1.1",+ "dayjs": "1.11.13","dropbox": "10.7.0","focus-visible": "5.1.0","grapheme-splitter": "1.0.4",@@ -69,8 +70,6 @@"jwt-decode": "2.2.0","lib-jitsi-meet": "https://github.com/jitsi/lib-jitsi-meet/releases/download/v1991.0.0+80c2686a/lib-jitsi-meet.tgz","lodash-es": "4.17.21",- "moment": "2.29.4",- "moment-duration-format": "2.2.2","null-loader": "4.0.1","optional-require": "1.0.3","pixelmatch": "5.3.0",@@ -141,7 +140,6 @@"@types/lodash-es": "4.17.12","@types/minimatch": "5.1.2","@types/mocha": "10.0.10",- "@types/moment-duration-format": "2.2.6","@types/offscreencanvas": "2019.7.2","@types/pixelmatch": "5.2.5","@types/pretty": "2.0.3",diff --git a/react-native-sdk/package.json b/react-native-sdk/package.jsonindex 6e7210204c..ec661701b9 100644--- a/react-native-sdk/package.json+++ b/react-native-sdk/package.json@@ -23,6 +23,7 @@"@stomp/stompjs": "0.0.0","@xmldom/xmldom": "0.0.0","base64-js": "0.0.0",+ "dayjs": "0.0.0","grapheme-splitter": "0.0.0","i18n-iso-countries": "0.0.0","i18next": "0.0.0",@@ -32,8 +33,6 @@"jwt-decode": "0.0.0","lib-jitsi-meet": "0.0.0","lodash-es": "0.0.0",- "moment": "0.0.0",- "moment-duration-format": "0.0.0","optional-require": "0.0.0","promise.allsettled": "0.0.0","promise.withresolvers": "0.0.0",diff --git a/react/features/base/i18n/dateUtil.ts b/react/features/base/i18n/dateUtil.tsindex e61e67b419..6ad888a9c5 100644--- a/react/features/base/i18n/dateUtil.ts+++ b/react/features/base/i18n/dateUtil.ts@@ -1,65 +1,81 @@-import moment from 'moment';-import momentDurationFormatSetup from 'moment-duration-format';+import dayjs from 'dayjs';+import durationPlugin from 'dayjs/plugin/duration';+import relativeTimePlugin from 'dayjs/plugin/relativeTime';+import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';import i18next from './i18next';-// allows for moment durations to be formatted-momentDurationFormatSetup(moment);+dayjs.extend(durationPlugin);+dayjs.extend(relativeTimePlugin);+dayjs.extend(localizedFormatPlugin);-// MomentJS uses static language bundle loading, so in order to support dynamic+// Day.js uses static language bundle loading, so in order to support dynamic// language selection in the app we need to load all bundles that we support in// the app.-require('moment/locale/af');-require('moment/locale/ar');-require('moment/locale/be');-require('moment/locale/bg');-require('moment/locale/ca');-require('moment/locale/cs');-require('moment/locale/da');-require('moment/locale/de');-require('moment/locale/el');-require('moment/locale/en-gb');-require('moment/locale/eo');-require('moment/locale/es-us');-require('moment/locale/es');-require('moment/locale/et');-require('moment/locale/eu');-require('moment/locale/fa');-require('moment/locale/fi');-require('moment/locale/fr-ca');-require('moment/locale/fr');-require('moment/locale/gl');-require('moment/locale/he');-require('moment/locale/hr');-require('moment/locale/hu');-require('moment/locale/hy-am');-require('moment/locale/id');-require('moment/locale/is');-require('moment/locale/it');-require('moment/locale/ja');-require('moment/locale/ko');-require('moment/locale/lt');-require('moment/locale/lv');-require('moment/locale/ml');-require('moment/locale/mn');-require('moment/locale/mr');-require('moment/locale/nb');-require('moment/locale/nl');-require('moment/locale/oc-lnc');-require('moment/locale/pl');-require('moment/locale/pt');-require('moment/locale/pt-br');-require('moment/locale/ro');-require('moment/locale/ru');-require('moment/locale/sk');-require('moment/locale/sl');-require('moment/locale/sr');-require('moment/locale/sv');-require('moment/locale/tr');-require('moment/locale/uk');-require('moment/locale/vi');-require('moment/locale/zh-cn');-require('moment/locale/zh-tw');+import 'dayjs/locale/af';+import 'dayjs/locale/ar';+import 'dayjs/locale/be';+import 'dayjs/locale/bg';+import 'dayjs/locale/ca';+import 'dayjs/locale/cs';+import 'dayjs/locale/da';+import 'dayjs/locale/de';+import 'dayjs/locale/el';+import 'dayjs/locale/eo';+import 'dayjs/locale/es';+import 'dayjs/locale/es-us';+import 'dayjs/locale/et';+import 'dayjs/locale/eu';+import 'dayjs/locale/fa';+import 'dayjs/locale/fi';+import 'dayjs/locale/fr';+import 'dayjs/locale/fr-ca';+import 'dayjs/locale/gl';+import 'dayjs/locale/he';+import 'dayjs/locale/hi';+import 'dayjs/locale/hr';+import 'dayjs/locale/hu';+import 'dayjs/locale/hy-am';+import 'dayjs/locale/id';+import 'dayjs/locale/is';+import 'dayjs/locale/it';+import 'dayjs/locale/ja';+import 'dayjs/locale/ko';+import 'dayjs/locale/lt';+import 'dayjs/locale/lv';+import 'dayjs/locale/ml';+import 'dayjs/locale/mn';+import 'dayjs/locale/mr';+import 'dayjs/locale/nb';+import 'dayjs/locale/nl';+import 'dayjs/locale/oc-lnc';+import 'dayjs/locale/pl';+import 'dayjs/locale/pt';+import 'dayjs/locale/pt-br';+import 'dayjs/locale/ro';+import 'dayjs/locale/ru';+import 'dayjs/locale/sk';+import 'dayjs/locale/sl';+import 'dayjs/locale/sq';+import 'dayjs/locale/sr';+import 'dayjs/locale/sv';+import 'dayjs/locale/te';+import 'dayjs/locale/tr';+import 'dayjs/locale/uk';+import 'dayjs/locale/vi';+import 'dayjs/locale/zh-cn';+import 'dayjs/locale/zh-tw';++const LOCALE_MAPPING: Record<string, string> = {+ // i18next -> dayjs+ 'hy': 'hy-am',+ 'oc': 'oc-lnc',+ 'zhCN': 'zh-cn',+ 'zhTW': 'zh-tw',+ 'ptBR': 'pt-br',+ 'esUS': 'es-us',+ 'frCA': 'fr-ca'+};/*** Returns a localized date formatter initialized with a specific {@code Date}@@ -71,7 +87,7 @@ require('moment/locale/zh-tw');* @returns {Object}*/export function getLocalizedDateFormatter(dateOrTimeStamp: Date | number) {- return moment(dateOrTimeStamp).locale(_getSupportedLocale());+ return dayjs(dateOrTimeStamp).locale(_getSupportedLocale());}/**@@ -84,23 +100,17 @@ export function getLocalizedDateFormatter(dateOrTimeStamp: Date | number) {* @returns {Object}*/export function getLocalizedDurationFormatter(duration: number) {- // FIXME The flow-type definition of moment is v2.3 while our package.json- // states v2.19 so maybe locale on moment's duration was introduced in- // between?- //-// If the conference is under an hour long we want to display it without// showing the hour and we want to include the hour if the conference is// more than an hour long- // @ts-ignore- if (moment.duration(duration).format('h') !== '0') {- // @ts-ignore- return moment.duration(duration).format('h:mm:ss');+ const d = dayjs.duration(duration);++ if (d.hours() !== 0) {+ return d.format('h:mm:ss');}- // @ts-ignore- return moment.duration(duration).format('mm:ss', { trim: false });+ return d.format('mm:ss');}/**@@ -110,9 +120,18 @@ export function getLocalizedDurationFormatter(duration: number) {* @returns {string}*/function _getSupportedLocale() {+ const availableLocales = Object.keys(dayjs.Ls);const i18nLocale = i18next.language;let supportedLocale;+ if (LOCALE_MAPPING[i18nLocale]) {+ return LOCALE_MAPPING[i18nLocale];+ }++ if (availableLocales.includes(i18nLocale)) {+ return i18nLocale;+ }+if (i18nLocale) {const localeRegexp = new RegExp('^([a-z]{2,2})(-)*([a-z]{2,2})*$');const localeResult = localeRegexp.exec(i18nLocale.toLowerCase());@@ -123,11 +142,7 @@ function _getSupportedLocale() {`^${localeResult[1]}(-)*${`(${localeResult[3]})*` || ''}`);supportedLocale-- // FIXME The flow-type definition of moment is v2.3 while our- // package.json states v2.19 so maybe locales on moment was- // introduced in between?- = moment.locales().find(lang => currentLocaleRegexp.exec(lang));+ = availableLocales.find(lang => currentLocaleRegexp.exec(lang));}}