Split local time and date calculations into their own module.
This commit is contained in:
parent
1590fb9f17
commit
722fb44f7c
13
alertmonUtils.js
Normal file
13
alertmonUtils.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
var moment = require('moment-timezone');
|
||||||
|
|
||||||
|
exports.getLocTimeFromUTC = function(utcDtTm) {
|
||||||
|
var localTm = moment.utc(new Date(utcDtTm));
|
||||||
|
localTm = moment(localTm).tz('America/New_York').format('h:mm:ss a');
|
||||||
|
return localTm;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getLocDateFromUTC = function(utcDtTm) {
|
||||||
|
var localDt = moment.utc(new Date(utcDtTm));
|
||||||
|
localDt = moment(localDt).tz('America/New_York').format('MM-DD-YYYY');
|
||||||
|
return localDt;
|
||||||
|
};
|
19
server.js
19
server.js
@ -2,7 +2,7 @@ var express = require("express");
|
|||||||
var hbs = require('express-hbs');
|
var hbs = require('express-hbs');
|
||||||
require('handlebars-form-helpers').register(hbs.handlebars);
|
require('handlebars-form-helpers').register(hbs.handlebars);
|
||||||
var nodemailer = require('nodemailer');
|
var nodemailer = require('nodemailer');
|
||||||
var moment = require('moment-timezone');
|
var alertmonUtils = require('./alertmonUtils.js');
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var app = express();
|
var app = express();
|
||||||
@ -77,11 +77,8 @@ app.get('/', function(req, res){
|
|||||||
|
|
||||||
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
||||||
rows.forEach(function(row){
|
rows.forEach(function(row){
|
||||||
var localDtTm = moment.utc(new Date(row.MaxPub));
|
row.MaxPubDate = alertmonUtils.getLocDateFromUTC(row.MaxPub);
|
||||||
localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss');
|
row.MaxPubTime = alertmonUtils.getLocTimeFromUTC(row.MaxPub);
|
||||||
row.MaxPub = localDtTm;
|
|
||||||
row.MaxPubDate = moment(localDtTm).format('MM-DD-YYYY');
|
|
||||||
row.MaxPubTime = moment(localDtTm).format('h:mm:ss a');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.render('index', {cores: rows}, function(err, html) {
|
res.render('index', {cores: rows}, function(err, html) {
|
||||||
@ -179,11 +176,11 @@ app.get('/core/:id', function(req, res){
|
|||||||
|
|
||||||
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
// Loop over elements in rows array, convert ugly UTC times to pretty local times.
|
||||||
rows.forEach(function(row){
|
rows.forEach(function(row){
|
||||||
var localDtTm = moment.utc(new Date(row.published_at));
|
//var localDtTm = moment.utc(new Date(row.published_at));
|
||||||
localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss');
|
//localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss');
|
||||||
row.published_at = localDtTm;
|
//row.published_at = localDtTm;
|
||||||
row.pubDate = moment(localDtTm).format('MM-DD-YYYY');
|
row.pubDate = alertmonUtils.getLocDateFromUTC(row.published_at);
|
||||||
row.pubTime = moment(localDtTm).format('h:mm:ss a');
|
row.pubTime = alertmonUtils.getLocTimeFromUTC(row.published_at);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.render('core', {alerts: rows}, function(err, html) {
|
res.render('core', {alerts: rows}, function(err, html) {
|
||||||
|
Loading…
Reference in New Issue
Block a user