Skip to content

Instantly share code, notes, and snippets.

@AbdulKabia
Created March 28, 2018 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbdulKabia/c26b755356569aea81af0f66d85c1d4f to your computer and use it in GitHub Desktop.
Save AbdulKabia/c26b755356569aea81af0f66d85c1d4f to your computer and use it in GitHub Desktop.
'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