weather: use next solar event

Fixes urbit/landscape#679
This commit is contained in:
Liam Fitzgerald 2021-06-28 11:45:11 +10:00
parent c31eefac1c
commit 5e1919d054
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -202,19 +202,20 @@ class WeatherTile extends React.Component<WeatherTileProps, WeatherTileState> {
const d = data['weather'][0]; const d = data['weather'][0];
const bg = this.colorFromCondition(data); const bg = this.colorFromCondition(data);
const sunset = moment(moment().format('YYYY-MM-DD') + ' ' + d.astronomy[0].sunset, 'YYYY-MM-DD hh:mm A'); const sunset = moment(moment().hours(1).format('YYYY-MM-DD') + ' ' + d.astronomy[0].sunset, 'YYYY-MM-DD hh:mm A');
const sunsetDiff = sunset.diff(moment(), 'hours'); let sunsetDiff = sunset.diff(moment(), 'hours');
const sunrise = moment(moment().format('YYYY-MM-DD') + ' ' + d.astronomy[0].sunrise, 'YYYY-MM-DD hh:mm A'); const sunrise = moment(moment().hours(1).format('YYYY-MM-DD') + ' ' + d.astronomy[0].sunrise, 'YYYY-MM-DD hh:mm A');
let sunriseDiff = sunrise.diff(moment(), 'hours'); let sunriseDiff = sunrise.diff(moment(), 'hours');
if (sunriseDiff > 24) { if (sunsetDiff < 0) {
sunriseDiff = sunriseDiff - 24; sunsetDiff = sunsetDiff + 24;
} else if (sunriseDiff < 0) { }
if (sunriseDiff < 0) {
sunriseDiff = sunriseDiff + 24; sunriseDiff = sunriseDiff + 24;
} }
const nextSolarEvent = sunsetDiff > 0 const nextSolarEvent = sunsetDiff < sunriseDiff
? `Sun sets in ${sunsetDiff}h` ? `Sun sets in ${sunsetDiff}h`
: `Sun rises in ${sunriseDiff}h`; : `Sun rises in ${sunriseDiff}h`;