From ee5600aac9548075634f51113f9b5ed078f82e12 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 20 Dec 2020 13:33:17 -0600 Subject: Fix date format on posts to show year --- src/server.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/server.js b/src/server.js index 81b7b0e..81f1edb 100644 --- a/src/server.js +++ b/src/server.js @@ -50,6 +50,11 @@ function hashWithSalt(password, salt){ return hash.digest("base64"); }; +function formatDate(d) { + let month = d.toLocaleString('default', { month: 'long' }); + return month + " " + d.getDate() + ", " + (1900+d.getYear()) +} + async function formatPostsforSingle(models, postType, postId){ var posts = await models.posts.findAll({ where: { @@ -60,7 +65,8 @@ async function formatPostsforSingle(models, postType, postId){ posts = posts.map(x => x.get({ plain: true })); await addImagesAndTagsToPosts(models, posts) posts.forEach(post => { - post.createdAt = post.createdAt.toString().substring(0, 10) + post.createdAt = formatDate(post.createdAt) + post.showTitle = post.type != "bread" }) return posts } @@ -72,7 +78,7 @@ async function formatPostsForType(models, postType){ posts = posts.map(x => x.get({ plain: true })); await addImagesAndTagsToPosts(models, posts) posts.forEach(post => { - post.createdAt = post.createdAt.toString().substring(0, 10) + post.createdAt = formatDate(post.createdAt) post.showTitle = post.type != "bread" }) return posts; -- cgit v1.2.3