#38 - Remplacer momentjs

This commit is contained in:
Damien Broqua 2022-04-10 16:04:50 +02:00
parent e8f91288fc
commit f5196edfb8
3 changed files with 15 additions and 7 deletions

View File

@ -47,6 +47,8 @@
"connect-flash": "^0.1.1", "connect-flash": "^0.1.1",
"connect-mongo": "^4.6.0", "connect-mongo": "^4.6.0",
"cookie-parser": "^1.4.6", "cookie-parser": "^1.4.6",
"date-fns": "^2.28.0",
"date-fns-tz": "^1.3.3",
"debug": "^4.3.3", "debug": "^4.3.3",
"disconnect": "^1.2.2", "disconnect": "^1.2.2",
"ejs": "^3.1.6", "ejs": "^3.1.6",
@ -55,8 +57,6 @@
"express-session": "^1.17.2", "express-session": "^1.17.2",
"joi": "^17.6.0", "joi": "^17.6.0",
"knacss": "^8.0.4", "knacss": "^8.0.4",
"moment": "^2.29.1",
"moment-timezone": "^0.5.34",
"mongoose": "^6.2.1", "mongoose": "^6.2.1",
"mongoose-unique-validator": "^3.0.0", "mongoose-unique-validator": "^3.0.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",

View File

@ -1,4 +1,4 @@
import moment from "moment"; import { format as formatDate } from "date-fns";
import Pages from "./Pages"; import Pages from "./Pages";
import Export from "./Export"; import Export from "./Export";
@ -26,7 +26,7 @@ class Albums extends Pages {
User: user._id, User: user._id,
}; };
data.released = data.released data.released = data.released
? moment(data.released.replace("-00", "-01")) ? new Date(data.released.replace("-00", "-01"))
: null; : null;
delete data.id; delete data.id;
@ -211,11 +211,16 @@ class Albums extends Pages {
async loadItem() { async loadItem() {
const { itemId: _id } = this.req.params; const { itemId: _id } = this.req.params;
const { _id: User } = this.req.user; const { _id: User } = this.req.user;
const item = await AlbumsModel.findOne({ const album = await AlbumsModel.findOne({
_id, _id,
User, User,
}); });
const item = {
...album.toJSON(),
released: formatDate(album.released, "MM/dd/yyyy"),
};
this.setPageContent("item", item); this.setPageContent("item", item);
this.setPageTitle( this.setPageTitle(
`Détails de l'album ${item.title} de ${item.artists_sort}` `Détails de l'album ${item.title} de ${item.artists_sort}`

View File

@ -1,4 +1,5 @@
import momenttz from "moment-timezone"; import { utcToZonedTime } from "date-fns-tz";
import setHours from "date-fns/setHours";
import xl from "excel4node"; import xl from "excel4node";
class Export { class Export {
@ -132,7 +133,9 @@ class Export {
} }
if (released) { if (released) {
ws.cell(currentRow, 7) ws.cell(currentRow, 7)
.date(momenttz.tz(released, "Europe/Paris").hour(12)) .date(
setHours(utcToZonedTime(released, "Europe/Paris"), 12)
)
.style({ numberFormat: "dd/mm/yyyy" }); .style({ numberFormat: "dd/mm/yyyy" });
} }
ws.cell(currentRow, 8).string(format).style(style); ws.cell(currentRow, 8).string(format).style(style);