bugfixing group earnings

This commit is contained in:
MuslemRahimi 2025-02-26 17:02:40 +01:00
parent ec27fd44d9
commit 7014bfdb41
2 changed files with 14 additions and 17 deletions

View File

@ -159,35 +159,32 @@ export const groupScreenerRules = (allRows) => {
export const groupEarnings = (earnings) => {
return Object?.entries(
earnings?.reduce((acc, item) => {
const date = new Date(item?.date);
const berlinDate = new Intl.DateTimeFormat('en-US', {
// Force formatting in UTC to avoid local timezone conversion
const dateKey = new Intl.DateTimeFormat('en-US', {
day: '2-digit',
month: 'short',
year: 'numeric',
timeZone: 'Europe/Berlin'
}).format(date);
timeZone: 'UTC'
})?.format(new Date(item.date));
if (!acc[berlinDate]) acc[berlinDate] = [];
acc[berlinDate]?.push(item);
if (!acc[dateKey]) acc[dateKey] = [];
acc[dateKey].push(item);
return acc;
}, {})
)
// Sort the grouped dates in descending order (most recent first)
?.sort(([dateA], [dateB]) => new Date(dateB) - new Date(dateA))
// Sort the grouped dates in descending order
?.sort(([dateA], [dateB]) => new Date(dateA) - new Date(dateB))
?.map(([date, earnings]) => [
date,
// Sort earnings within the date by time in descending order
// Sort earnings within the date by time (also treat times as UTC)
earnings?.sort((a, b) => {
const berlinTimeA = new Date(
new Date(`${a?.date}T${a?.time}`).toLocaleString('en-US', { timeZone: 'Europe/Berlin' })
);
const berlinTimeB = new Date(
new Date(`${b?.date}T${b?.time}`).toLocaleString('en-US', { timeZone: 'Europe/Berlin' })
);
return berlinTimeB - berlinTimeA;
const timeA = new Date(`1970-01-01T${a?.time}Z`);
const timeB = new Date(`1970-01-01T${b?.time}Z`);
return timeB - timeA;
})
]);
};

View File

@ -277,8 +277,8 @@
if (watchList?.length > 0) {
columns = generateColumns(watchList);
sortOrders = generateSortOrders(watchList);
groupedEarnings = groupEarnings(earnings);
groupedNews = groupNews(news, watchList);
} else {
groupedEarnings = [];