Replies: 2 comments
-
I've been comparing the import { DateTime } from "luxon";
const current = data.current_condition[0];
const weather = data.weather[0];
const { sunrise, sunset } = weather.astronomy[0];
const observationTime = DateTime.fromFormat(current.localObsDateTime, "yyyy-MM-dd hh:mm a").toMillis();
const sunriseTime = DateTime.fromFormat(sunrise, "hh:mm a").toMillis();
const sunsetTime = DateTime.fromFormat(sunset, "hh:mm a").toMillis();
// This might not be accurate in extreme latitudes, e.g where sunset can be after midnight,
// but should be fine most of the time in most areas
const isDayTime = observationTime > sunriseTime && observationTime < sunsetTime; Keep in mind that this definitely won't catch all edge cases, as Igor points out here: #581 (comment). I'm not even sure how wttr would respond to such cases, e.g where there is no sunrise / sunset for the whole day. I'm using |
Beta Was this translation helpful? Give feedback.
-
Have you seen:
Also check out this StackOverflow post to grep Sunrise/Sunset: https://unix.stackexchange.com/questions/723733/regex-that-would-grep-the-time-after-a-string |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm looking for an easy way to determine if it is day or night. Is there something in the json that is specifically for this? I thought maybe the UV field, but it always seems to be low when at night it would be zero (I think). Of course I can use the time of day and calculate sun position, but that seems like overkill.
Beta Was this translation helpful? Give feedback.
All reactions