Skip to content

Commit 78bfa51

Browse files
authored
Merge pull request #15687 from ethereum/fix-date-sort
fix: sorting using pre-translated dates
2 parents 968ba1e + 8901f25 commit 78bfa51

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/lib/utils/rss.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type { Lang, RSSItem } from "../types"
44
import { isValidDate } from "./date"
55
import { getLocaleTimestamp } from "./time"
66

7-
export const sortByPubDate = (items: RSSItem[]) =>
7+
// Sort by original pubDate string (not yet localized)
8+
export const sortByPubDateRaw = (items: (RSSItem & { pubDateRaw: string })[]) =>
89
items.sort((a, b) => {
9-
const dateA = new Date(a.pubDate)
10-
const dateB = new Date(b.pubDate)
10+
const dateA = new Date(a.pubDateRaw)
11+
const dateB = new Date(b.pubDateRaw)
1112
if (isNaN(dateA.getTime()) || isNaN(dateB.getTime())) {
12-
console.error("Invalid date found:", a.pubDate, b.pubDate)
13+
console.error("Invalid date found:", a.pubDateRaw, b.pubDateRaw)
1314
return 0
1415
}
1516
return dateB.getTime() - dateA.getTime()
@@ -20,7 +21,7 @@ export const postProcess = (rssItems: RSSItem[], locale: Lang) =>
2021
const pubDate = isValidDate(item.pubDate)
2122
? getLocaleTimestamp(locale, item.pubDate)
2223
: ""
23-
const formattedItem = { ...item, pubDate }
24+
const formattedItem = { ...item, pubDate, pubDateRaw: item.pubDate }
2425

2526
switch (item.sourceFeedUrl) {
2627
case VITALIK_FEED:
@@ -47,5 +48,5 @@ export const polishRSSList = (items: RSSItem[][], locale: Lang) => {
4748

4849
const latestItems = latestOfEach.flat()
4950
const readyForSorting = postProcess(latestItems, locale)
50-
return sortByPubDate(readyForSorting)
51+
return sortByPubDateRaw(readyForSorting)
5152
}

0 commit comments

Comments
 (0)