From 3c571e6b882dccf56a6df6d4070469430dca5d87 Mon Sep 17 00:00:00 2001 From: Phil Olynyk Date: Sat, 9 Oct 2021 11:47:45 -0400 Subject: [PATCH] Fix weird Y2K feature of QTime - Thanks to Kappa --- oscar/SleepLib/loader_plugins/cms50_loader.cpp | 9 ++++++--- oscar/SleepLib/loader_plugins/cms50f37_loader.cpp | 9 ++++++--- oscar/SleepLib/loader_plugins/md300w1_loader.cpp | 9 +++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/oscar/SleepLib/loader_plugins/cms50_loader.cpp b/oscar/SleepLib/loader_plugins/cms50_loader.cpp index b7b89888..c5e1964f 100644 --- a/oscar/SleepLib/loader_plugins/cms50_loader.cpp +++ b/oscar/SleepLib/loader_plugins/cms50_loader.cpp @@ -591,10 +591,13 @@ bool CMS50Loader::readSpoRFile(QString path) dchr[j] = 0; if (dchr[0]) { QString dstr(dchr); - m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss"); - if (m_startTime.date().year() < 2000) { - m_startTime = m_startTime.addYears(100); + // Ensure date is correct first to ensure DST is handled correctly + QDate date = QDate::fromString(dstr.left(8),"MM/dd/yy"); + QTime time = QTime::fromString(dstr.right(8),"HH:mm:ss"); + if (date.year() < 2000) { + date = date.addYears(100); } + m_startTime = QDateTime(date, time); } else { m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0)); cms50dplus = true; diff --git a/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp b/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp index fa88bc38..e69e2a4c 100644 --- a/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp +++ b/oscar/SleepLib/loader_plugins/cms50f37_loader.cpp @@ -923,10 +923,13 @@ bool CMS50F37Loader::readSpoRFile(const QString & path) dchr[j] = 0; if (dchr[0]) { QString dstr(dchr); - m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss"); - if (m_startTime.date().year() < 2000) { - m_startTime = m_startTime.addYears(100); + // Ensure date is correct first to ensure DST is handled correctly + QDate date = QDate::fromString(dstr.left(8),"MM/dd/yy"); + QTime time = QTime::fromString(dstr.right(8),"HH:mm:ss"); + if (date.year() < 2000) { + date = date.addYears(100); } + m_startTime = QDateTime(date, time); } else { // this should probaly find the most recent SH data day m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0)); // make it today at midnight cms50dplus = true; diff --git a/oscar/SleepLib/loader_plugins/md300w1_loader.cpp b/oscar/SleepLib/loader_plugins/md300w1_loader.cpp index 1161e247..2f385514 100644 --- a/oscar/SleepLib/loader_plugins/md300w1_loader.cpp +++ b/oscar/SleepLib/loader_plugins/md300w1_loader.cpp @@ -196,8 +196,13 @@ bool MD300W1Loader::readDATFile(const QString & path) QString datestr = QString().sprintf("%02d/%02d/%02d %02d:%02d:%02d", (unsigned char)data.at(i+4),(unsigned char)data.at(i+5),(unsigned char)data.at(i+3), (unsigned char)data.at(i+6),(unsigned char)data.at(i+7),(unsigned char)data.at(i+8)); - QDateTime datetime = QDateTime::fromString(datestr,"MM/dd/yy HH:mm:ss"); - if (datetime.date().year() < 2000) datetime = datetime.addYears(100); + // Ensure date is correct first to ensure DST is handled correctly + QDate date = QDate::fromString(datestr.left(8),"MM/dd/yy"); + QTime time = QTime::fromString(datestr.right(8),"HH:mm:ss"); + if (date.year() < 2000) { + date = date.addYears(100); + } + QDateTime datetime = QDateTime(date, time); ts = datetime.toTime_t(); gap = ts - lasttime; if (gap > 1) { // always true for first record, b/c time started on 1 Jan 1970