Skip to content

Commit 1ab7ad5

Browse files
committed
Set utc hours to zero incase of DST
- Order organizations on descending order before passing to piechart
1 parent de8aaa9 commit 1ab7ad5

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

community-dashboard/app/Base/utils/temporal.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,31 @@ export function getTimestamps(
3131
const sanitizedStartDate = resolveTime(startDate, resolution);
3232
const sanitizedEndDate = resolveTime(endDate, resolution);
3333

34-
const returns: number[] = [
34+
const timestamps: number[] = [
3535
sanitizedStartDate.getTime(),
3636
];
3737

38-
while (sanitizedStartDate < sanitizedEndDate) {
38+
let increment = 1;
39+
while (true) {
40+
const myDate = new Date(sanitizedStartDate);
3941
if (resolution === 'year') {
40-
sanitizedStartDate.setFullYear(sanitizedStartDate.getFullYear() + 1);
42+
myDate.setFullYear(sanitizedStartDate.getFullYear() + increment);
4143
} else if (resolution === 'month') {
42-
sanitizedStartDate.setMonth(sanitizedStartDate.getMonth() + 1);
44+
myDate.setMonth(sanitizedStartDate.getMonth() + increment);
4345
} else {
44-
sanitizedStartDate.setDate(sanitizedStartDate.getDate() + 1);
46+
myDate.setDate(sanitizedStartDate.getDate() + increment);
4547
}
46-
returns.push(sanitizedStartDate.getTime());
48+
myDate.setUTCHours(0, 0, 0, 0);
49+
50+
if (myDate > sanitizedEndDate) {
51+
break;
52+
}
53+
54+
timestamps.push(myDate.getTime());
55+
increment += 1;
4756
}
4857

49-
return returns;
58+
return timestamps;
5059
}
5160

5261
export function formatDate(value: number | string) {

community-dashboard/app/views/StatsBoard/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,13 @@ function StatsBoard(props: Props) {
297297
(item) => item.total,
298298
);
299299

300-
return getTimestamps(
300+
const timestamps = getTimestamps(
301301
contributionTimeSeries[0].date,
302302
contributionTimeSeries[contributionTimeSeries.length - 1].date,
303303
resolution,
304-
).map((item) => ({
304+
);
305+
306+
return timestamps.map((item) => ({
305307
total: mapping[item] ?? 0,
306308
date: item,
307309
}));
@@ -366,7 +368,7 @@ function StatsBoard(props: Props) {
366368
...item,
367369
projectType: item.projectType ?? '-1',
368370
}))
369-
.sort((a, b) => compareNumber(a.totalSwipes, b.totalSwipes)) ?? []
371+
.sort((a, b) => compareNumber(a.totalSwipes, b.totalSwipes, -1)) ?? []
370372
),
371373
[swipeByProjectType],
372374
);
@@ -384,7 +386,7 @@ function StatsBoard(props: Props) {
384386
organizationName: item.organizationName ?? 'Unknown',
385387
}))
386388
.filter((project) => isDefined(project.organizationName))
387-
.sort((a, b) => compareNumber(a.totalSwipes, b.totalSwipes)) ?? [];
389+
.sort((a, b) => compareNumber(a.totalSwipes, b.totalSwipes, -1)) ?? [];
388390

389391
if (sortedTotalSwipeByOrganization.length <= 5) {
390392
return sortedTotalSwipeByOrganization;

0 commit comments

Comments
 (0)