* We use the y/m/d from local time for sunrise/sunset calculations, and the solar calculator * returns the time from midnight in UTC for that day. We therefore need to adjust this * to account for timezone and daylight savings. */
| 36 | * to account for timezone and daylight savings. |
| 37 | */ |
| 38 | ZonedTime getNextSunriseSet(bool isSunrise) |
| 39 | { |
| 40 | auto utcNow = SystemClock.now(eTZ_UTC); |
| 41 | DateTime dt(tz.toLocal(utcNow)); |
| 42 | dt.Hour = 0; |
| 43 | dt.Minute = 0; |
| 44 | dt.Second = 0; |
| 45 | SolarCalculator calc(MyZone::solarRef); |
| 46 | int offset_secs = SECS_PER_MIN * calc.sunRiseSet(isSunrise, dt.Year, dt.Month + 1, dt.Day); |
| 47 | |
| 48 | time_t utcNext = dt + offset_secs; |
| 49 | |
| 50 | // If time has already passed, then make it tomorrow |
| 51 | if(utcNext < utcNow) { |
| 52 | utcNext += SECS_PER_DAY; |
| 53 | } |
| 54 | |
| 55 | return tz.makeZoned(utcNext); |
| 56 | } |
| 57 | |
| 58 | void checkTimeZoneOffset(time_t systemTime) |
| 59 | { |