From 400ef1aad66f70d587e0fe4eaec7ea9cf8a66e13 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Thu, 16 Sep 2021 22:44:54 +0300 Subject: [PATCH 1/3] Add safety net for timezone in DateUtils --- src/libs/DateUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js index 1ffe14c5e9ec..45c2e5c4888b 100644 --- a/src/libs/DateUtils.js +++ b/src/libs/DateUtils.js @@ -1,4 +1,6 @@ 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'; @@ -10,11 +12,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); }, }); From 8b09dc2575c2af7f697d3b0c89ec6daa7b3588d7 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Fri, 17 Sep 2021 00:03:05 +0300 Subject: [PATCH 2/3] handle response errors as well when defaulting to the default locale --- src/libs/Navigation/AppNavigator/AuthScreens.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index b6bc0b1314f8..5338f4cb283d 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -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 { From 0d0490d62666012d1f17341725d6eaa70f78374b Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Fri, 17 Sep 2021 00:07:05 +0300 Subject: [PATCH 3/3] remove extra blank space --- src/libs/DateUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js index 45c2e5c4888b..a4741d4aa31c 100644 --- a/src/libs/DateUtils.js +++ b/src/libs/DateUtils.js @@ -1,7 +1,6 @@ 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';