diff --git a/package.json b/package.json index a6c6dea..329b77b 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,15 @@ { - "name": "alertmon", - "version": "0.0.1", - "dependencies": { - "body-parser": "^1.12.4", - "express": "^4.12.4", - "sqlite3": "^3.0.8", - "express-hbs": "^0.8.4", - "nodemailer": "^1.3.4" - }, - "scripts": { "start": "node server.js" } + "name": "alertmon", + "version": "0.0.1", + "dependencies": { + "body-parser": "^1.12.4", + "express": "^4.12.4", + "express-hbs": "^0.8.4", + "moment-timezone": "^0.4.0", + "nodemailer": "^1.3.4", + "sqlite3": "^3.0.8" + }, + "scripts": { + "start": "node server.js" + } } diff --git a/server.js b/server.js index 7ff6fd8..de3ae15 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,7 @@ var express = require("express"); var hbs = require('express-hbs'); var nodemailer = require('nodemailer'); +var moment = require('moment-timezone'); var fs = require("fs"); var bodyParser = require("body-parser"); var app = express(); @@ -86,6 +87,14 @@ app.get('/core/:id', function(req, res){ } else { //console.log("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;"); //console.log(rows); + + // Loop over elements in rows array, convert ugly UTC times to pretty local times. + rows.forEach(function(row){ + var localDtTm = moment.utc((row.published_at || "").replace(/-/g,"/").replace(/[TZ]/g," ")).toDate(); + localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss'); + row.published_at = localDtTm; + }); + res.render('core', {alerts: rows}, function(err, html) { res.send(html); });