Skip to content

Commit

Permalink
Latest posts: i18n date (#7996)
Browse files Browse the repository at this point in the history
* i18n date

* use wp.date

* user format

* add wp-date dependency
  • Loading branch information
Soean authored and mcsf committed Oct 15, 2018
1 parent e825554 commit 0ea7c43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-compose',
'wp-core-data',
'wp-data',
'wp-date',
'wp-editor',
'wp-element',
'wp-html-entities',
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { isUndefined, pickBy } from 'lodash';
import moment from 'moment';
import classnames from 'classnames';

/**
Expand All @@ -19,6 +18,7 @@ import {
Toolbar,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { dateI18n, format, getSettings } from '@wordpress/date';
import { decodeEntities } from '@wordpress/html-entities';
import {
InspectorControls,
Expand Down Expand Up @@ -116,6 +116,8 @@ class LatestPostsEdit extends Component {
},
];

const dateFormat = getSettings().formats.date;

return (
<Fragment>
{ inspectorControls }
Expand All @@ -139,8 +141,8 @@ class LatestPostsEdit extends Component {
<li key={ i }>
<a href={ post.link } target="_blank">{ decodeEntities( post.title.rendered.trim() ) || __( '(Untitled)' ) }</a>
{ displayPostDate && post.date_gmt &&
<time dateTime={ moment( post.date_gmt ).utc().format() } className={ `${ this.props.className }__post-date` }>
{ moment( post.date_gmt ).local().format( 'MMMM DD, Y' ) }
<time dateTime={ format( 'c', post.date_gmt ) } className={ `${ this.props.className }__post-date` }>
{ dateI18n( dateFormat, post.date_gmt ) }
</time>
}
</li>
Expand Down

0 comments on commit 0ea7c43

Please sign in to comment.