Skip to content

Commit 455e097

Browse files
add new toSimpleDateString function
1 parent 3087239 commit 455e097

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

benchmarking/src/benchmarking.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async function benchmarkFetch(url: string, options: BenchmarkFetchOptions): Prom
9797
export async function saveResultsToDisk(results: BenchmarkingResults): Promise<string> {
9898
const date = new Date();
9999

100-
const fileName = `${date.toISOString().split(".")[0]!.replace("T", "_").replaceAll(":", "-")}.json`;
100+
const fileName = `${toSimpleDateString(date)}.json`;
101101

102102
const outputFile = nodePath.resolve(`./results/${fileName}`);
103103

@@ -108,3 +108,20 @@ export async function saveResultsToDisk(results: BenchmarkingResults): Promise<s
108108

109109
return outputFile;
110110
}
111+
112+
/**
113+
* Takes a date and coverts it to a simple format that can be used as
114+
* a filename (which is human readable and doesn't contain special
115+
* characters)
116+
*
117+
* The format being: `YYYY-MM-DD_hh-mm-ss`
118+
*
119+
* @param date the date to convert
120+
* @returns a string representing the date
121+
*/
122+
function toSimpleDateString(date: Date): string {
123+
const isoString = date.toISOString();
124+
const isoDate = isoString.split(".")[0]!;
125+
126+
return isoDate.replace("T", "_").replaceAll(":", "-");
127+
}

0 commit comments

Comments
 (0)