ec-weather-js
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "ec-weather-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Javascript API for Environment Canada Weather Data", | ||
@@ -5,0 +5,0 @@ "main": "Weather.js", |
@@ -73,3 +73,3 @@ /** | ||
} | ||
} | ||
}; | ||
const result = recurse(this.data); | ||
@@ -107,3 +107,3 @@ return new Parse(result); | ||
} | ||
} | ||
}; | ||
const result = recurse(this.data); | ||
@@ -110,0 +110,0 @@ return new Parse(result); |
@@ -21,3 +21,3 @@ /** | ||
constructor(fetchedXMLWeatherData) { | ||
if (!fetchedXMLWeatherData) throw new TypeError('Constructor must be passed weather data from Environment Canada.') | ||
if (!fetchedXMLWeatherData) throw new TypeError('Constructor must be passed weather data from Environment Canada.'); | ||
if (typeof fetchedXMLWeatherData !== 'string') throw new TypeError('Argument must be a string.'); | ||
@@ -71,5 +71,5 @@ | ||
if (date instanceof Date) { | ||
const utcTimestamp = makeUTCTimestamp(date); | ||
const utcTimestamp = this._makeUTCTimestamp(date); | ||
// Retreive the value if the date stamp is a key | ||
// Retreive the value if the timestamp is a key | ||
if (forecastData.has(utcTimestamp)) { | ||
@@ -106,3 +106,3 @@ return forecastData.get(utcTimestamp); | ||
// and if the hour is at night, add 'night' | ||
const weekday = (localDateHour >= 6 && localDateHour < 18) ? getWeekDay(localDate) : getWeekDay(localDate) + ' night'; | ||
const weekday = (localDateHour >= 6 && localDateHour < 18) ? this._getWeekDay(localDate) : this._getWeekDay(localDate) + ' night'; | ||
// retrieve the forecast for that day of the week. | ||
@@ -117,46 +117,46 @@ return forecastData.get(weekday); | ||
} | ||
} | ||
/** | ||
* Helper function. | ||
* Turns a Date instance into a UTC Timestamp compatible with Environment Canada's weather data. | ||
* @param {<Date>} date The date to forecast. | ||
* @returns {string} The UTC Timestamp. | ||
*/ | ||
function makeUTCTimestamp(date) { | ||
const year = date.getUTCFullYear().toString(); | ||
let month = date.getUTCMonth() + 1; | ||
month = month.toString(); | ||
if (month.length < 2) month = '0' + month; | ||
let day = date.getUTCDate().toString(); | ||
if (day.length < 2) day = '0' + day; | ||
let hour = date.getUTCHours().toString(); | ||
if (hour.length < 2) hour = '0' + hour; | ||
return year + month + day + hour + '00'; | ||
/** | ||
* Helper method. | ||
* Turns a Date instance into a UTC Timestamp compatible with Environment Canada's weather data. | ||
* @param {<Date>} date The date to forecast. | ||
* @returns {string} The UTC Timestamp. | ||
*/ | ||
_makeUTCTimestamp(date) { | ||
const year = date.getUTCFullYear().toString(); | ||
let month = date.getUTCMonth() + 1; | ||
month = month.toString(); | ||
if (month.length < 2) month = '0' + month; | ||
let day = date.getUTCDate().toString(); | ||
if (day.length < 2) day = '0' + day; | ||
let hour = date.getUTCHours().toString(); | ||
if (hour.length < 2) hour = '0' + hour; | ||
return year + month + day + hour + '00'; | ||
} | ||
/** | ||
* Helper method. | ||
* Expands the abbreviated weekday text returned from a Date object. | ||
* @param {<Date>} date The localized date to forecast. | ||
* @returns {string} Full weekday name. | ||
*/ | ||
_getWeekDay(date) { | ||
const partial = date.toUTCString().slice(0, 3); | ||
const days = new Map([ | ||
[ 'sun', 'sunday' ], | ||
[ 'mon', 'monday' ], | ||
[ 'tue', 'tuesday' ], | ||
[ 'wed', 'wednesday' ], | ||
[ 'thu', 'thursday' ], | ||
[ 'fri', 'friday' ], | ||
[ 'sat', 'saturday' ] | ||
]); | ||
return days.get(partial.toLowerCase()); | ||
} | ||
} | ||
/** | ||
* Helper function. | ||
* Expands the abbreviated weekday text returned from a Date object. | ||
* @param {<Date>} date The localized date to forecast. | ||
* @returns {string} Full weekday name. | ||
*/ | ||
function getWeekDay(date) { | ||
const partial = date.toUTCString().slice(0, 3); | ||
const days = new Map([ | ||
[ 'sun', 'sunday' ], | ||
[ 'mon', 'monday' ], | ||
[ 'tue', 'tuesday' ], | ||
[ 'wed', 'wednesday' ], | ||
[ 'thu', 'thursday' ], | ||
[ 'fri', 'friday' ], | ||
[ 'sat', 'saturday' ] | ||
]); | ||
return days.get(partial.toLowerCase()); | ||
} | ||
module.exports = Weather; |
13186
6