Daylight Saving Time - DST in europe

Hi,

For a while I'm trying to find out if DST is on or not. I have a actual sketch running that send me sun up / sun down times. In this program I'm using the dst setting for Europe and there time is running like a charm but when I receive the time of dusk2down it is off for 1 hour during dst on.

I had found Determining if currently set time is in daylight savings or not - #5 by robertew - Programming Questions - Arduino Forum from robertew and decided to adjust this to the date we use in europe to change the time.
In europe it is the last sundy of march and oktober.

I've changed it a bit but I cannot figure out why he sometimes won't get a result.
(see year 2026 - 2039 - 2051)
This cleaned out sketch should just print starting day in march and end in oktober

What am I missing?

#include <Dusk2Dawn2.h>
#include <TimeLib.h>

#include "esp_system.h"
#include "time.h"


void setup() {
  Serial.begin (9600);
  setTime(12, 00, 00, 1, 1, 2020);  //Set time

}


void loop()
{
  calc();
  adjustTime(84600);

}

void calc()
{
  // ********************* Calculate offset for Sunday *********************
  int DST = 0;
  int y = year() - 2000;                // Get year from RTC and subtract 2000
 int x1 = (y + y / 4 + 5) % 7;         // remainder will identify which day of month

  if ((day() == (31 - x1) ) && (month() == 3) && ( hour() >= 2))
  {
    Serial.print("year: " + String (y) + "   month: " + String (month()) + "    day: " + String (day()) + "  X1=" + String(x1) + "    ");
  }
  // ************* Test DST: ENDS on Last Sunday of okt @ 2:00 AM ************
  if (month() == 10 && day() == (30 - x1) && hour() >= 2)
  {
    Serial.println("year: " + String (y) + "   month: " + String (month()) + "   day: " + String (day()) + "  X1=" + String(x1) );
  }
}

resluts are

year: 20   month: 3    day: 29  X1=2    year: 20   month: 10   day: 28  X1=2
year: 21   month: 3    day: 28  X1=3    year: 21   month: 10   day: 27  X1=3
year: 22   month: 3    day: 27  X1=4    year: 22   month: 10   day: 26  X1=4
year: 23   month: 3    day: 26  X1=5    year: 23   month: 10   day: 25  X1=5
year: 24   month: 3    day: 31  X1=0    year: 24   month: 10   day: 30  X1=0
year: 25   month: 3    day: 30  X1=1    year: 25   month: 10   day: 29  X1=1
year: 26                                                            month: 10   day: 28  X1=2
year: 27   month: 3    day: 28  X1=3    year: 27   month: 10   day: 27  X1=3
year: 28   month: 3    day: 26  X1=5    year: 28   month: 10   day: 25  X1=5
year: 29   month: 3    day: 25  X1=6    year: 29   month: 10   day: 24  X1=6
year: 30   month: 3    day: 31  X1=0    year: 30   month: 10   day: 30  X1=0
year: 31   month: 3    day: 30  X1=1    year: 31   month: 10   day: 29  X1=1
year: 32   month: 3    day: 28  X1=3    year: 32   month: 10   day: 27  X1=3
year: 33   month: 3    day: 27  X1=4    year: 33   month: 10   day: 26  X1=4
year: 34   month: 3    day: 26  X1=5    year: 34   month: 10   day: 25  X1=5
year: 35   month: 3    day: 25  X1=6    year: 35   month: 10   day: 24  X1=6
year: 36   month: 3    day: 30  X1=1    year: 36   month: 10   day: 29  X1=1
year: 37   month: 3    day: 29  X1=2    year: 37   month: 10   day: 28  X1=2
year: 38   month: 3    day: 28  X1=3    year: 38   month: 10   day: 27  X1=3
year: 39[                                                           month: 10   day: 26  X1=4
..
year: 49   month: 3    day: 28  X1=3    year: 49   month: 10   day: 27  X1=3
year: 50   month: 3    day: 27  X1=4    year: 51   month: 3    day: 26  X1=5    
year: 51                                             year: 51   month: 10   day: 25  X1=5
year: 52   month: 3    day: 31  X1=0    year: 52   month: 10   day: 30  X1=0
year: 53   month: 3    day: 30  X1=1    year: 53   month: 10   day: 29  X1=1

Here is my code. I made it because I wanted code that was accurate to the second, and I could not find it at that time.
You can try to test it: Het Nederlandstalig Arduino forum - Bekijk onderwerp - klok datum met dag aanduiding.

It is used together with TimeLib and I let the sketch always run at wintertime. Only when I display the time, then I request the isDstEurope(). If true, I add one hour to a temporary time_t time (number of seconds since 1970) and then I derive the date and time from that.

The 'c'-language always had the time, local time, and so on. I think they were not included in the AVR lib. However, they are available now and they can be used. There is also a set_dst() : Arduino/time.h at master · Patapom/Arduino · GitHub.

Are you using a ESP ? Then you should use their time system and see if they have something for the DST. When using NTP to get the time, and with the right settings, you will get the local time correctly.

I use the JChristensen Timezone Library for this kind of thing. But, only ever had application in USA. Is determining DST in Europe that much different or complex?