Daylight savings problem


#21

Hi all,

I am newbie from Belgium to this forum and wanted to share this piece of code I used for a few years to solve this issue on a particle core.
I didn’t find how to post code in a nice gray background so forgive me posting it as plain text.

The original formula is from the following site :

http://delphiforfun.org/programs/math_topics/dstcalc.htm
in my application it changes the setting on midnight, so not on 2 or 3 .

//zomert is a bool, false when wintertime is active and true when summertime is active 

  switch (zomert)   // check summer / winter time
 { 
  case false: // if current setting is winter
    if ( ((Time.day() >= (31-(((5*Time.year()/4)+4)%7))) and (Time.month() == 3 )) or ((Time.month() < 10) and (Time.month() > 3)) )
   {
     // summer time
     zomert = true;
     zoneUTC=2;
     Time.zone(+2);
     Particle.syncTime();
     delay(2000);
   }
   break;
   
   case true: // if current setting is summer
    if ( ((Time.day() >= (31-(((5*Time.year()/4)+1)%7))) and (Time.month() == 10 )) or ((Time.month() < 3) or (Time.month() > 10)))
    {
      // winter time
      zomert = false;
      zoneUTC=1;
      Time.zone(+1);
      Particle.syncTime();
      delay(2000);
    }
   break;    
 }

regards,
Ronny


#22

I have reformatted your code block.
To achieve the same thing you can use this icon image or you use the edit option (image ) on your own post and see what I added before and after your code to achive the same thing (with the extra formatting hint cpp).


#23

Ronny

There are fully working and tested functions above in this topic thread which you could also use/study and that use the Time.isDST() and Time.beginDST() rather than move the Timezone!
What help are you after?


#24

Hi Armor,
I will look at the functions above, i don’t have a specific problem, I just wanted to share my code that I’ve been using for a few years to tackle the daylight saving problem
Kind regards


#25

Thanks ScruffR for the explanation and the edit, will do it that way next time😉