mattermost-mobile/app/components/formatted_date/index.tsx
Elias Nahum a4e4e18445
[Gekidou] perf improvement & fix upgrade path (#6302)
* Improve loading display name of direct channels

* Improve team switching

* Improve perceived performance when opening the app with an active session

* Fix upgrade path from v1

* Set moment locale while formatting date

* feedback review
2022-05-24 08:45:17 -04:00

32 lines
1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import moment from 'moment-timezone';
import React from 'react';
import {useIntl} from 'react-intl';
import {Text, TextProps} from 'react-native';
type FormattedDateProps = TextProps & {
format?: string;
timezone?: string | UserTimezone | null;
value: number | string | Date;
}
const FormattedDate = ({format = 'MMM DD, YYYY', timezone, value, ...props}: FormattedDateProps) => {
const {locale} = useIntl();
moment.locale(locale);
let formattedDate = moment(value).format(format);
if (timezone) {
let zone: string;
if (typeof timezone === 'object') {
zone = timezone.useAutomaticTimezone ? timezone.automaticTimezone : timezone.manualTimezone;
} else {
zone = timezone;
}
formattedDate = moment.tz(value, zone).format(format);
}
return <Text {...props}>{formattedDate}</Text>;
};
export default FormattedDate;