Skip to content

Commit

Permalink
Use date and time formats from @wordpress/date as a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Mar 11, 2022
1 parent ba74a6b commit b3fcfda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 9 additions & 2 deletions packages/block-library/src/comment-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { dateI18n } from '@wordpress/date';
import {
dateI18n,
__experimentalGetSettings as getDateSettings,
} from '@wordpress/date';
import {
InspectorControls,
useBlockProps,
Expand Down Expand Up @@ -31,7 +34,11 @@ export default function Edit( {
} ) {
const blockProps = useBlockProps();
const [ date ] = useEntityProp( 'root', 'comment', 'date', commentId );
const [ siteFormat ] = useEntityProp( 'root', 'site', 'date_format' );
const [ siteFormat = getDateSettings().formats.date ] = useEntityProp(
'root',
'site',
'date_format'
);

const inspectorControls = (
<InspectorControls>
Expand Down
18 changes: 15 additions & 3 deletions packages/block-library/src/post-date/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import classnames from 'classnames';
*/
import { useEntityProp } from '@wordpress/core-data';
import { useRef } from '@wordpress/element';
import { dateI18n } from '@wordpress/date';
import {
dateI18n,
__experimentalGetSettings as getDateSettings,
} from '@wordpress/date';
import {
AlignmentControl,
BlockControls,
Expand Down Expand Up @@ -40,8 +43,17 @@ export default function PostDateEdit( {
} );
const timeRef = useRef();
const isDescendentOfQueryLoop = Number.isFinite( queryId );
const [ siteFormat ] = useEntityProp( 'root', 'site', 'date_format' );
const [ siteTimeFormat ] = useEntityProp( 'root', 'site', 'time_format' );
const dateSettings = getDateSettings();
const [ siteFormat = dateSettings.formats.date ] = useEntityProp(
'root',
'site',
'date_format'
);
const [ siteTimeFormat = dateSettings.formats.time ] = useEntityProp(
'root',
'site',
'time_format'
);
const [ date, setDate ] = useEntityProp(
'postType',
postType,
Expand Down

0 comments on commit b3fcfda

Please sign in to comment.