Reformat timestamps and display as local times using moment-timezone
This commit is contained in:
parent
c1f092f5d1
commit
4e36ba07ed
23
package.json
23
package.json
@ -1,12 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "alertmon",
|
"name": "alertmon",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.12.4",
|
"body-parser": "^1.12.4",
|
||||||
"express": "^4.12.4",
|
"express": "^4.12.4",
|
||||||
"sqlite3": "^3.0.8",
|
"express-hbs": "^0.8.4",
|
||||||
"express-hbs": "^0.8.4",
|
"moment-timezone": "^0.4.0",
|
||||||
"nodemailer": "^1.3.4"
|
"nodemailer": "^1.3.4",
|
||||||
},
|
"sqlite3": "^3.0.8"
|
||||||
"scripts": { "start": "node server.js" }
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node server.js"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var express = require("express");
|
var express = require("express");
|
||||||
var hbs = require('express-hbs');
|
var hbs = require('express-hbs');
|
||||||
var nodemailer = require('nodemailer');
|
var nodemailer = require('nodemailer');
|
||||||
|
var moment = require('moment-timezone');
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var app = express();
|
var app = express();
|
||||||
@ -86,6 +87,14 @@ app.get('/core/:id', function(req, res){
|
|||||||
} else {
|
} else {
|
||||||
//console.log("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;");
|
//console.log("SELECT coreId, published_at FROM Alerts WHERE coreId = '" + coreId + "' ORDER BY published_at DESC LIMIT 30;");
|
||||||
//console.log(rows);
|
//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.render('core', {alerts: rows}, function(err, html) {
|
||||||
res.send(html);
|
res.send(html);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user