Skip to content

Commit a1542e1

Browse files
committed
tweak(panel/playerDrops): improved timeline day start rounding
1 parent a50ea2f commit a1542e1

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

panel/src/pages/PlayerDropsPage/chartingUtils.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { DisplayLodType } from "./PlayerDropsPage";
55

66
export type PlayerDropsCategoryCount = [category: string, count: number];
77

8+
// Helper function to floor a date to the start of the day
9+
const floorToStartOfDay = (dateString: string) => {
10+
const date = new Date(dateString);
11+
date.setHours(0, 0, 0, 0);
12+
return date.toISOString();
13+
};
14+
15+
816
/**
917
* Processes the player drops summary api data to return the data for the timeline chart.
1018
*
@@ -31,17 +39,22 @@ export const processDropsSummary = (apiData: PlayerDropsSummaryHour[], displayLo
3139
let currDayData: PlayerDropsSummaryHour | undefined;
3240
for (const hourData of windowData) {
3341
const hourDayOfMonth = (new Date(hourData.hour)).getDate();
42+
const hourDayStart = floorToStartOfDay(hourData.hour);
3443
if (!currDayData) {
3544
currDayOfMonth = hourDayOfMonth;
3645
currDayData = {
37-
hour: hourData.hour,
46+
hour: hourDayStart,
3847
changes: 0,
3948
dropTypes: [],
4049
};
4150
} else if (hourDayOfMonth !== currDayOfMonth) {
4251
binnedData.push(currDayData);
4352
currDayOfMonth = hourDayOfMonth;
44-
currDayData = structuredClone(hourData);
53+
currDayData = {
54+
hour: hourDayStart,
55+
changes: hourData.changes,
56+
dropTypes: structuredClone(hourData.dropTypes),
57+
};
4558
continue;
4659
}
4760

0 commit comments

Comments
 (0)