Skip to content

Commit

Permalink
[Fix] #171, most recent date, add leading 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Type-Style committed Sep 21, 2024
1 parent b5543a4 commit c2279c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/scripts/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit c2279c8

Please sign in to comment.