From c2279c81a8cbfc8a70b82a31ce9dfc54132455d8 Mon Sep 17 00:00:00 2001 From: Type-Style Date: Sat, 21 Sep 2024 14:06:55 +0200 Subject: [PATCH] [Fix] #171, most recent date, add leading 0 --- src/scripts/file.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scripts/file.ts b/src/scripts/file.ts index fc8d013..bb81b41 100644 --- a/src/scripts/file.ts +++ b/src/scripts/file.ts @@ -7,7 +7,8 @@ import logger from '@src/scripts/logger'; export const getFile = (res: Response, next: NextFunction, method: File.method): File.Obj => { const date = new Date(); - const formattedDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; + const formattedDate = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; + const dirPath = path.resolve(__dirname, '../data'); let filePath = path.resolve(dirPath, `data-${formattedDate}.json`); @@ -93,7 +94,7 @@ const findMostRecentFile = (directoryPath: string) => { // check if it is a file (and not a directory) and most recent if (stats.isFile() && stats.mtimeMs > mostRecentTime) { if (stats.mtimeMs > mostRecentTime) { - mostRecentTime &&= stats.mtimeMs; + mostRecentTime = stats.mtimeMs; mostRecentFile = filePath; } }