When Teensy Loader uploads some firmware, it also sets the Teensy's clock. The value it's sending is incorrect. It looks like it gets the current system time from the computer and then adds the time zone offset. For example, it's about Wed Feb 4 9:40AM GMT-08:00 now, which corresponds to 1770226800 seconds. However, the Teensy prints 1770198000 seconds. This is exactly 8 hours too short.
In my strong view, the Teensy clock should be set to GMT time, because I'd expect
However, if it is really desired that
In short, I strongly believe
You can play with these numbers at https://epochconverter.com. A screenshot of these values is attached, as well as some source code that prints the current time in seconds since the Epoch.
In my strong view, the Teensy clock should be set to GMT time, because I'd expect
_gettimeofday() to return time in UTC (note: almost the same as GMT) (so sayeth https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html), given that the time zone parameter is obsolete. In other words, don't add the computer's local time zone offset when sending the time from Teensy Loader.However, if it is really desired that
_gettimeofday() returns the local time, with the time zone included (and I disagree with this), then so be it, but I'd like to point out another potential flaw. Say a program has proper time zone knowledge. It then needs to subtract the time zone offset from the system clock, but if this is ever fixed, that code would be wrong.In short, I strongly believe
_gettimeofday() should return the time in UTC and not in local time.You can play with these numbers at https://epochconverter.com. A screenshot of these values is attached, as well as some source code that prints the current time in seconds since the Epoch.
C++:
#include <chrono>
#include <cinttypes>
void setup() {
Serial.begin(115200);
while (!Serial && millis() < 4000) {
// Wait for Serial
}
const auto now = std::chrono::system_clock::now().time_since_epoch();
const auto now_s = std::chrono::duration_cast<std::chrono::seconds>(now);
printf("now = %" PRId64 " s\r\n", now_s.count());
printf("Copy this into https://epochconverter.com and observe"
" the incorrect time zone.\r\n");
printf("Copy into the field and press [Timestamp to Human date].\r\n");
}
void loop() {
// put your main code here, to run repeatedly:
}
Attachments
Last edited: