MCPcopy Create free account
hub / github.com/SmingHub/Sming / getNextSunriseSet

Function getNextSunriseSet

samples/SystemClock_NTP/app/NtpClientDemo.cpp:38–56  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

36 * to account for timezone and daylight savings.
37 */
38ZonedTime 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
58void checkTimeZoneOffset(time_t systemTime)
59{

Callers 1

ntpResultMethod · 0.85

Calls 1

nowMethod · 0.45

Tested by

no test coverage detected