Skip to content

Commit

Permalink
Date: Mark getSettings as experimental (WordPress#10636)
Browse files Browse the repository at this point in the history
* Date: Mark getSettings as experimental

* Update all references to __experimentalGetSettings

* Bump deprecated version

* Add change to changelog

* Remove deprecated from 4.2

Co-Authored-By: ajitbohra <ajit@lubus.in>

* Marks as unreleased

Co-Authored-By: ajitbohra <ajit@lubus.in>
  • Loading branch information
ajitbohra authored and antpb committed Oct 26, 2018
1 parent caafa12 commit 667d165
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
3 changes: 3 additions & 0 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Gutenberg's deprecation policy is intended to support backwards-compatibility for releases, when possible. The current deprecations are listed below and are grouped by _the version at which they will be removed completely_. If your plugin depends on these behaviors, you must update to the recommended alternative before the noted version.

# 4.4.0
- `wp.date.getSettings` has been removed. Please use `wp.date.__experimentalGetSettings` instead.

# 4.3.0

- `isEditorSidebarPanelOpened` selector (`core/edit-post`) has been removed. Please use `isEditorPanelEnabled` instead.
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 @@ -18,7 +18,7 @@ import {
Toolbar,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { dateI18n, format, getSettings } from '@wordpress/date';
import { dateI18n, format, __experimentalGetSettings } from '@wordpress/date';
import { decodeEntities } from '@wordpress/html-entities';
import {
InspectorControls,
Expand Down Expand Up @@ -116,7 +116,7 @@ class LatestPostsEdit extends Component {
},
];

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

return (
<Fragment>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/date-time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Render a DateTimePicker.

```jsx
import { DateTimePicker } from '@wordpress/components';
import { getSettings } from '@wordpress/date';
import { __experimentalGetSettings } from '@wordpress/date';
import { withState } from '@wordpress/compose';

const MyDateTimePicker = withState( {
date: new Date(),
} )( ( { date, setState } ) => {
const settings = getSettings();
const settings = __experimentalGetSettings();

// To know if the current timezone is a 12 hour time with look for an "a" in the time format.
// We also make sure this a is not escaped by a "/".
Expand Down
6 changes: 6 additions & 0 deletions packages/date/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.2.0 (unreleased)

### Breaking Change

- Marked getSettings as experimental

## 2.1.0 (2018-09-26)

### New Features
Expand Down
16 changes: 16 additions & 0 deletions 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';
import 'moment-timezone/moment-timezone-utils';

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

// Changes made here will likely need to be made in `lib/client-assets.php` as
// well because it uses the `setSettings()` function to change these settings.
let settings = {
Expand Down Expand Up @@ -85,7 +90,18 @@ export function setSettings( dateSettings ) {
*
* @return {Object} Settings, including locale data.
*/
export function __experimentalGetSettings() {
return settings;
}

// deprecations
export function getSettings() {
deprecated( 'wp.date.getSettings', {
version: '4.4',
alternative: 'wp.date.__experimentalGetSettings',
plugin: 'Gutenberg',
hint: 'Unstable APIs are strongly discouraged to be used, and are subject to removal without notice.',
} );
return settings;
}

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,13 +1,13 @@
/**
* WordPress dependencies
*/
import { getSettings } from '@wordpress/date';
import { __experimentalGetSettings } from '@wordpress/date';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { DateTimePicker } from '@wordpress/components';

export function PostSchedule( { date, onUpdateDate } ) {
const settings = getSettings();
const settings = __experimentalGetSettings();
// 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 "/"
const is12HourTime = /a(?!\\)/i.test(
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/post-schedule/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { dateI18n, getSettings } from '@wordpress/date';
import { dateI18n, __experimentalGetSettings } from '@wordpress/date';
import { withSelect } from '@wordpress/data';

export function PostScheduleLabel( { date, isFloating } ) {
const settings = getSettings();
const settings = __experimentalGetSettings();

return date && ! isFloating ?
dateI18n( settings.formats.datetimeAbbreviated, date ) :
Expand Down

0 comments on commit 667d165

Please sign in to comment.