I always used similar dst check function like this one:
<code>
long adjustDstEurope(long epoch)
{
// last sunday of march
int beginDSTDate= (31 - (5* year(epoch) /4 + 4) % 7);
int beginDSTMonth=3;
//last sunday of october
int endDSTDate= (31 - (5 * year(epoch) /4 + 1) % 7);
int endDSTMonth=10;
// DST is valid as:
if (((month(epoch) > beginDSTMonth) && (month(epoch) < endDSTMonth))
|| ((month(epoch) == beginDSTMonth) && (day(epoch) >= beginDSTDate))
|| ((month(epoch) == endDSTMonth) && (day(epoch) < endDSTDate)))
return true; // DST europe = GMT +2
else return false; // nonDST europe = GMT +1
}
</code>
but i never understood the logic of previous code and did not write it myself.
but now i wrote this:
<code>
boolean dst_check(long epoch) {
//day(); // the day now (1-31)
//weekday(); // day of the week (1-7), Sunday is day 1
if (day(epoch)>= 24+weekday(epoch) && month(epoch) == 3) ||
(month(epoch) > 3 && month(epoch) < 10) ||
(day(epoch)< 24+weekday(epoch) && month(epoch) == 10 )
return true; // DST europe = GMT +2
else return false; // nonDST europe = GMT +1
}
</code>
i want to use smallest code as possible and not extra libs.
Which is best?
rene7777:
Which is best?
Which Arduino board? ESP32 does all of that for you in the background. No effort required on your part.
awneil
August 25, 2023, 8:03am
3
rene7777:
Which is best?
Depends what you mean by, "best"...
IMO, "best" (if possible) is to not use DST at all - do everything in UTC.
Why do you feel you need DST in your Arduino?
Administrations may alter (or abandon) DST on a whim - so no algorithm can be completely reliable.
If you really must do DST on the device, and have a comms link, then signal DST over that link.
It's a esp01.
The DST (European summer/wintertime) is needed for accurate logging and timekeeping events.
Here in Central Europe we go the last Sunday of March and October to +2 instead +1
utc time retrieved by a ntc server every hour.
But is my function not better than the 1st function?
It's hard to test, only once each month I should change the month number and i can test it betwen next Saturday and Sunday.
Official the DST changes on 02:00 and 03:00 AM. But for the working of the programming has not much of a impact.
PaulRB
August 25, 2023, 9:21am
5
The built-in functions mentioned by @gfvalvo also work for esp8266 including esp-01. Very simple to use.
https://werner.rothschopf.net/202011_arduino_esp8266_ntp_en.htm
1 Like
awneil
August 25, 2023, 9:36am
6
You don't need DST for that - just work in UTC!
You mean NTP?
rene7777:
It's hard to test
Indeed it is - that's another good reason not to do it!
Wawa
August 25, 2023, 9:37am
7
See post#9 in this thread .
Change the configTime values to where you live.
The timezone string can be found here . You should pick an NTP server in your country.
Leo..
as already mentioned: use the functionality of the ESP core.
The english page was already posted,
if you need it in German:
ESP8266 NTP Abfrage mit Sommerzeit / Winterzeit (NodeMCU, Wemos D1) (rothschopf.net)
system
Closed
February 21, 2024, 9:59am
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.