UNPKG

jw-weather

Version:

Reader for various weather APIs

162 lines (127 loc) 3.82 kB
function formatDate(fullDate, formatString) { try { var myDate = new Date(fullDate); var fDate = ""; var year = myDate.getFullYear(); var month = myDate.getMonth() + 1; var date = myDate.getDate(); // @ts-ignore if (month < 10) { month = '0' + month; } // @ts-ignore if (date < 10) { date = '0' + date; } if (formatString === 'short') { fDate += year; fDate += '/' + month; fDate += '/' + date; return fDate; } else if (formatString === 'YY/MM/DD') { fDate += year.toString().substr(-2); fDate += '/' + month; fDate += '/' + date; return fDate; } else if (formatString === 'TEMPLATE') { } else { return fullDate; //no format string provided } } catch (e) { return fullDate; //something went wrong } } function formatTime(fullTime, formatString) { if (fullTime === null) { return ''; } else { if (typeof formatString === 'undefined') { formatString = 'short'; } var myTime = new Date(fullTime); var hours = myTime.getHours(); var ampm = ' pm'; if (hours < 12) { ampm = ' am'; } if (hours > 12) { hours -= 12; } var mins = myTime.getMinutes(); // @ts-ignore if (mins < 10) { mins = '0' + mins; } return hours + ':' + mins + ampm; } } var LAT = 38.90045212699474; var LONG = -77.03596056403421; var Weather = require('./weather'); var openWeather = new Weather.service({ provider: 'OpenWeatherMap', key: '', latitude: LAT, longitude: LONG, celsius: false }); openWeather.on('ready', function() { console.log('openWeather Ready'); console.log('...update openWeather...'); openWeather.update(function() { console.log('openWeather listing:'); console.log(openWeather.fullWeather()); }); }); openWeather.on('error', function(err) { console.log('Weather Error: ' + err); }); /* var accuWeather = new Weather.service({ provider: 'accuWeather', key: '', latitude: LAT, longitude: LONG, celsius: false }); accuWeather.on('ready', function() { console.log('accuWeather Ready'); console.log('...update accuWeather...'); accuWeather.update(function() { console.log('accuWeather listing:'); console.log(accuWeather.fullWeather().temp); }); }); accuWeather.on('error', function(err) { console.log('accuWeather Error: ' + err); }); */ /* var darkSky = new Weather.service({ provider: 'darkSky', key: '', latitude: LAT, longitude: LONG, celsius: false }); darkSky.on('ready', function() { console.log('darkSky Ready'); console.log('...update darkSky...'); darkSky.update(function() { console.log('darkSky listing:'); console.log(darkSky.fullWeather().temp); }); }); darkSky.on('error', function(err) { console.log('darkSky Error: ' + err); }); */ /* var weatherbit = new Weather.service({ provider: 'weatherbit', key: '', latitude: LAT, longitude: LONG, celsius: false }); weatherbit.on('ready', function() { console.log('weatherbit Ready'); console.log('...update weatherbit...'); weatherbit.update(function() { console.log('weatherbit listing:'); console.log(weatherbit.fullWeather()); //console.log(formatTime(weatherbit.sunrise)); }); }); weatherbit.on('error', function(err) { console.log('weatherbit Error: ' + err); }); */