Skip to content

Commit

Permalink
Calculate sunrise/set based on local time date
Browse files Browse the repository at this point in the history
  • Loading branch information
decompil3d committed Jun 12, 2024
1 parent bf0a836 commit 6d84a01
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hourly-weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,10 @@ export class HourlyWeatherCard extends LitElement {
private getAdjustedConditionForForecastSegment(fs: ForecastSegment): string {
const when = new Date(fs.datetime);
const { latitude, longitude } = this.hass.config;
const rise = sunrise(when, latitude, longitude);
const set = sunset(when, latitude, longitude);
const noonUTCOnDay = new Date(when.toLocaleDateString());
noonUTCOnDay.setUTCHours(12, 0, 0, 0);
const rise = sunrise(noonUTCOnDay, latitude, longitude);
const set = sunset(noonUTCOnDay, latitude, longitude);
const isDay = when >= rise && when <= set;
if (!isDay && fs.condition === 'partlycloudy') {
return 'night-partly-cloudy';
Expand Down

0 comments on commit 6d84a01

Please sign in to comment.