Skip to content

Instantly share code, notes, and snippets.

@jevuu
Created March 23, 2018 02:56
Show Gist options
  • Save jevuu/33d5c551709faf7e85236334dcb886b1 to your computer and use it in GitHub Desktop.
Save jevuu/33d5c551709faf7e85236334dcb886b1 to your computer and use it in GitHub Desktop.
//Get date and sunrise and sunset times. Compare current time against sunrise and sunset times. Set to night mode.
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){
log.info('The sun is up.');
tileUrl = 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png'
}else{
log.info('The sun is down. Or error.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment