File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
dotcom-rendering/src/components Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -109,11 +109,28 @@ function formatDateRangeText(
109109) : string {
110110 const earliest = earliestArticleTime ? new Date ( earliestArticleTime ) : null ;
111111 const latest = latestArticleTime ? new Date ( latestArticleTime ) : null ;
112- const format = ( d ?: Date | null ) => d ?. toLocaleDateString ( 'en-GB' ) ?? '' ;
112+ const format = ( d ?: Date | null ) => {
113+ if ( ! d ) return '' ;
114+ const day = d . getDate ( ) ;
115+ const suffix = ( day : number ) => {
116+ if ( day > 3 && day < 21 ) return 'th' ;
117+ switch ( day % 10 ) {
118+ case 1 :
119+ return 'st' ;
120+ case 2 :
121+ return 'nd' ;
122+ case 3 :
123+ return 'rd' ;
124+ default :
125+ return 'th' ;
126+ }
127+ } ;
128+ return `${ day } ${ suffix ( day ) } ${ d . toLocaleDateString ( 'en-GB' , {
129+ month : 'long' ,
130+ year : 'numeric' ,
131+ } ) } `;
132+ } ;
113133
114- // if (earliest && latest) {
115- // return `between ${format(earliest)} and ${format(latest)}`;
116- // } else
117134 if ( earliest ) {
118135 return `since ${ format ( earliest ) } ` ;
119136 } else if ( latest ) {
You can’t perform that action at this time.
0 commit comments