Skip to content

Commit 65b43ae

Browse files
committed
Guarantee end_date is always on or before the current date for the detail chart
1 parent 908eaaf commit 65b43ae

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

site/frontend/src/pages/compare/compile/table/benchmark-detail.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,20 @@ function getGraphRange(
7474
// ranges. If the commit range is not larger than the `dayRange`, the display will likely be
7575
// "centered" around the commit date.
7676
77-
// Calculate the end of the range, which is commit date + half of the
78-
// amount of days we want to show. If this date is in the future,
79-
// the server will clip the result at the current date.
80-
const end = formatDate(getFutureDate(end_date, DAY_RANGE / 2));
77+
// Calculate the end of the range, which is the earlier date between
78+
// current date and the commit date + half of the amount of days we
79+
// want to show.
80+
let centered_end = getFutureDate(end_date, DAY_RANGE / 2);
81+
const today = new Date().setUTCHours(0, 0, 0, 0);
82+
if (centered_end.getTime() > today) {
83+
centered_end = new Date(today);
84+
}
85+
const end = formatDate(centered_end);
8186
8287
// Calculate the start of the range, which is the earlier date between
83-
// the base artifact date and the commit date - half of the amount of days
88+
// the base artifact date and the calculated end date - the amount of days
8489
// we want to show.
85-
const centered_start = getPastDate(end_date, DAY_RANGE / 2);
90+
const centered_start = getPastDate(centered_end, DAY_RANGE);
8691
const start = formatDate(
8792
start_date < centered_start ? start_date : centered_start
8893
);

0 commit comments

Comments
 (0)