Skip to content

Commit

Permalink
@wordpress/date: Rename __experimentalGetSettings() to getSettings() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Sep 7, 2022
1 parent a654883 commit 999cd14
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 47 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { DateTimePicker } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { forwardRef } from '@wordpress/element';
import { __experimentalGetSettings as getSettings } from '@wordpress/date';
import { getSettings } from '@wordpress/date';

/**
* Internal dependencies
Expand Down
5 changes: 1 addition & 4 deletions packages/block-library/src/comment-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import {
dateI18n,
__experimentalGetSettings as getDateSettings,
} from '@wordpress/date';
import { dateI18n, getSettings as getDateSettings } from '@wordpress/date';
import {
InspectorControls,
useBlockProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ToolbarGroup,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { dateI18n, format, __experimentalGetSettings } from '@wordpress/date';
import { dateI18n, format, getSettings } from '@wordpress/date';
import {
InspectorControls,
BlockAlignmentToolbar,
Expand Down Expand Up @@ -422,7 +422,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
},
];

const dateFormat = __experimentalGetSettings().formats.date;
const dateFormat = getSettings().formats.date;

return (
<div>
Expand Down
5 changes: 1 addition & 4 deletions packages/block-library/src/post-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import classnames from 'classnames';
*/
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { useRef } from '@wordpress/element';
import {
dateI18n,
__experimentalGetSettings as getDateSettings,
} from '@wordpress/date';
import { dateI18n, getSettings as getDateSettings } from '@wordpress/date';
import {
AlignmentControl,
BlockControls,
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/date-time/date/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
*/
import { __, _n, sprintf, isRTL } from '@wordpress/i18n';
import { arrowLeft, arrowRight } from '@wordpress/icons';
import { dateI18n, __experimentalGetSettings } from '@wordpress/date';
import { dateI18n, getSettings } from '@wordpress/date';
import { useState, useRef, useEffect } from '@wordpress/element';

/**
Expand Down Expand Up @@ -322,7 +322,7 @@ function Day( {
}

function getDayLabel( date: Date, isSelected: boolean, numEvents: number ) {
const { formats } = __experimentalGetSettings();
const { formats } = getSettings();
const localizedDate = dateI18n(
formats.date,
date,
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/date-time/time/timezone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __experimentalGetSettings as getDateSettings } from '@wordpress/date';
import { getSettings as getDateSettings } from '@wordpress/date';

/**
* Internal dependencies
Expand Down
4 changes: 4 additions & 0 deletions packages/date/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## Deprecations

- `__experimentalGetSettings` has been renamed to `getSettings`.

## 4.16.0 (2022-08-24)

## 4.15.0 (2022-08-10)
Expand Down
8 changes: 8 additions & 0 deletions packages/date/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ _Returns_

- `Date`: Date

### getSettings

Returns the currently defined date settings.

_Returns_

- `DateSettings`: Settings, including locale data.

### gmdate

Formats a date (like `date()` in PHP), in the UTC timezone.
Expand Down
1 change: 1 addition & 0 deletions packages/date/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"types": "build-types",
"dependencies": {
"@babel/runtime": "^7.16.0",
"@wordpress/deprecated": "file:../deprecated",
"moment": "^2.22.1",
"moment-timezone": "^0.5.31"
},
Expand Down
21 changes: 20 additions & 1 deletion packages/date/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import momentLib from 'moment';
import 'moment-timezone/moment-timezone';
import 'moment-timezone/moment-timezone-utils';

/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';

/** @typedef {import('moment').Moment} Moment */
/** @typedef {import('moment').LocaleSpecification} MomentLocaleSpecification */

Expand Down Expand Up @@ -202,10 +207,24 @@ export function setSettings( dateSettings ) {
*
* @return {DateSettings} Settings, including locale data.
*/
export function __experimentalGetSettings() {
export function getSettings() {
return settings;
}

/**
* Returns the currently defined date settings.
*
* @deprecated
* @return {DateSettings} Settings, including locale data.
*/
export function __experimentalGetSettings() {
deprecated( 'wp.date.__experimentalGetSettings', {
since: '6.1',
alternative: 'wp.date.getSettings',
} );
return getSettings();
}

function setupWPTimezone() {
// Create WP timezone based off dateSettings.
momentLib.tz.add(
Expand Down
40 changes: 20 additions & 20 deletions packages/date/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Internal dependencies
*/
import {
__experimentalGetSettings,
getSettings,
date as dateNoI18n,
dateI18n,
getDate,
Expand All @@ -28,7 +28,7 @@ describe( 'isInTheFuture', () => {
} );

it( 'should ignore the timezone', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Set a timezone in the future.
setSettings( {
Expand Down Expand Up @@ -75,7 +75,7 @@ describe( 'Function date', () => {
] )(
'should format date as "%s", ignoring locale settings',
( formatString, expected ) => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
Expand Down Expand Up @@ -110,7 +110,7 @@ describe( 'Function date', () => {
);

it( 'should format date into a date that uses site’s timezone, if no timezone was provided and there’s a site timezone set', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -136,7 +136,7 @@ describe( 'Function date', () => {
} );

it( 'should format date into a date that uses site’s UTC offset setting, if no timezone was provided and there isn’t a timezone set in the site', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -162,7 +162,7 @@ describe( 'Function date', () => {
} );

it( 'should format date into a date that uses the given timezone, if said timezone is valid', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -183,7 +183,7 @@ describe( 'Function date', () => {
} );

it( 'should format date into a date that uses the given UTC offset, if given timezone is actually a UTC offset', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand Down Expand Up @@ -246,7 +246,7 @@ describe( 'Function gmdate', () => {
] )(
'should format date as "%s", ignoring locale settings',
( formatString, expected ) => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
Expand Down Expand Up @@ -281,7 +281,7 @@ describe( 'Function gmdate', () => {
);

it( 'should format date into a UTC date', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand Down Expand Up @@ -325,7 +325,7 @@ describe( 'Function dateI18n', () => {
] )(
'should format date as "%s", using locale settings',
( formatString, expected ) => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
Expand Down Expand Up @@ -361,7 +361,7 @@ describe( 'Function dateI18n', () => {
);

it( 'should format date into a date that uses site’s timezone, if no timezone was provided and there’s a site timezone set', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -387,7 +387,7 @@ describe( 'Function dateI18n', () => {
} );

it( 'should format date into a date that uses site’s UTC offset setting, if no timezone was provided and there isn’t a timezone set in the site', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -413,7 +413,7 @@ describe( 'Function dateI18n', () => {
} );

it( 'should format date into a date that uses the given timezone, if said timezone is valid', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -434,7 +434,7 @@ describe( 'Function dateI18n', () => {
} );

it( 'should format date into a date that uses the given UTC offset, if given timezone is actually a UTC offset', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand Down Expand Up @@ -466,7 +466,7 @@ describe( 'Function dateI18n', () => {
} );

it( 'should format date into a UTC date if `gmt` is set to `true`', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -487,7 +487,7 @@ describe( 'Function dateI18n', () => {
} );

it( 'should format date into a date that uses site’s timezone if `gmt` is set to `false`', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand Down Expand Up @@ -535,7 +535,7 @@ describe( 'Function gmdateI18n', () => {
] )(
'should format date as "%s", using locale settings',
( formatString, expected ) => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different locale.
const l10n = settings.l10n;
Expand Down Expand Up @@ -570,7 +570,7 @@ describe( 'Function gmdateI18n', () => {
);

it( 'should format date into a UTC date', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Simulate different timezone.
setSettings( {
Expand All @@ -592,7 +592,7 @@ describe( 'Function gmdateI18n', () => {

describe( 'Moment.js Localization', () => {
it( 'should change the relative time strings', () => {
const settings = __experimentalGetSettings();
const settings = getSettings();

// Change the locale strings for tests.
setSettings( {
Expand All @@ -608,7 +608,7 @@ describe( 'Moment.js Localization', () => {
} );

// Get the freshly changed setings.
const newSettings = __experimentalGetSettings();
const newSettings = getSettings();

// Test the unchanged values.
expect( newSettings.l10n.locale ).toBe( settings.l10n.locale );
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/post-schedule/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { __experimentalGetSettings } from '@wordpress/date';
import { getSettings } from '@wordpress/date';
import { useDispatch, useSelect } from '@wordpress/data';
import { __experimentalPublishDateTimePicker as PublishDateTimePicker } from '@wordpress/block-editor';
import { useState, useMemo } from '@wordpress/element';
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function PostSchedule( { onClose } ) {
[ eventsByPostType ]
);

const settings = __experimentalGetSettings();
const settings = getSettings();

// To know if the current timezone is a 12 hour time with look for "a" in the time format
// We also make sure this a is not escaped by a "/"
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/components/post-schedule/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __, _x, sprintf, isRTL } from '@wordpress/i18n';
import { __experimentalGetSettings, getDate, dateI18n } from '@wordpress/date';
import { getSettings, getDate, dateI18n } from '@wordpress/date';
import { useSelect } from '@wordpress/data';

/**
Expand Down Expand Up @@ -95,7 +95,7 @@ export function getPostScheduleLabel(
}

function getTimezoneAbbreviation() {
const { timezone } = __experimentalGetSettings();
const { timezone } = getSettings();

if ( timezone.abbr && isNaN( Number( timezone.abbr ) ) ) {
return timezone.abbr;
Expand All @@ -106,7 +106,7 @@ function getTimezoneAbbreviation() {
}

function isTimezoneSameAsSiteTimezone( date ) {
const { timezone } = __experimentalGetSettings();
const { timezone } = getSettings();

const siteOffset = Number( timezone.offset );
const dateOffset = -1 * ( date.getTimezoneOffset() / 60 );
Expand Down

0 comments on commit 999cd14

Please sign in to comment.