Browse Source

Refactor generateFilePath function to use custom date format instead of ISO format

node10
Onja 11 months ago
parent
commit
62798ab869
  1. 19
      src/models/file.js

19
src/models/file.js

@ -28,13 +28,28 @@ class File {
constructor(url) {
this.url = url;
}
formatDateToCustomFormat(date) {
// Obtenir les composantes de la date et de l'heure
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // Janvier est 0, février est 1, etc.
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
// Créer la chaîne au format personnalisé
const formattedDate = `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`;
return formattedDate;
}
// Create a generateFilePath function witch returns a path with a filename and datetime
generateFilePath(filename) {
const date = new Date();
return {
filepath: path.join(dest, `${filename}-${date.toISOString().split('T')[0]}.csv`),
generatedpath: path.join(dest, `${filename}-generated-${date.toISOString().split('T')[0]}.csv`),
filepath: path.join(dest, `${filename}-${this.formatDateToCustomFormat(date)}.csv`),
generatedpath: path.join(dest, `${filename}-generated-${this.formatDateToCustomFormat(date)}.csv`),
};
}

Loading…
Cancel
Save