diff --git a/app/components/formatted_time.js b/app/components/formatted_time.js index cb6c95998..2d1e4d750 100644 --- a/app/components/formatted_time.js +++ b/app/components/formatted_time.js @@ -3,28 +3,35 @@ import React from 'react'; import PropTypes from 'prop-types'; -import {injectIntl, intlShape} from 'react-intl'; import {Text} from 'react-native'; -class FormattedTime extends React.PureComponent { +export default class FormattedTime extends React.PureComponent { static propTypes = { - intl: intlShape.isRequired, value: PropTypes.any.isRequired, - format: PropTypes.string, children: PropTypes.func, + hour12: PropTypes.bool, }; render() { const { - intl, value, children, - ...props + hour12, } = this.props; - Reflect.deleteProperty(props, 'format'); + const date = new Date(value); + const militaryTime = !hour12; - const formattedTime = intl.formatDate(value, {...props, hour: 'numeric', minute: 'numeric'}); + const hour = militaryTime ? date.getHours() : (date.getHours() % 12 || 12); + let minute = date.getMinutes(); + minute = minute >= 10 ? minute : ('0' + minute); + let time = ''; + + if (!militaryTime) { + time = (date.getHours() >= 12 ? ' PM' : ' AM'); + } + + const formattedTime = hour + ':' + minute + time; if (typeof children === 'function') { return children(formattedTime); @@ -33,5 +40,3 @@ class FormattedTime extends React.PureComponent { return {formattedTime}; } } - -export default injectIntl(FormattedTime);