Skip to content

Instantly share code, notes, and snippets.

@jevuu
Created March 23, 2018 03:12
Show Gist options
  • Save jevuu/ec3ee8b937d1b98d4e8951476ad260ca to your computer and use it in GitHub Desktop.
Save jevuu/ec3ee8b937d1b98d4e8951476ad260ca to your computer and use it in GitHub Desktop.
Gets the time that sunrise ends and sunset begins
'use strict';
const log = require('./log');
const SunCalc = require('suncalc');
var mode = 'day';
module.exports.setMode = (lat, lng) => {
var date = new Date();//'2018-03-16T23:59:59.000Z');
var sunTimes = SunCalc.getTimes(date, lat, lng);
log.info('Current date and time is:' + date + '\nTime for sunset is:' + sunTimes.sunset);
if (date > sunTimes.sunriseEnd && date < sunTimes.sunset){
mode = "day";
log.info('The sun is up.');
}else{
mode = "night";
log.info('The sun is down. Or error.');
}
return mode;
}
module.exports.getMode = () => {
return mode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment