diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js
index 0d67cc369d93..791bd9e8c81c 100644
--- a/src/libs/DateUtils.js
+++ b/src/libs/DateUtils.js
@@ -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);
}
/**
@@ -136,6 +140,7 @@ const DateUtils = {
startCurrentDateUpdater,
updateTimezone,
throttledUpdateTimezone,
+ getLocalMomentFromTimestamp,
};
export default DateUtils;
diff --git a/src/pages/DetailsPage.js b/src/pages/DetailsPage.js
index c92874175396..46329d7b203d 100755
--- a/src/pages/DetailsPage.js
+++ b/src/pages/DetailsPage.js
@@ -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';
@@ -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({
@@ -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]);
diff --git a/src/pages/home/report/ParticipantLocalTime.js b/src/pages/home/report/ParticipantLocalTime.js
index 3b0339f01f7a..dcb48b101b06 100644
--- a/src/pages/home/report/ParticipantLocalTime.js
+++ b/src/pages/home/report/ParticipantLocalTime.js
@@ -3,7 +3,6 @@ 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';
@@ -11,6 +10,7 @@ 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 */
@@ -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() {
diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js
index 76ff0f2df1a2..c74745a8126d 100755
--- a/src/pages/home/report/ReportActionCompose.js
+++ b/src/pages/home/report/ReportActionCompose.js
@@ -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.
@@ -498,7 +497,7 @@ class ReportActionCompose extends React.Component {
]}
>
{shouldShowReportRecipientLocalTime
- && }
+ && }