Skip to content

Commit bd50d1e

Browse files
committed
Separate date computation and formatting
1 parent b28fea9 commit bd50d1e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import {capitalize, computed, onMounted, Ref, ref} from "vue";
99
import Tooltip from "../../tooltip.vue";
1010
import {ArtifactDescription} from "../../types";
11-
import {daysBetweenDates, getFutureDate, getPastDate} from "./utils";
11+
import {daysBetweenDates, getFutureDate, getPastDate, formatDate} from "./utils";
1212
import {GraphRenderOpts, renderPlots} from "../../../../graph/render";
1313
import {GraphData, GraphKind, GraphsSelector} from "../../../../graph/data";
1414
import uPlot from "uplot";
@@ -55,7 +55,7 @@ function getGraphRange(artifact: ArtifactDescription): GraphRange {
5555
// the last `DAY_RANGE` days.
5656
if (artifact.type === "try") {
5757
return {
58-
start: getPastDate(date, DAY_RANGE),
58+
start: formatDate(getPastDate(date, DAY_RANGE)),
5959
end: artifact.commit,
6060
date: null,
6161
};
@@ -66,7 +66,7 @@ function getGraphRange(artifact: ArtifactDescription): GraphRange {
6666
// Calculate the end of the range, which is commit date + half of the
6767
// amount of days we want to show. If this date is in the future,
6868
// the server will clip the result at the current date.
69-
const end = getFutureDate(date, DAY_RANGE / 2);
69+
const end = formatDate(getFutureDate(date, DAY_RANGE / 2));
7070
7171
// Calculate how many days there have been from the commit date
7272
const daysInFuture = Math.min(
@@ -78,7 +78,7 @@ function getGraphRange(artifact: ArtifactDescription): GraphRange {
7878
// the days that will be clipped by the server.
7979
const daysInPast = DAY_RANGE - daysInFuture;
8080
81-
const start = getPastDate(date, daysInPast);
81+
const start = formatDate(getPastDate(date, daysInPast));
8282
return {
8383
start,
8484
end,

site/frontend/src/pages/compare/compile/table/utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
/**
22
* Returns a date that is the given days in the past from the passed `date`.
33
*/
4-
export function getPastDate(date: Date, days: number): string {
4+
export function getPastDate(date: Date, days: number): Date {
55
const past = new Date(date.getTime());
66
past.setUTCDate(date.getUTCDate() - days);
7-
return format_ymd(past);
7+
return past;
88
}
99

1010
/**
1111
* Returns a date that is the given days in the future from the passed `date`.
1212
*/
13-
export function getFutureDate(date: Date, days: number): string {
13+
export function getFutureDate(date: Date, days: number): Date {
1414
const future = new Date(date.getTime());
1515
future.setUTCDate(date.getUTCDate() + days);
16-
return format_ymd(future);
16+
return future;
1717
}
1818

19-
function format_ymd(date: Date): string {
19+
/**
20+
* Returns a formated date string
21+
*/
22+
export function formatDate(date: Date): string {
2023
const year = date.getUTCFullYear();
2124
const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
2225
const day = date.getUTCDate().toString().padStart(2, "0");

0 commit comments

Comments
 (0)