Skip to content

Commit

Permalink
Merge pull request #48523 from daledah/fix/47452
Browse files Browse the repository at this point in the history
fix: don't set user's timezone if it's empty
  • Loading branch information
chiragsalian authored Sep 16, 2024
2 parents 9002770 + 8e5e9da commit 5e7c594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
import CENTRAL_PANE_SCREENS from './CENTRAL_PANE_SCREENS';
import createCustomStackNavigator from './createCustomStackNavigator';
Expand Down Expand Up @@ -150,7 +151,7 @@ Onyx.connect({

// If the current timezone is different than the user's timezone, and their timezone is set to automatic
// then update their timezone.
if (timezone?.automatic && timezone?.selected !== currentTimezone) {
if (!isEmptyObject(currentTimezone) && timezone?.automatic && timezone?.selected !== currentTimezone) {
timezone.selected = currentTimezone;
PersonalDetails.updateAutomaticTimezone({
automatic: true,
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings/Profile/TimezoneInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as PersonalDetails from '@userActions/PersonalDetails';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type TimezoneInitialPageProps = WithCurrentUserPersonalDetailsProps;

Expand All @@ -23,14 +24,16 @@ function TimezoneInitialPage({currentUserPersonalDetails}: TimezoneInitialPagePr

const {translate} = useLocalize();

const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone as SelectedTimezone;

/**
* Updates setting for automatic timezone selection.
* Note: If we are updating automatically, we'll immediately calculate the user's timezone.
*/
const updateAutomaticTimezone = (isAutomatic: boolean) => {
PersonalDetails.updateAutomaticTimezone({
automatic: isAutomatic,
selected: isAutomatic ? (Intl.DateTimeFormat().resolvedOptions().timeZone as SelectedTimezone) : timezone.selected,
selected: isAutomatic && !isEmptyObject(currentTimezone) ? currentTimezone : timezone.selected,
});
};

Expand Down

0 comments on commit 5e7c594

Please sign in to comment.