bugfixing group news
This commit is contained in:
parent
7014bfdb41
commit
56e3b18b7b
@ -200,37 +200,39 @@ export const groupNews = (news, watchList) => {
|
|||||||
return match ? { ...item, type: match.type } : { ...item };
|
return match ? { ...item, type: match.type } : { ...item };
|
||||||
})
|
})
|
||||||
?.reduce((acc, item) => {
|
?.reduce((acc, item) => {
|
||||||
|
// Use UTC to format the published date without shifting the day
|
||||||
const dateKey = new Intl.DateTimeFormat('en-US', {
|
const dateKey = new Intl.DateTimeFormat('en-US', {
|
||||||
day: '2-digit',
|
day: '2-digit',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
|
timeZone: 'UTC'
|
||||||
}).format(new Date(item?.publishedDate));
|
}).format(new Date(item?.publishedDate));
|
||||||
const titleKey = item.title;
|
|
||||||
|
const titleKey = item?.title;
|
||||||
if (!acc[dateKey]) acc[dateKey] = {};
|
if (!acc[dateKey]) acc[dateKey] = {};
|
||||||
if (!acc[dateKey][titleKey]) acc[dateKey][titleKey] = [];
|
if (!acc[dateKey][titleKey]) acc[dateKey][titleKey] = [];
|
||||||
acc[dateKey][titleKey]?.push(item);
|
acc[dateKey][titleKey]?.push(item);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
)
|
)
|
||||||
// Sort the grouped dates in descending order to have the latest date first
|
// Sort the grouped dates in descending order (latest date first)
|
||||||
?.sort(([dateA], [dateB]) => new Date(dateB) - new Date(dateA))
|
?.sort(([dateA], [dateB]) => new Date(dateB) - new Date(dateA))
|
||||||
?.map(([date, titleGroup]) => [
|
?.map(([date, titleGroup]) => [
|
||||||
date,
|
date,
|
||||||
Object.entries(titleGroup)
|
Object.entries(titleGroup)
|
||||||
// Sort titles by the latest time of their items
|
// Sort titles by the latest time of their items
|
||||||
.sort(([, itemsA], [, itemsB]) => {
|
?.sort(([, itemsA], [, itemsB]) => {
|
||||||
const latestTimeA = new Date(Math.max(...itemsA.map(item => new Date(item.publishedDate))));
|
const latestTimeA = new Date(Math.max(...itemsA?.map(item => new Date(item.publishedDate + 'Z'))));
|
||||||
const latestTimeB = new Date(Math.max(...itemsB.map(item => new Date(item.publishedDate))));
|
const latestTimeB = new Date(Math.max(...itemsB?.map(item => new Date(item.publishedDate + 'Z'))));
|
||||||
return latestTimeB - latestTimeA;
|
return latestTimeB - latestTimeA;
|
||||||
})
|
})
|
||||||
.map(([title, items]) => {
|
?.map(([title, items]) => {
|
||||||
// Sort items within each title group by latest time
|
// Sort items within each title group by the latest time (treating times as UTC)
|
||||||
items.sort((a, b) => new Date(b.publishedDate) - new Date(a.publishedDate));
|
items.sort((a, b) => new Date(b?.publishedDate + 'Z') - new Date(a?.publishedDate + 'Z'));
|
||||||
|
|
||||||
// Get the unique symbols
|
// Get the unique symbols
|
||||||
const symbols = [...new Set(items.map(item => item.symbol))];
|
const symbols = [...new Set(items?.map(item => item.symbol))];
|
||||||
|
|
||||||
// Return the group with symbols and items
|
|
||||||
return { title, items, symbols };
|
return { title, items, symbols };
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user