From 43fd34f5f74b5cc66265612d909992efd34251eb Mon Sep 17 00:00:00 2001 From: Philip Langer Date: Fri, 11 Aug 2023 16:13:29 +0200 Subject: [PATCH] Fix sorting by date string Contributed on behalf of STMicroelectronics --- scripts/performance-report.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/performance-report.ts b/scripts/performance-report.ts index 00553cf4e..e013d2fe6 100644 --- a/scripts/performance-report.ts +++ b/scripts/performance-report.ts @@ -220,11 +220,10 @@ export async function generatePerformanceReport(path: string) { export async function readValuesFromHistory(path: string, values: string[]): Promise> { const valueHistoryMap = initializeValueHistoryMap(values); - const files = fs.readdirSync(path).sort(); + const files = fs.readdirSync(path) + .filter(file => !file.endsWith('index.html')) + .sort((a, b) => toDate(a).getTime() - toDate(b).getTime()); for (const file of files) { - if (file.endsWith('index.html')) { - continue; - } const entryLabel = file.substring(0, file.indexOf('.')); const entries = await readEntries(path + '/' + file, values); entries.forEach(entry => @@ -243,6 +242,13 @@ export function initializeValueHistoryMap(values: string[]) { return valueHistoryMap; } +export function toDate(fileName: string): Date { + const [date, timeString] = fileName.replace('.txt', '').split('T'); + const dateFragments = date.split('-').map(str => Number.parseInt(str)); + const timeFragments = timeString.split('-').map(str => Number.parseInt(str)); + return new Date(dateFragments[0], dateFragments[1], dateFragments[2], timeFragments[0], timeFragments[1], timeFragments[2]); +} + export async function readEntries(path: string, values: string[]): Promise<{ valueLabel: string, entryValue: number }[]> { const entries: { valueLabel: string, entryValue: number }[] = []; try {