-
-
Save jevuu/ec3ee8b937d1b98d4e8951476ad260ca to your computer and use it in GitHub Desktop.
Gets the time that sunrise ends and sunset begins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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