From a6e09368bbc2ccc2da2ff1af7a7e4df635190bc3 Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 26 Mar 2021 12:43:22 -0700 Subject: [PATCH 1/2] remove timezone migration --- src/libs/DateUtils.js | 11 ++++++- src/libs/migrateOnyx.js | 2 -- src/libs/migrations/ReformatTimezone.js | 41 ------------------------- 3 files changed, 10 insertions(+), 44 deletions(-) delete mode 100644 src/libs/migrations/ReformatTimezone.js diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js index ce32d4939663..d59a942517b4 100644 --- a/src/libs/DateUtils.js +++ b/src/libs/DateUtils.js @@ -8,7 +8,16 @@ import CONST from '../CONST'; let timezone; Onyx.connect({ key: ONYXKEYS.MY_PERSONAL_DETAILS, - callback: (val) => { timezone = val ? val.timezone.selected : CONST.DEFAULT_TIME_ZONE.selected; }, + callback: (val) => { + timezone = val ? val.timezone : CONST.DEFAULT_TIME_ZONE.selected; + + // Make sure that if we have a timezone in object format that we're getting the selected timezone name + // Older timezone formats only include the timezone name, but the newer format also included whether or + // not the timezone was selected automatically + if (_.isObject(timezone)) { + timezone = val.timezone.selected; + } + }, }); /** diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 5ee060ea0bc2..8b0d428076c2 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -1,6 +1,5 @@ import RenameActiveClientsKey from './migrations/RenameActiveClientsKey'; import RenamePriorityModeKey from './migrations/RenamePriorityModeKey'; -import ReformatTimezone from './migrations/ReformatTimezone'; export default function () { const startTime = Date.now(); @@ -11,7 +10,6 @@ export default function () { const migrationPromises = [ RenameActiveClientsKey, RenamePriorityModeKey, - ReformatTimezone, ]; // Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the diff --git a/src/libs/migrations/ReformatTimezone.js b/src/libs/migrations/ReformatTimezone.js deleted file mode 100644 index 24221f3f0780..000000000000 --- a/src/libs/migrations/ReformatTimezone.js +++ /dev/null @@ -1,41 +0,0 @@ -import Onyx from 'react-native-onyx'; -import _ from 'underscore'; -import ONYXKEYS from '../../ONYXKEYS'; - -// This migration changes the format of the timezone in the Onyx key MY_PERSONAL_DETAILS from a string to an object -export default function () { - return new Promise((resolve) => { - // Connect to the old key in Onyx to get the old value of myPersonalDetails timezone - // then update the timezone to be the default timezone and set the myPersonalDetails - // key with the updated values - const connectionID = Onyx.connect({ - key: ONYXKEYS.MY_PERSONAL_DETAILS, - callback: (myPersonalDetails) => { - Onyx.disconnect(connectionID); - - if (_.isUndefined(myPersonalDetails) || _.isEmpty(myPersonalDetails)) { - console.debug('[Migrate Onyx] Skipped migration ReformatTimezone: No myPersonalDetails key found'); - return resolve(); - } - - // Fail early here because there is nothing to migrate, the timezone is already in the expected format - if (_.isObject(myPersonalDetails.timezone)) { - console.debug('[Migrate Onyx] Skipped migration ReformatTimezone'); - return resolve(); - } - - // Update the timezone with the user's old timezone selection and set "automatic" to false - // because we don't know if their old timezone was set automatically or not - const details = myPersonalDetails; - details.timezone = {selected: details.timezone, automatic: false}; - Onyx.set({ - [ONYXKEYS.MY_PERSONAL_DETAILS]: details, - }) - .then(() => { - console.debug('[Migrate Onyx] Ran migration ReformatTimezone'); - resolve(); - }); - }, - }); - }); -} From ab521e6083c8d8667e4da6a51dd7614963405aca Mon Sep 17 00:00:00 2001 From: Nikki Wines Date: Fri, 26 Mar 2021 12:51:20 -0700 Subject: [PATCH 2/2] add underscore import --- src/libs/DateUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js index d59a942517b4..45ae4b14da15 100644 --- a/src/libs/DateUtils.js +++ b/src/libs/DateUtils.js @@ -1,5 +1,6 @@ import moment from 'moment'; import 'moment-timezone'; +import _ from 'underscore'; import Onyx from 'react-native-onyx'; import Str from 'expensify-common/lib/str'; import ONYXKEYS from '../ONYXKEYS';