Skip to content

Commit

Permalink
Adds "Time Ago" option to SelectControl of DateFormatPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
amitraj2203 committed Jun 4, 2024
1 parent e57eed5 commit 661be5d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { _x, __ } from '@wordpress/i18n';
import { dateI18n } from '@wordpress/date';
import { dateI18n, humanTimeDiff } from '@wordpress/date';
import { useState, createInterpolateElement } from '@wordpress/element';
import {
TextControl,
Expand Down Expand Up @@ -92,13 +92,17 @@ function NonDefaultControls( { format, onChange } ) {
_x( 'F j, Y', 'long date format' ),
/* translators: See https://www.php.net/manual/datetime.format.php */
_x( 'M j', 'short date format without the year' ),
__( 'Time Ago' ),
] ),
];

const suggestedOptions = suggestedFormats.map(
( suggestedFormat, index ) => ( {
key: `suggested-${ index }`,
name: dateI18n( suggestedFormat, EXAMPLE_DATE ),
name:
suggestedFormat === 'Time Ago'
? humanTimeDiff( EXAMPLE_DATE, new Date() )
: dateI18n( suggestedFormat, EXAMPLE_DATE ),
format: suggestedFormat,
} )
);
Expand Down

0 comments on commit 661be5d

Please sign in to comment.