Index: sources/view/settings/VDateTime.cpp =================================================================== diff -u -r389f028cb9d4d320eae393de7c4408a58a619356 -r124c2e38e72a1a655d9d479c9c7a1cd8c5d5e6c4 --- sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 389f028cb9d4d320eae393de7c4408a58a619356) +++ sources/view/settings/VDateTime.cpp (.../VDateTime.cpp) (revision 124c2e38e72a1a655d9d479c9c7a1cd8c5d5e6c4) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2021-2023 Diality Inc. - All Rights Reserved. + * Copyright (c) 2021-2025 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file VDateTime.cpp - * \author (last) Behrouz NematiPour - * \date (last) 08-Jun-2022 + * \author (last) Vy + * \date (last) 16-Aug-2023 * \author (original) Behrouz NematiPour * \date (original) 16-Apr-2021 * @@ -30,14 +30,29 @@ ACTION_VIEW_CONNECTION(AdjustHDDateTimeResponseData); ACTION_VIEW_CONNECTION(AdjustDGDateTimeResponseData); + ACTION_VIEW_CONNECTION(HDRTCEpochData); ADJUST_VIEW_CONNECTION( AdjustHDDateTimeRequestData); ADJUST_VIEW_CONNECTION( AdjustDGDateTimeRequestData); connect(&_process, SIGNAL( finished(int)), this, SLOT(onSetDateUIFinished(int))); + + connect(&_process, SIGNAL( errorOccurred(QProcess::ProcessError)), + this, SLOT(onSetDateUIErrored(QProcess::ProcessError))); } /*! + * \brief VDateTime::onSetDateUIErrored + * The slot for when the set datetime script errors, log the error + */ +void VDateTime::onSetDateUIErrored(QProcess::ProcessError error){ + QString mScript = Storage::Scripts_Path_Name(); + mScript += Storage::Date_Time_Set_Sh; + LOG_DEBUG(QString("%1 errored. Error %2").arg(mScript).arg(error)); + //DEBUG: qDebug()<< QString("%1 errored. Error ").arg(mScript) << error; +} + +/*! * \brief VDateTime::doCurrentTime * Reads and displays the current date and time */ @@ -75,32 +90,30 @@ day ( vDay ); hour ( vHour ); minute ( vMinute ); - quint32 epoch = - QDateTime( - QDate(_year .toInt() , - _month .toInt() , - _day .toInt()), - QTime(_hour .toInt() , - _minute .toInt()) - ).toSecsSinceEpoch(); - // the accepted format of the Linux data command: - // example: 2021-03-16 16:24:00 - QString mDateTime = QString("%1-%2-%3 %4:%5:%6") - .arg(_year ) - .arg(_month ) - .arg(_day ) - .arg(_hour ) - .arg(_minute) - .arg(_second); + const QDateTime currentDateTimeLocal ( QDate(_year .toInt() , + _month .toInt() , + _day .toInt()) , + QTime(_hour .toInt() , + _minute .toInt())); + const QString dateTimeLocalStr = currentDateTimeLocal.toString(_Settings.getDatetimeFormat()); - LOG_DEBUG(tr("SetDateTime %1").arg(mDateTime)); + // Get the current UTC datetime + const QDateTime currentDateTimeUTC = currentDateTimeLocal.toUTC(); + const quint32 epochUTC_sec = currentDateTimeUTC.toSecsSinceEpoch(); + LOG_DEBUG(tr("SetDateTime %1").arg(dateTimeLocalStr)); status("Setting date and time ..."); - dateTimeUI(mDateTime); - dateTimeHD(epoch ); - dateTimeDG(epoch ); + dateTimeUI(dateTimeLocalStr ); + dateTimeHD(epochUTC_sec ); + dateTimeDG(epochUTC_sec ); + + //DEBUG: QDateTime convertBack; + //DEBUG: convertBack.setSecsSinceEpoch(epochUTC_sec); + //DEBUG: qDebug()<<"Secs since Epoch" << convertBack.toSecsSinceEpoch() << " UTC: " << convertBack.toUTC().toString(_Settings.getDatetimeFormat()); + + //DEBUG: qDebug() << "doConfirm RTC | epoch : " << epochUTC_sec << " | local: " << currentDateTimeLocal.toString(_Settings.getDatetimeFormat()) << " | current time zone: " << currentDateTimeLocal.timeZone() << " | UTC: " << currentDateTimeUTC.toString(_Settings.getDatetimeFormat()) ; } /*! @@ -247,3 +260,26 @@ quint16 military = _currentDateTime.time().hour() * 100 + _currentDateTime.time().minute(); greeting(military); } + +/*! + * + * \brief VHDPOSTData::onActionReceive + * \details received response model data handler + * \param vData - model data + */ +void VDateTime::onActionReceive(const HDRTCEpochData &vData) +{ + // Doing a single update of the HD-UI RTC sync on start-up + static bool _hasDoneHDSyncRTC = false; + if ( !_hasDoneHDSyncRTC ) { + QDateTime hdRTCTime_localZone; // Default timespec is Qt::localTime / local time zoned + hdRTCTime_localZone.setSecsSinceEpoch(vData.mEpoch); + + const QString newDateTimeString = hdRTCTime_localZone.toString(_Settings.getDatetimeFormat()); + dateTimeUI(newDateTimeString); + + _hasDoneHDSyncRTC = true; // indicate HD-UI RTC sync'd + + //DEBUG: qDebug() << "Sync HD->UI RTC | HD Epoch: " << vData.mEpoch << " | HD datetime (local zone): " << hdRTCTime_localZone.toString(_Settings.getDatetimeFormat()) <<" | local datetime : " << newDateTimeString; + } +}