Skip to content

Commit 48beb99

Browse files
authored
chore: migrate from momentjs to dayjs (#6724)
1 parent f3e1497 commit 48beb99

File tree

28 files changed

+111
-72
lines changed

28 files changed

+111
-72
lines changed

app/containers/MessageActions/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { forwardRef, useImperativeHandle } from 'react';
22
import { Alert, Share } from 'react-native';
33
import Clipboard from '@react-native-clipboard/clipboard';
44
import { connect } from 'react-redux';
5-
import moment from 'moment';
65

6+
import dayjs from '../../lib/dayjs';
77
import database from '../../lib/database';
88
import { getSubscriptionByRoomId } from '../../lib/database/services/Subscription';
99
import I18n from '../../i18n';
@@ -154,11 +154,11 @@ const MessageActions = React.memo(
154154
if (blockEditInMinutes) {
155155
let msgTs;
156156
if (message.ts != null) {
157-
msgTs = moment(message.ts);
157+
msgTs = dayjs(message.ts);
158158
}
159159
let currentTsDiff = 0;
160160
if (msgTs != null) {
161-
currentTsDiff = moment().diff(msgTs, 'minutes');
161+
currentTsDiff = dayjs().diff(msgTs, 'minutes');
162162
}
163163
return currentTsDiff < blockEditInMinutes;
164164
}
@@ -185,11 +185,11 @@ const MessageActions = React.memo(
185185
if (blockDeleteInMinutes != null && blockDeleteInMinutes !== 0) {
186186
let msgTs;
187187
if (message.ts != null) {
188-
msgTs = moment(message.ts);
188+
msgTs = dayjs(message.ts);
189189
}
190190
let currentTsDiff = 0;
191191
if (msgTs != null) {
192-
currentTsDiff = moment().diff(msgTs, 'minutes');
192+
currentTsDiff = dayjs().diff(msgTs, 'minutes');
193193
}
194194
return currentTsDiff < blockDeleteInMinutes;
195195
}

app/containers/MessageComposer/components/Quotes/Quote.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { View, Text } from 'react-native';
3-
import moment from 'moment';
43

4+
import dayjs from '../../../../lib/dayjs';
55
import { useTheme } from '../../../../theme';
66
import sharedStyles from '../../../../views/Styles';
77
import { useRoomContext } from '../../../../views/RoomView/context';
@@ -25,7 +25,7 @@ export const Quote = ({ messageId }: { messageId: string }) => {
2525
if (message) {
2626
username = useRealName ? message.u?.name || message.u?.username || '' : message.u?.username || '';
2727
msg = message.msg || '';
28-
time = message.ts ? moment(message.ts).format('LT') : '';
28+
time = message.ts ? dayjs(message.ts).format('LT') : '';
2929
}
3030

3131
if (!message) {

app/containers/MessageSeparator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
3-
import moment from 'moment';
43

4+
import dayjs from '../lib/dayjs';
55
import I18n from '../i18n';
66
import sharedStyles from '../views/Styles';
77
import { themes } from '../lib/constants/colors';
@@ -36,7 +36,7 @@ const MessageSeparator = ({ ts, unread }: { ts?: Date | string | null; unread?:
3636
return null;
3737
}
3838

39-
const date = ts ? moment(ts).format('LL') : null;
39+
const date = ts ? dayjs(ts).format('LL') : null;
4040
const unreadLine = { backgroundColor: themes[theme].buttonBackgroundDangerDefault };
4141
const unreadText = { color: themes[theme].fontDanger };
4242
if (ts && unread) {

app/containers/Passcode/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import AsyncStorage from '@react-native-async-storage/async-storage';
2-
import moment from 'moment';
32

3+
import dayjs from '../../lib/dayjs';
44
import { LOCKED_OUT_TIMER_KEY, TIME_TO_LOCK } from '../../lib/constants/localAuthentication';
55

66
export const getLockedUntil = async () => {
77
const t = await AsyncStorage.getItem(LOCKED_OUT_TIMER_KEY);
88
if (t) {
9-
return moment(t).add(TIME_TO_LOCK).toDate();
9+
return dayjs(t).add(TIME_TO_LOCK, 'millisecond').toDate();
1010
}
1111
return null;
1212
};

app/containers/SupportedVersions/useSupportedVersionMessage.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import moment from 'moment';
2-
1+
import dayjs from '../../lib/dayjs';
32
import { useAppSelector } from '../../lib/hooks/useAppSelector';
43

54
const applyParams = (message: string, params: Record<string, unknown>) => {
@@ -25,7 +24,7 @@ export const useSupportedVersionMessage = () => {
2524
instance_email: email,
2625
instance_ws_name: name,
2726
instance_domain: server,
28-
remaining_days: moment(expiration).diff(new Date(), 'days'),
27+
remaining_days: dayjs(expiration).diff(new Date(), 'days'),
2928
instance_version: version,
3029
...message?.params
3130
};

app/containers/UIKit/DatePicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { StyleSheet, Text, unstable_batchedUpdates, View } from 'react-native';
33
import DateTimePicker, { type BaseProps } from '@react-native-community/datetimepicker';
44
import Touchable from 'react-native-platform-touchable';
55
import { BlockContext } from '@rocket.chat/ui-kit';
6-
import moment from 'moment';
76

7+
import dayjs from '../../lib/dayjs';
88
import Button from '../Button';
99
import { textParser } from './utils';
1010
import { themes } from '../../lib/constants/colors';
@@ -54,7 +54,7 @@ export const DatePicker = ({ element, language, action, context, loading, value,
5454
onShow(false);
5555
}
5656
});
57-
action({ value: moment(newDate).format('YYYY-MM-DD') });
57+
action({ value: dayjs(newDate).format('YYYY-MM-DD') });
5858
}
5959
};
6060

app/containers/message/Components/Attachments/Reply.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { dequal } from 'dequal';
2-
import moment from 'moment';
32
import React, { useContext, useState } from 'react';
43
import { StyleSheet, Text, View } from 'react-native';
54
import { Image } from 'expo-image';
@@ -17,6 +16,7 @@ import { Attachments } from './components';
1716
import MessageContext from '../../Context';
1817
import Touchable from '../../Touchable';
1918
import messageStyles from '../../styles';
19+
import dayjs from '../../../../lib/dayjs';
2020

2121
const styles = StyleSheet.create({
2222
button: {
@@ -103,7 +103,7 @@ const Title = React.memo(
103103
({ attachment, timeFormat, theme }: { attachment: IAttachment; timeFormat?: string; theme: TSupportedThemes }) => {
104104
'use memo';
105105

106-
const time = attachment.message_link && attachment.ts ? moment(attachment.ts).format(timeFormat) : null;
106+
const time = attachment.message_link && attachment.ts ? dayjs(attachment.ts).format(timeFormat) : null;
107107
return (
108108
<View style={styles.authorContainer}>
109109
{attachment.author_name ? (

app/containers/message/Time.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import moment from 'moment';
21
import React from 'react';
32
import { Text } from 'react-native';
43

4+
import dayjs from '../../lib/dayjs';
55
import { useTheme } from '../../theme';
66
import messageStyles from './styles';
77

@@ -15,7 +15,7 @@ const MessageTime = ({ timeFormat, ts }: IMessageTime) => {
1515

1616
const { colors } = useTheme();
1717

18-
const time = moment(ts).format(timeFormat);
18+
const time = dayjs(ts).format(timeFormat);
1919

2020
return <Text style={[messageStyles.time, { color: colors.fontSecondaryInfo }]}>{time}</Text>;
2121
};

app/i18n/moment.ts renamed to app/i18n/dayjs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const localeKeys: { [key: string]: string } = {
1515
sv: 'sv',
1616
tr: 'tr',
1717
'zh-CN': 'zh-cn',
18-
'zh-TW': 'zh-tw'
18+
'zh-TW': 'zh-tw',
19+
no: 'nb'
1920
};
2021

21-
export const toMomentLocale = (locale: string): string => localeKeys[locale];
22+
export const toDayJsLocale = (locale: string): string => localeKeys[locale] || locale;

app/i18n/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import i18n from 'i18n-js';
22
import { I18nManager } from 'react-native';
33
import * as RNLocalize from 'react-native-localize';
4-
import moment from 'moment';
5-
import 'moment/min/locales';
64

7-
import { toMomentLocale } from './moment';
5+
import dayjs from '../lib/dayjs/index';
6+
import { toDayJsLocale } from './dayjs';
87
import { isRTL } from './isRTL';
98
import englishJson from './locales/en.json';
109

@@ -177,7 +176,7 @@ export const setLanguage = (l: string) => {
177176
// TODO: Review this logic
178177
// @ts-ignore
179178
i18n.isRTL = I18nManager.isRTL;
180-
moment.locale(toMomentLocale(locale));
179+
dayjs.locale(toDayJsLocale(locale));
181180
};
182181

183182
i18n.translations = { en: translations.en?.() };

0 commit comments

Comments
 (0)