MCPcopy Index your code
hub / github.com/darkreader/darkreader / isNightAtLocation

Function isNightAtLocation

src/utils/time.ts:240–263  ·  view source on GitHub ↗
(
    latitude: number,
    longitude: number,
    date: Date = new Date(),
)

Source from the content-addressed store, hash-verified

238}
239
240export function isNightAtLocation(
241 latitude: number,
242 longitude: number,
243 date: Date = new Date(),
244): boolean {
245 const time = getSunsetSunriseUTCTime(latitude, longitude, date);
246
247 if (time.alwaysDay) {
248 return false;
249 } else if (time.alwaysNight) {
250 return true;
251 }
252
253 const sunriseTime = time.sunriseTime;
254 const sunsetTime = time.sunsetTime;
255 const currentTime = (
256 date.getUTCHours() * getDuration({hours: 1}) +
257 date.getUTCMinutes() * getDuration({minutes: 1}) +
258 date.getUTCSeconds() * getDuration({seconds: 1}) +
259 date.getUTCMilliseconds()
260 );
261
262 return isInTimeIntervalUTC(sunsetTime, sunriseTime, currentTime);
263}
264
265export function nextTimeChangeAtLocation(
266 latitude: number,

Callers 3

updateAutoStateMethod · 0.90
SunMoonIconFunction · 0.90
time.tests.tsFile · 0.90

Calls 3

getSunsetSunriseUTCTimeFunction · 0.85
getDurationFunction · 0.85
isInTimeIntervalUTCFunction · 0.85

Tested by

no test coverage detected