Reformat timestamps and display as local times using moment-timezone

This commit is contained in:
jkaplon 2015-07-09 12:33:53 -04:00
parent c1f092f5d1
commit 4e36ba07ed
2 changed files with 22 additions and 10 deletions

View File

@ -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"
}
}

View File

@ -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);
});