Commit a50296e1 authored by Zac Wood's avatar Zac Wood
Browse files

Added time zone awareness to each location (closes #30)

parent 08a24b6e
import moment from 'moment-timezone';
Template.weather.helpers({ Template.weather.helpers({
weatherData: function() { weatherData: function() {
weatherDataDependency.depend(); weatherDataDependency.depend();
...@@ -50,16 +52,20 @@ Template.weather.helpers({ ...@@ -50,16 +52,20 @@ Template.weather.helpers({
//Formats a unix timestamp a full human readable time //Formats a unix timestamp a full human readable time
formatTimestamp: function(timestamp) { formatTimestamp: function(timestamp) {
if(timestamp === undefined) return "..."; if(timestamp === undefined) return "...";
var d = new Date(timestamp*1000);
//console.log("GOT: "+timestamp) // See https://momentjs.com/timezone/
return d.toLocaleString("en-us", { hour: 'numeric', minute: 'numeric', timeZoneName:'short'}); var d = moment.tz(timestamp*1000, weatherData.data.timezone).format('YYYY-MM-DD HH:MM z');
return d.format();
}, },
//Formats unix time to just a 12 hour time //Formats unix time to just a 12 hour time
formatTimestampToHour: function(timestamp) { formatTimestampToHour: function(timestamp) {
if(timestamp === undefined) return "..."; if(timestamp === undefined) return "...";
var d = new Date(timestamp*1000);
//console.log("GOT: "+timestamp) // See https://momentjs.com/timezone/
return d.toLocaleString("en-us", { hour: 'numeric'}); var time = moment.tz(timestamp*1000, weatherData.data.timezone).format('h A (z)');
return time;
}, },
//Converts icon names from darksky to those that can be used by our css library //Converts icon names from darksky to those that can be used by our css library
convertIconName: function(apiIcon) { convertIconName: function(apiIcon) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"babel-runtime": "^6.22.0" "babel-runtime": "^6.22.0",
"moment-timezone": "^0.5.13"
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment