Files
mattermost-mobile/app/components/formatted_date/index.tsx
Elias Nahum 0b4980cf65 [Gekidou] multiple fixes (#6335)
* Fix navigation stack tracking

* Fix hardwareBackPress handlers

* Use user locale for formattedTime

* Show in-app notifications when in a thread but hide when in the same thread

* Fix post draft archived & read only safe area

* Do not show reply post option in thread screen

* Open permalink as full screen modal

* Fix crash when using chinese locale

* Fix team list and call handle team change
2022-06-03 07:18:29 -04:00

35 lines
1.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';
import {getLocaleFromLanguage} from '@i18n';
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(getLocaleFromLanguage(locale).toLowerCase());
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;