58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
const fs = require('fs');
|
|
const moment = require('moment');
|
|
|
|
const crearDDMMAAAA = (date) => {
|
|
const fechaMoment = moment(date);
|
|
let ddmmaaaa = '';
|
|
|
|
if (fechaMoment.isValid())
|
|
ddmmaaaa = `${fechaMoment.year()}/${
|
|
fechaMoment.month() < 9
|
|
? '0' + (fechaMoment.month() + 1)
|
|
: fechaMoment.month() + 1
|
|
}/${
|
|
fechaMoment.date() < 10 ? '0' + fechaMoment.date() : fechaMoment.date()
|
|
}`;
|
|
return ddmmaaaa;
|
|
};
|
|
|
|
const crearDDMMAAAAHHMM = (date) => {
|
|
const fechaMoment = moment(date);
|
|
let ddmmaaaa = crearDDMMAAAA(date);
|
|
|
|
if (fechaMoment.isValid())
|
|
ddmmaaaa += ` ${
|
|
fechaMoment.hour() < 10 ? '0' + fechaMoment.hour() : fechaMoment.hour()
|
|
}:${
|
|
fechaMoment.minute() < 10
|
|
? '0' + fechaMoment.minute()
|
|
: fechaMoment.minute()
|
|
}`;
|
|
return ddmmaaaa;
|
|
};
|
|
|
|
const eliminarArchivo = (path) => {
|
|
return new Promise((resolve, reject) => {
|
|
fs.unlink(path, (err) => {
|
|
if (err) reject(err);
|
|
resolve({ message: 'Se elimino el archivo correctamente.' });
|
|
});
|
|
});
|
|
};
|
|
|
|
const crearArchivo = (path, texto) => {
|
|
return new Promise((resolve, reject) => {
|
|
fs.appendFile(path, texto, (err) => {
|
|
if (err) reject(err);
|
|
resolve({ message: 'Se creo el archivo correctamente.' });
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
crearDDMMAAAA,
|
|
crearDDMMAAAAHHMM,
|
|
eliminarArchivo,
|
|
crearArchivo,
|
|
};
|