diff --git a/.gitignore b/.gitignore index ba1fafd..3bf8a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ node_modules public/ePub views/header2.ejs index-temp.ejs +utils.js +public/AirQIdx_Guide.png \ No newline at end of file diff --git a/crypto.js b/crypto.js index 968bfc1..295487b 100644 --- a/crypto.js +++ b/crypto.js @@ -8,6 +8,21 @@ const decrypt = (data) => { return CryptoJS.enc.Base64.parse(data).toString(CryptoJS.enc.Utf8); }; +const toLocalDt = (unix_ts) => { + // Create a new JavaScript Date object based on the timestamp + // multiplied by 1000 so that the argument is in milliseconds, not seconds. + var date = new Date(unix_ts * 1000); + // Hours part from the timestamp + var hours = date.getHours(); + // Minutes part from the timestamp + var minutes = "0" + date.getMinutes(); + // Seconds part from the timestamp + var seconds = "0" + date.getSeconds(); + + // Will display time in 10:30:23 format + return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); +} + function test() { let enStr = encrypt("e88e1a8096cd4897b79b230a9c49b243"); console.log("Encrypted Key: " + enStr); @@ -16,4 +31,4 @@ function test() { } // test(); -export {encrypt, decrypt}; \ No newline at end of file +export {encrypt, decrypt, toLocalDt}; \ No newline at end of file diff --git a/index.js b/index.js index 799048b..1d15224 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,8 @@ dotenv.config() import request from 'request'; import express from 'express'; import bodyParser from 'body-parser'; -import {encrypt, decrypt} from './crypto.js' +import {encrypt, decrypt} from './crypto.js'; + // Create network routing const app = express(); @@ -31,7 +32,7 @@ app.get('/weatherbit', (req, res) => { // console.dir(req.params) // console.dir(req.body); let apikey = encrypt(process.env.WEATHERBIT_KEY); - res.render('pages/weatherbit', { key: apikey}); + res.render('pages/weatherbit', { key: apikey }); }) // Posting data to the client-side requires two API calls. diff --git a/public/utils.ejs b/public/utils.ejs new file mode 100644 index 0000000..dcf3d75 --- /dev/null +++ b/public/utils.ejs @@ -0,0 +1,18 @@ +<% + +unixTsToLocalTime = (unix_ts) => { + // Create a new JavaScript Date object based on the timestamp + // multiplied by 1000 so that the argument is in milliseconds, not seconds. + var date = new Date(unix_ts * 1000); + // Hours part from the timestamp + var hours = date.getHours(); + // Minutes part from the timestamp + var minutes = "0" + date.getMinutes(); + // Seconds part from the timestamp + var seconds = "0" + date.getSeconds(); + + // Will display time in 10:30:23 format + return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); +} + +%> \ No newline at end of file diff --git a/views/pages/weatherbit.ejs b/views/pages/weatherbit.ejs index 2bf5fd1..9239651 100644 --- a/views/pages/weatherbit.ejs +++ b/views/pages/weatherbit.ejs @@ -3,13 +3,14 @@
<%- include('./../partials/head'); %> + <%- include ('./../../public/utils'); %>