From 41a095e465c9a35d1b183d185a0458e877bb22da Mon Sep 17 00:00:00 2001 From: Badri Sunderarajan Date: Thu, 25 Feb 2021 15:35:35 +0530 Subject: [PATCH] Parse dates nicely with Moment.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So we can see them all in a standard format 🙂 --- index.js | 5 +++-- package.json | 3 ++- yarn.lock | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5c41896..5ac3378 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const express = require("express") const bodyParser = require("body-parser") +const moment = require("moment") const Airtable = require("airtable") // Let's load some configuration! @@ -57,8 +58,8 @@ app.post("/edcal", (req, res) => { articles.push({ title: record.get("Title"), author: record.get("Author"), - due_date: record.get("Due Date"), - publish_date: record.get("Publish Date"), + due_date: moment(record.get("Due Date")).format("DD MMM"), + publish_date: moment(record.get("Publish Date")).format("DD MMM YYYY"), in_charge: record.get("In charge"), status: record.get("Status"), }) diff --git a/package.json b/package.json index 4bd1bff..3d8676f 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "airtable": "^0.10.1", "body-parser": "^1.19.0", "dotenv": "^8.2.0", - "express": "^4.17.1" + "express": "^4.17.1", + "moment": "^2.29.1" } } diff --git a/yarn.lock b/yarn.lock index fbf442e..0ea5af8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -273,6 +273,11 @@ mime@1.6.0: resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== +moment@^2.29.1: + version "2.29.1" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3" + integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"