diff --git a/src/components/withLocalize.js b/src/components/withLocalize.js index 918c05594825..a188e413ddf6 100755 --- a/src/components/withLocalize.js +++ b/src/components/withLocalize.js @@ -1,6 +1,8 @@ import React, {createContext, forwardRef} from 'react'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; +import lodashGet from 'lodash/get'; + import getComponentDisplayName from '../libs/getComponentDisplayName'; import ONYXKEYS from '../ONYXKEYS'; import * as Localize from '../libs/Localize'; @@ -9,6 +11,8 @@ import * as LocalePhoneNumber from '../libs/LocalePhoneNumber'; import * as NumberFormatUtils from '../libs/NumberFormatUtils'; import * as LocaleDigitUtils from '../libs/LocaleDigitUtils'; import CONST from '../CONST'; +import compose from '../libs/compose'; +import withCurrentUserPersonalDetails from './withCurrentUserPersonalDetails'; const LocaleContext = createContext(null); @@ -42,12 +46,24 @@ const localeProviderPropTypes = { /** The user's preferred locale e.g. 'en', 'es-ES' */ preferredLocale: PropTypes.string, - /* Actual content wrapped by this component */ + /** Actual content wrapped by this component */ children: PropTypes.node.isRequired, + + /** The current user's personalDetails */ + currentUserPersonalDetails: PropTypes.shape({ + + /** Timezone of the current user */ + timezone: PropTypes.shape({ + + /** Value of the selected timezone */ + selected: PropTypes.string, + }), + }), }; const localeProviderDefaultProps = { preferredLocale: CONST.DEFAULT_LOCALE, + currentUserPersonalDetails: {}, }; class LocaleContextProvider extends React.Component { @@ -105,6 +121,7 @@ class LocaleContextProvider extends React.Component { this.props.preferredLocale, datetime, includeTimezone, + lodashGet(this.props, 'currentUserPersonalDetails.timezone.selected'), ); } @@ -152,11 +169,14 @@ class LocaleContextProvider extends React.Component { LocaleContextProvider.propTypes = localeProviderPropTypes; LocaleContextProvider.defaultProps = localeProviderDefaultProps; -const Provider = withOnyx({ - preferredLocale: { - key: ONYXKEYS.NVP_PREFERRED_LOCALE, - }, -})(LocaleContextProvider); +const Provider = compose( + withCurrentUserPersonalDetails, + withOnyx({ + preferredLocale: { + key: ONYXKEYS.NVP_PREFERRED_LOCALE, + }, + }), +)(LocaleContextProvider); Provider.displayName = 'withOnyx(LocaleContextProvider)'; diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js index 6fc5aa83902a..663d3a5f93fa 100644 --- a/src/libs/DateUtils.js +++ b/src/libs/DateUtils.js @@ -49,6 +49,7 @@ function getLocalMomentFromDatetime(locale, datetime, currentSelectedTimezone = if (!datetime) { return moment.tz(currentSelectedTimezone); } + return moment.utc(datetime).tz(currentSelectedTimezone); } @@ -63,11 +64,12 @@ function getLocalMomentFromDatetime(locale, datetime, currentSelectedTimezone = * @param {String} locale * @param {String} datetime * @param {Boolean} includeTimeZone + * @param {String} [currentSelectedTimezone] * * @returns {String} */ -function datetimeToCalendarTime(locale, datetime, includeTimeZone = false) { - const date = getLocalMomentFromDatetime(locale, datetime); +function datetimeToCalendarTime(locale, datetime, includeTimeZone = false, currentSelectedTimezone) { + const date = getLocalMomentFromDatetime(locale, datetime, currentSelectedTimezone); const tz = includeTimeZone ? ' [UTC]Z' : ''; const todayAt = Localize.translate(locale, 'common.todayAt');