-
-
Save AbdulKabia/c26b755356569aea81af0f66d85c1d4f to your computer and use it in GitHub Desktop.
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 SunCalc = require('suncalc'); | |
let isLight = false; | |
/** | |
* Calculate the current time of day and figure out if it's dark or light outside. | |
* @param {*} myLat | |
* @param {*} myLng | |
*/ | |
let calculateCurrentTime = (myLat, myLng) => { | |
let tempCurrentTime = SunCalc.getTimes(new Date(), myLat, myLng); | |
let userDawn = tempCurrentTime.dawn; | |
let userDusk = tempCurrentTime.dusk; | |
let myDate = new Date(); | |
if (myDate.getTime() <= userDusk.getTime() && myDate.getTime() >= userDawn.getTime()) { | |
isLight = true; | |
} | |
} | |
module.exports.calculateCurrentTime = calculateCurrentTime; | |
module.exports.isLight = () => isLight; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment