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
32 changes: 26 additions & 6 deletions src/components/withLocalize.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -105,6 +121,7 @@ class LocaleContextProvider extends React.Component {
this.props.preferredLocale,
datetime,
includeTimezone,
lodashGet(this.props, 'currentUserPersonalDetails.timezone.selected'),
);
}

Expand Down Expand Up @@ -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)';

Expand Down
6 changes: 4 additions & 2 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function getLocalMomentFromDatetime(locale, datetime, currentSelectedTimezone =
if (!datetime) {
return moment.tz(currentSelectedTimezone);
}

return moment.utc(datetime).tz(currentSelectedTimezone);
}

Expand All @@ -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');
Expand Down