Skip to content

Commit

Permalink
Merge pull request #26248 from waterim/fix-19810-moment-timezones-mig…
Browse files Browse the repository at this point in the history
…ration

Datetime polyfill, removed moment.tz.guess()
  • Loading branch information
mountiny authored Sep 13, 2023
2 parents 4d104f5 + 1c0b43b commit 56ceee5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 7 deletions.
57 changes: 57 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
},
"dependencies": {
"@expensify/react-native-web": "0.18.15",
"@formatjs/intl-datetimeformat": "^6.10.0",
"@formatjs/intl-getcanonicallocales": "^2.2.0",
"@formatjs/intl-listformat": "^7.2.2",
"@formatjs/intl-locale": "^3.3.0",
Expand Down
1 change: 1 addition & 0 deletions src/libs/IntlPolyfill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import polyfillNumberFormat from './polyfillNumberFormat';
export default function intlPolyfill() {
// Just need to polyfill Intl.NumberFormat for web based platforms
polyfillNumberFormat();
require('@formatjs/intl-datetimeformat');
}
1 change: 1 addition & 0 deletions src/libs/IntlPolyfill/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function polyfill() {
require('@formatjs/intl-getcanonicallocales/polyfill');
require('@formatjs/intl-locale/polyfill');
require('@formatjs/intl-pluralrules/polyfill');
require('@formatjs/intl-datetimeformat');
polyfillNumberFormat();
polyfillListFormat();
}
3 changes: 1 addition & 2 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import Onyx, {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import moment from 'moment';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
Expand Down Expand Up @@ -65,7 +64,7 @@ Onyx.connect({
}

timezone = lodashGet(val, [currentAccountID, 'timezone'], {});
const currentTimezone = moment.tz.guess(true);
const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;

// If the current timezone is different than the user's timezone, and their timezone is set to automatic
// then update their timezone.
Expand Down
4 changes: 1 addition & 3 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import moment from 'moment-timezone';
import 'moment/locale/es';
import {AppState} from 'react-native';
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -386,7 +384,7 @@ function openProfile(personalDetails) {
if (lodashGet(oldTimezoneData, 'automatic', true)) {
newTimezoneData = {
automatic: true,
selected: moment.tz.guess(true),
selected: Intl.DateTimeFormat().resolvedOptions().timeZone,
};
}

Expand Down
3 changes: 1 addition & 2 deletions src/pages/settings/Profile/TimezoneInitialPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import lodashGet from 'lodash/get';
import React from 'react';
import {View} from 'react-native';
import moment from 'moment-timezone';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../../components/withCurrentUserPersonalDetails';
import ScreenWrapper from '../../../components/ScreenWrapper';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
Expand Down Expand Up @@ -37,7 +36,7 @@ function TimezoneInitialPage(props) {
const updateAutomaticTimezone = (isAutomatic) => {
PersonalDetails.updateAutomaticTimezone({
automatic: isAutomatic,
selected: isAutomatic ? moment.tz.guess() : timezone.selected,
selected: isAutomatic ? Intl.DateTimeFormat().resolvedOptions().timeZone : timezone.selected,
});
};

Expand Down

0 comments on commit 56ceee5

Please sign in to comment.