Skip to content

Commit

Permalink
Merge pull request #5307 from kidroca/kidroca/DateUtils-timezone-init…
Browse files Browse the repository at this point in the history
…ial-value-fix

Add safety net for timezone in DateUtils
  • Loading branch information
luacmartins authored Sep 16, 2021
2 parents 93129e6 + 0d0490d commit ea45c24
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import moment from 'moment-timezone';
import lodashGet from 'lodash/get';

// IMPORTANT: load any locales (other than english) that might be passed to moment.locale()
import 'moment/locale/es';
Expand All @@ -10,11 +11,11 @@ import CONST from '../CONST';
import {translate} from './translate';
import * as PersonalDetails from './actions/PersonalDetails';

let timezone;
let timezone = CONST.DEFAULT_TIME_ZONE;
Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
callback: (val) => {
timezone = val ? val.timezone : CONST.DEFAULT_TIME_ZONE;
timezone = lodashGet(val, 'timezone', CONST.DEFAULT_TIME_ZONE);
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class AuthScreens extends React.Component {
returnValueList: 'nameValuePairs',
nvpNames: ONYXKEYS.NVP_PREFERRED_LOCALE,
}).then((response) => {
const preferredLocale = response.nameValuePairs.preferredLocale || CONST.DEFAULT_LOCALE;
const preferredLocale = lodashGet(response, ['nameValuePairs', 'preferredLocale'], CONST.DEFAULT_LOCALE);
if ((currentPreferredLocale !== CONST.DEFAULT_LOCALE) && (preferredLocale !== currentPreferredLocale)) {
setLocale(currentPreferredLocale);
} else {
Expand Down

0 comments on commit ea45c24

Please sign in to comment.