Fix weird Y2K feature of QTime - Thanks to Kappa

This commit is contained in:
Phil Olynyk 2021-10-09 11:47:45 -04:00
parent 3d05e10db2
commit 3c571e6b88
3 changed files with 19 additions and 8 deletions

View File

@ -591,10 +591,13 @@ bool CMS50Loader::readSpoRFile(QString path)
dchr[j] = 0; dchr[j] = 0;
if (dchr[0]) { if (dchr[0]) {
QString dstr(dchr); QString dstr(dchr);
m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss"); // Ensure date is correct first to ensure DST is handled correctly
if (m_startTime.date().year() < 2000) { QDate date = QDate::fromString(dstr.left(8),"MM/dd/yy");
m_startTime = m_startTime.addYears(100); QTime time = QTime::fromString(dstr.right(8),"HH:mm:ss");
if (date.year() < 2000) {
date = date.addYears(100);
} }
m_startTime = QDateTime(date, time);
} else { } else {
m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0)); m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0));
cms50dplus = true; cms50dplus = true;

View File

@ -923,10 +923,13 @@ bool CMS50F37Loader::readSpoRFile(const QString & path)
dchr[j] = 0; dchr[j] = 0;
if (dchr[0]) { if (dchr[0]) {
QString dstr(dchr); QString dstr(dchr);
m_startTime = QDateTime::fromString(dstr, "MM/dd/yy HH:mm:ss"); // Ensure date is correct first to ensure DST is handled correctly
if (m_startTime.date().year() < 2000) { QDate date = QDate::fromString(dstr.left(8),"MM/dd/yy");
m_startTime = m_startTime.addYears(100); 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 } 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 m_startTime = QDateTime(QDate::currentDate(), QTime(0,0,0)); // make it today at midnight
cms50dplus = true; cms50dplus = true;

View File

@ -196,8 +196,13 @@ bool MD300W1Loader::readDATFile(const QString & path)
QString datestr = QString().sprintf("%02d/%02d/%02d %02d:%02d:%02d", 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+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)); (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"); // Ensure date is correct first to ensure DST is handled correctly
if (datetime.date().year() < 2000) datetime = datetime.addYears(100); 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(); ts = datetime.toTime_t();
gap = ts - lasttime; gap = ts - lasttime;
if (gap > 1) { // always true for first record, b/c time started on 1 Jan 1970 if (gap > 1) { // always true for first record, b/c time started on 1 Jan 1970