Salut a tous je sais que ce sujet est déjà sorti sur le forum , mais il c'est arrêter en route donc j'aimerais le reprendre car j'ai aussi un problème avec le changement automatique d’heure été / hiver donc si quelqu'un a la bonté de m'aider
J'utilise la fonction ci-dessous dont je n'arrive plus à retrouver la source ici. Elle m'avait été donné quand j'avais évoqué le sujet.
Elle prend en entrée un DateTime issu de la lib RTCLib pour DS1307.
L'heure dans le DS1307 est toujours en UTC et cette fonction retourne le nombre de secondes à y ajouter pour avoir l'heure locale.
J'utilise ça dans mes horloges, et c'est vraiment très pratique.
uint16_t adjustDstEurope(DateTime t)
{
/*You can use the following equations to calculate when DST starts and ends.
The divisions are integer divisions, in which remainders are discarded.
"mod" means the remainder when doing integer division, e.g., 20 mod 7 = 6.
That is, 20 divided by 7 is 2 and 6/7th (where six is the remainder).
With: y = year.
For the United States:
Begin DST: Sunday April (2+6*y-y/4) mod 7+1
End DST: Sunday October (31-(y*5/4+1) mod 7)
Valid for years 1900 to 2006, though DST wasn't adopted until the 1950s-1960s. 2007 and after:
Begin DST: Sunday March 14 - (1 + y*5/4) mod 7
End DST: Sunday November 7 - (1 + y*5/4) mod 7;
European Economic Community:
Begin DST: Sunday March (31 - (5*y/4 + 4) mod 7) at 1h U.T.
End DST: Sunday October (31 - (5*y/4 + 1) mod 7) at 1h U.T.
Since 1996, valid through 2099
(Equations by Wei-Hwa Huang (US), and Robert H. van Gent (EC))
Adjustig Time with DST Europe/France/Paris: UTC+1h in winter, UTC+2h in summer
*/
// last sunday of march
int beginDSTDate= (31 - (5* t.year() /4 + 4) % 7);
//Serial.println(beginDSTDate);
int beginDSTMonth=3;
//last sunday of october
int endDSTDate= (31 - (5 * t.year() /4 + 1) % 7);
//Serial.println(endDSTDate);
int endDSTMonth=10;
// DST is valid as:
if (((t.month() > beginDSTMonth) && (t.month() < endDSTMonth))
|| ((t.month() == beginDSTMonth) && (t.day() > beginDSTDate))
|| ((t.month() == beginDSTMonth) && (t.day() == beginDSTDate) && (t.hour() >= 1))
|| ((t.month() == endDSTMonth) && (t.day() < endDSTDate))
|| ((t.month() == endDSTMonth) && (t.day() == endDSTDate) && (t.hour() < 1)))
return 7200; // DST europe = utc +2 hour (summer time)
else return 3600; // nonDST europe = utc +1 hour (winter time)
}