diff --git a/src/libs/DateUtils.js b/src/libs/DateUtils.js index ce32d4939663..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'; @@ -8,7 +9,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(); - }); - }, - }); - }); -}