mattermost-mobile/app/components/formatted_date/index.tsx
Elias Nahum fcc6394502
Gekidou fixes (#5748)
* Use Intl based on user locale

* set PROMPT_IN_APP_PIN_CODE_AFTER to wait for 5 mins

* Observables Improvements

* Fix iPad external keyboard listener

* file model description
2021-10-13 14:13:39 -03:00

27 lines
904 B
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 {Text, TextProps} from 'react-native';
type FormattedDateProps = TextProps & {
format?: string;
timezone?: string | UserTimezone | null;
value: number | string | Date;
}
const FormattedDate = ({format = 'ddd, MMM DD, YYYY', timezone, value, ...props}: FormattedDateProps) => {
let formattedDate = moment(value).format(format);
if (timezone) {
let zone = timezone as string;
if (typeof timezone === 'object') {
zone = timezone.useAutomaticTimezone ? timezone.automaticTimezone : timezone.manualTimezone;
}
formattedDate = moment.tz(value, zone).format(format);
}
return <Text {...props}>{formattedDate}</Text>;
};
export default FormattedDate;