From a4c034611acd6b4323bd3fa35af3578c7be495df Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 23 Nov 2021 19:09:36 +0000 Subject: [PATCH] Fix timezone issues --- src/decoders/decoder.h | 2 +- src/decoders/noaa.h | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/decoders/decoder.h b/src/decoders/decoder.h index 128fc2d..6467eed 100644 --- a/src/decoders/decoder.h +++ b/src/decoders/decoder.h @@ -65,7 +65,7 @@ class Decoder { } std::istream stream(&file); get_filesize(stream); - created = QFileInfo(QString::fromStdString(filename)).birthTime().toSecsSinceEpoch(); + created = QFileInfo(QString::fromStdString(filename)).birthTime().toUTC().toSecsSinceEpoch(); while (is_running && !stream.eof()) { work(stream); diff --git a/src/decoders/noaa.h b/src/decoders/noaa.h index 6403cd8..c6da4f6 100644 --- a/src/decoders/noaa.h +++ b/src/decoders/noaa.h @@ -138,16 +138,9 @@ class NOAADecoder : public Decoder { } // Calculate the timestamp of the start of the year - struct tm* timeinfo = gmtime(&created); - timeinfo->tm_sec = 0; - timeinfo->tm_min = 0; - timeinfo->tm_hour = 0; - timeinfo->tm_mday = 1; - timeinfo->tm_wday = 0; - timeinfo->tm_yday = 0; - timeinfo->tm_mon = 0; - time_t year = mktime(timeinfo) - 86400; - + int _year = QDateTime::fromSecsSinceEpoch(created).date().year(); + double year = QDate(_year, 1, 1).startOfDay(Qt::UTC).toSecsSinceEpoch() - 86400.0; + uint16_t days = repacked[8] >> 1; uint32_t ms = (repacked[9] & 0b1111111) << 20 | repacked[10] << 10 | repacked[11]; double timestamp = (double)year + (double)days*86400.0 + (double)ms/1000.0;