Forum: Mikrocontroller und Digitale Elektronik mktime( 16:00:60 ) -> 17:01:00?


von Karl N. (Gast)


Lesenswert?

Wenn ich zu einer struct tm 60 Sekunden addiere und mktime aufrufe, wird 
auch die Stunde inkrementiert - warum?

    Sat May 22 16:00:00 2021
    tm_sec += 60;
    Sat May 22 16:00:60 2021
    mktime()
    Sat May 22 17:01:00 2021

.platformio\packages\framework-arduinoespressif8266\tools\sdk\libc\xtens 
a-lx106-elf\include\time.h

https://www.cplusplus.com/reference/ctime/mktime/

von Karl N. (Gast)


Lesenswert?


von Jörg W. (dl8dtl) (Moderator) Benutzerseite


Lesenswert?

Mein Manual sagt:

"The functions mktime() and timegm() convert the broken-down time in the 
structure pointed to by tm into a time value with the same encoding as 
that of the values returned by the time(3) function (that is, seconds 
from the Epoch, UTC).[…]

The original values of the tm_wday and tm_yday components of the 
structure are ignored, and the original values of the other components 
are not restricted to their normal ranges, and will be normalized if 
needed. […]"

Das ist also ein Feature.

von Karl N. (Gast)


Lesenswert?

Jörg W. schrieb:
> will be normalized if needed

Das versuche ich ja auszunutzen, allerdings nutzt die Funktion auch die 
lokale Zeitzone, und die ist hier gerade DST - daher kommt die eine 
Stunde Differenz.

Nun sind die auf SO vorgeschlagenen Lösungen (lokale Zeit auf UTC 
stellen, andere Funktionen, Bibliotheken) für Linux.
Ich suche also weiter...

von Karl N. (Gast)


Lesenswert?

setTZ(TZ_Etc_UCT); sollte gehen.

von Karl N. (Gast)


Lesenswert?

Ja, damit bleibt tm_isdst 0 und die Rechnung stimmt.
Tippfehler: TZ_Etc_UTC, ist aber identisch (TZ.h,-> PSTR("UTC0")).

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.