Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Fix timezone issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerbo committed Nov 23, 2021
1 parent 987d36c commit a4c0346
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/decoders/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 3 additions & 10 deletions src/decoders/noaa.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a4c0346

Please sign in to comment.