Go Down

Topic: [Résolu] Mettre mon ds1307 à l'heure (Read 7924 times) previous topic - next topic

Uzuma

Bonsoir,

pardon pour mon absence. Je tenais juste à vous dire merci.

patg_



Je rebondis sur ton changement d'heure été/hiver, je suis super intéressé par l'avancement de ton code.

J'avais commencé à cogiter la dessus, mais par manque de temps je n'ai pas été jusqu'au bout. Bref je pense que je vais m'y remettre rapidement car c'est vraiment super utile.


Pas la peine de chercher il est déjà ici:
Equations by Wei-Hwa Huang (US), and Robert H. van Gent (EC)
Code: [Select]
int 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() == endDSTMonth) && (t.day() <= endDSTDate)))
  return 7200;      // DST europe = utc +2 hour (summer time)
  else return 3600; // nonDST europe = utc +1 hour (winter time)
}



Cette fonction est bugguée: elle ne tient pas compte de l'heure de changement d'heure (l'heure est changée le lendemain).
Voici une implémentation corrigée que je viens juste d'implémenter dans mon horloge chinoise V2. Elle tient compte de l'heure:
Code: [Select]

int 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)
}

Mes Arduineries: http://breizhmakers.over-blog.com/

john_lenfr

Je ne m'en suis pas rendu compte quand l'heure a changé.
Et comme je fais une synchro NTP que tout les jour c'est passé inaperçu pour mon application mais merci pour cette correction, je mets de coté ;)

Go Up