Skip to content

Commit 6c3965b

Browse files
committed
tweak articles published since date
1 parent 103aeb8 commit 6c3965b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

dotcom-rendering/src/components/StorylinesSection.importable.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)