Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ Onyx.connect({
*
* @param {String} locale
* @param {Number} timestamp
* @param {String} [currentSelectedTimezone]
*
* @returns {Moment}
*
* @private
*/
function getLocalMomentFromTimestamp(locale, timestamp) {
function getLocalMomentFromTimestamp(locale, timestamp, currentSelectedTimezone = timezone.selected) {
moment.locale(locale);
return moment.unix(timestamp).tz(timezone.selected);
if (!timestamp) {
return moment.tz(currentSelectedTimezone);
}
return moment.unix(timestamp).tz(currentSelectedTimezone);
}

/**
Expand Down Expand Up @@ -136,6 +140,7 @@ const DateUtils = {
startCurrentDateUpdater,
updateTimezone,
throttledUpdateTimezone,
getLocalMomentFromTimestamp,
};

export default DateUtils;
4 changes: 2 additions & 2 deletions src/pages/DetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import moment from 'moment';
import styles from '../styles/styles';
import Text from '../components/Text';
import ONYXKEYS from '../ONYXKEYS';
Expand All @@ -18,6 +17,7 @@ import CommunicationsLink from '../components/CommunicationsLink';
import Tooltip from '../components/Tooltip';
import CONST from '../CONST';
import * as ReportUtils from '../libs/reportUtils';
import DateUtils from '../libs/DateUtils';

const matchType = PropTypes.shape({
params: PropTypes.shape({
Expand Down Expand Up @@ -66,7 +66,7 @@ const DetailsPage = (props) => {
// If we have a reportID param this means that we
// arrived here via the ParticipantsPage and should be allowed to navigate back to it
const shouldShowBackButton = Boolean(props.route.params.reportID);
const timezone = moment().tz(details.timezone.selected);
const timezone = DateUtils.getLocalMomentFromTimestamp(props.preferredLocale, null, details.timezone.selected);
const GMTTime = `${timezone.toString().split(/[+-]/)[0].slice(-3)} ${timezone.zoneAbbr()}`;
const currentTime = Number.isNaN(Number(timezone.zoneAbbr())) ? timezone.zoneAbbr() : GMTTime;
const shouldShowLocalTime = !ReportUtils.hasExpensifyEmails([details.login]);
Expand Down
13 changes: 7 additions & 6 deletions src/pages/home/report/ParticipantLocalTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
View,
} from 'react-native';
import lodashGet from 'lodash/get';
import moment from 'moment';
import Str from 'expensify-common/lib/str';
import styles from '../../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import {participantPropTypes} from '../sidebar/optionPropTypes';
import Text from '../../../components/Text';
import Timers from '../../../libs/Timers';
import CONST from '../../../CONST';
import DateUtils from '../../../libs/DateUtils';

const propTypes = {
/** Personal details of the participant */
Expand Down Expand Up @@ -42,14 +42,15 @@ class ParticipantLocalTime extends PureComponent {

getParticipantLocalTime() {
const reportRecipientTimezone = lodashGet(this.props.participant, 'timezone', CONST.DEFAULT_TIME_ZONE);
moment.locale(this.props.preferredLocale);
const reportRecipientDay = moment().tz(reportRecipientTimezone.selected).format('dddd');
const currentUserDay = moment().tz(this.props.currentUserTimezone.selected).format('dddd');
const reportTimezone = DateUtils.getLocalMomentFromTimestamp(this.props.preferredLocale, null, reportRecipientTimezone.selected);
const currentTimezone = DateUtils.getLocalMomentFromTimestamp(this.props.preferredLocale);
const reportRecipientDay = reportTimezone.format('dddd');
const currentUserDay = currentTimezone.format('dddd');

if (reportRecipientDay !== currentUserDay) {
return `${moment().tz(reportRecipientTimezone.selected).format('LT')} ${reportRecipientDay}`;
return `${reportTimezone.format('LT')} ${reportRecipientDay}`;
}
return `${moment().tz(reportRecipientTimezone.selected).format('LT')}`;
return `${reportTimezone.format('LT')}`;
}

render() {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ class ReportActionCompose extends React.Component {
const hasMultipleParticipants = reportParticipants.length > 1;
const hasExcludedIOUEmails = lodashIntersection(reportParticipants, CONST.EXPENSIFY_EMAILS).length > 0;
const reportRecipient = this.props.personalDetails[reportParticipants[0]];
const currentUserTimezone = lodashGet(this.props.myPersonalDetails, 'timezone', CONST.DEFAULT_TIME_ZONE);
const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(this.props.personalDetails, this.props.myPersonalDetails, this.props.report);

// Prevents focusing and showing the keyboard while the drawer is covering the chat.
Expand All @@ -498,7 +497,7 @@ class ReportActionCompose extends React.Component {
]}
>
{shouldShowReportRecipientLocalTime
&& <ParticipantLocalTime participant={reportRecipient} currentUserTimezone={currentUserTimezone} />}
&& <ParticipantLocalTime participant={reportRecipient} />}
<View style={[
(this.state.isFocused || this.state.isDraggingOver)
? styles.chatItemComposeBoxFocusedColor
Expand Down