Skip to content

Commit

Permalink
Always use a somewhat recent example date
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Jun 12, 2024
1 parent 2dcb4fd commit eb6bd50
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/block-editor/src/components/date-format-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import {
__experimentalVStack as VStack,
} from '@wordpress/components';

// So that we can illustrate the different formats in the dropdown properly,
// show a date that has a day greater than 12 and a month with more than three
// letters. Here we're using 2022-01-25 which is when WordPress 5.9 was
// released.
const EXAMPLE_DATE = new Date( 2022, 0, 25 );
// So that we illustrate the different formats in the dropdown properly, show a date that is
// somwhat recent, has a day greater than 12, and a month with more than three letters.
const exampleDate = new Date();
exampleDate.setDate( 20 );
exampleDate.setMonth( exampleDate.getMonth() - 3 );
if ( exampleDate.getMonth() === 4 ) {
// May has three letters, so use March.
exampleDate.setMonth( 3 );
}

/**
* The `DateFormatPicker` component renders controls that let the user choose a
Expand Down Expand Up @@ -54,7 +58,7 @@ export default function DateFormatPicker( {
label={ __( 'Default format' ) }
help={ `${ __( 'Example:' ) } ${ dateI18n(
defaultFormat,
EXAMPLE_DATE
exampleDate
) }` }
checked={ ! format }
onChange={ ( checked ) =>
Expand Down Expand Up @@ -98,12 +102,12 @@ function NonDefaultControls( { format, onChange } ) {
const suggestedOptions = [
...suggestedFormats.map( ( suggestedFormat, index ) => ( {
key: `suggested-${ index }`,
name: dateI18n( suggestedFormat, EXAMPLE_DATE ),
name: dateI18n( suggestedFormat, exampleDate ),
format: suggestedFormat,
} ) ),
{
key: 'human-diff',
name: humanTimeDiff( EXAMPLE_DATE ),
name: humanTimeDiff( exampleDate ),
format: 'human-diff',
},
];
Expand Down

0 comments on commit eb6bd50

Please sign in to comment.