Public
Edited
Jul 7, 2024
Insert cell
Insert cell
Insert cell
https://vividmaps.com/sunrise-time-sunset-time-and-hours-of/
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
SunCalc = require("suncalc")
Insert cell
date.toISOString
Insert cell
SunCalc.getTimes(new Date(), 51.5, -0.1).sunrise
Insert cell
data = {
let acc = [];

for (const lat of lats) {
for (const lon of lons) {
let timeZone = getLocationTimeZone(lat, lon);

if (timeZone?.toString().startsWith("Antarctica/")) {
timeZone = undefined;
}

const sunrise = ss.getSunrise(lat, lon, date);
const sunset = ss.getSunset(lat, lon, date);

// prefixing all temporal types with t
const tsunrise = Temporal.Instant.fromEpochMilliseconds(
sunrise.getTime()
);
const tsunset = Temporal.Instant.fromEpochMilliseconds(sunset.getTime());

const tyardstick = timeZone
? Temporal.ZonedDateTime.from({
timeZone,
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
hour: 18
}).toInstant()
: undefined;

const tdurationSinceSunset = tyardstick
? tyardstick.since(tsunset)
: undefined;

let hoursSinceSunset = tdurationSinceSunset?.total({ unit: "hours" });
if (hoursSinceSunset < -10) {
hoursSinceSunset += 24;
}

acc.push({
lat,
lon,
timeZone,
sunrise,
sunset,
tyardstick,
yardstick: new Date(tyardstick?.epochMilliseconds),
tdurationSinceSunset,
// bruh come on TC39 on the good kush
hoursSinceSunset
});
}
}

return acc.filter(
(d) =>
!isNaN(d.sunset.getTime()) && !isNaN(d.sunrise.getTime()) && d.timeZone
);
}
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Temporal = (await require("@js-temporal/polyfill@0.4.3/dist/index.umd.js"))
.Temporal
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more