Split local time and date calculations into their own module.

This commit is contained in:
jkaplon 2015-08-05 14:31:22 -04:00
parent 1590fb9f17
commit 722fb44f7c
2 changed files with 21 additions and 11 deletions

13
alertmonUtils.js Normal file
View 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;
};

View File

@ -2,7 +2,7 @@ var express = require("express");
var hbs = require('express-hbs');
require('handlebars-form-helpers').register(hbs.handlebars);
var nodemailer = require('nodemailer');
var moment = require('moment-timezone');
var alertmonUtils = require('./alertmonUtils.js');
var fs = require("fs");
var bodyParser = require("body-parser");
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.
rows.forEach(function(row){
var localDtTm = moment.utc(new Date(row.MaxPub));
localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss');
row.MaxPub = localDtTm;
row.MaxPubDate = moment(localDtTm).format('MM-DD-YYYY');
row.MaxPubTime = moment(localDtTm).format('h:mm:ss a');
row.MaxPubDate = alertmonUtils.getLocDateFromUTC(row.MaxPub);
row.MaxPubTime = alertmonUtils.getLocTimeFromUTC(row.MaxPub);
});
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.
rows.forEach(function(row){
var localDtTm = moment.utc(new Date(row.published_at));
localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss');
row.published_at = localDtTm;
row.pubDate = moment(localDtTm).format('MM-DD-YYYY');
row.pubTime = moment(localDtTm).format('h:mm:ss a');
//var localDtTm = moment.utc(new Date(row.published_at));
//localDtTm = moment(localDtTm).tz('America/New_York').format('MM-DD-YYYY HH:mm:ss');
//row.published_at = localDtTm;
row.pubDate = alertmonUtils.getLocDateFromUTC(row.published_at);
row.pubTime = alertmonUtils.getLocTimeFromUTC(row.published_at);
});
res.render('core', {alerts: rows}, function(err, html) {