Browse Source

Added formatting to Time

Application-wide formatting for time strings
Felix Turowsky 1 year ago
parent
commit
98d5a0442c

+ 3 - 3
src/classes/styledtimedelegate.cpp

@@ -1,12 +1,12 @@
 #include "styledtimedelegate.h"
 #include "src/classes/time.h"
 
-StyledTimeDelegate::StyledTimeDelegate(QObject *parent)
-    : QStyledItemDelegate{parent}
+StyledTimeDelegate::StyledTimeDelegate(const OPL::DateTimeFormat &format, QObject *parent)
+    : QStyledItemDelegate{parent}, m_format(format)
 {}
 
 QString StyledTimeDelegate::displayText(const QVariant &value, const QLocale &locale) const
 {
-    const OPL::Time time(value.toInt());
+    const OPL::Time time(value.toInt(), m_format);
     return time.toString();
 }

+ 4 - 1
src/classes/styledtimedelegate.h

@@ -1,6 +1,7 @@
 #ifndef STYLEDTIMEDELEGATE_H
 #define STYLEDTIMEDELEGATE_H
 
+#include "src/opl.h"
 #include <QStyledItemDelegate>
 
 /*!
@@ -11,9 +12,11 @@
 class StyledTimeDelegate : public QStyledItemDelegate
 {
 public:
-    explicit StyledTimeDelegate(QObject *parent = nullptr);
+    explicit StyledTimeDelegate(const OPL::DateTimeFormat &format, QObject *parent = nullptr);
 
     QString displayText(const QVariant &value, const QLocale &locale) const override;
+private:
+    OPL::DateTimeFormat m_format;
 };
 
 #endif // STYLEDTIMEDELEGATE_H

+ 61 - 30
src/classes/time.cpp

@@ -1,20 +1,47 @@
 #include "time.h"
+#include "math.h"
 
 namespace OPL {
 
-Time::Time()
+Time::Time(const DateTimeFormat &format)
+    : m_format(format),
+    m_minutes(-1)
+{}
+
+Time::Time(const QTime &qTime, const DateTimeFormat &format)
 {
+    m_minutes = qTime.isValid() ? qTime.minute() + qTime.hour() * 60 : -1;
 }
 
+Time::Time(int32_t minutes, const DateTimeFormat &format)
+    : m_minutes(minutes), m_format(format)
+{}
+
 bool Time::isValidTimeOfDay() const
 {
-    return m_minutes <= MINUTES_PER_DAY;
+    return isValid() && m_minutes <= MINUTES_PER_DAY;
+}
+
+bool Time::isValid() const
+{
+    return m_minutes >= 0;
 }
 
 const QString Time::toString() const
 {
-    // convert to hh:mm
-    return QString::number(m_minutes / 60).rightJustified(2, '0') + QLatin1Char(':') + QString::number(m_minutes % 60).rightJustified(2, '0');
+    switch(m_format.timeFormat()) {
+    case DateTimeFormat::TimeFormat::Default:
+        return QString::number(m_minutes / 60).rightJustified(2, '0')
+               + ':'
+               + QString::number(m_minutes % 60).rightJustified(2, '0');
+    case DateTimeFormat::TimeFormat::Decimal:
+        return QString::number(m_minutes / 60.0, 'f', 2);
+        break;
+    case DateTimeFormat::TimeFormat::Custom:
+        return QTime(0, m_minutes, 0).toString(m_format.timeFormatString());
+    default:
+        return QString();
+    }
 }
 
 int32_t Time::toMinutes() const
@@ -22,34 +49,38 @@ int32_t Time::toMinutes() const
     return m_minutes;
 }
 
-int Time::toMinutes(TimeFrame timeFrame, int count)
+Time Time::fromString(const QString &timeString, const DateTimeFormat &format)
 {
-    switch (timeFrame) {
-    case Day:
-        return count * MINUTES_PER_DAY;
-    case Week:
-        return count * 7 * MINUTES_PER_DAY;
-    case Year:
-        return count * 7 * 52 * MINUTES_PER_DAY;
-    default:
-        return 0;
+    switch(format.timeFormat()) {
+    case DateTimeFormat::TimeFormat::Default:
+    {
+        const auto qTime = QTime::fromString(timeString, QStringLiteral("hh:mm"));
+        return Time(qTime, format);
+        break;
     }
-}
-
-Time Time::fromString(const QString &timeString)
-{
-    const QStringList parts = timeString.split(QChar(':'));
-    if(parts.size() < 2)
-        return {};
+    case DateTimeFormat::TimeFormat::Decimal:
+    {
+        // try to convert string to double
+        bool ok = false;
+        const double timeValue = timeString.toDouble(&ok);
 
+        if(!ok) {
+            return {-1, format};
+        }
 
-    int32_t hours = parts[0].toInt();
-    int32_t minutes = parts[1].toInt();
+        // extract integer and fractional part
+        double hours, minutes;
+        hours = modf(timeValue, &minutes);
 
-    if(hours < 0 || minutes < 0)
-        return{};
-
-    return Time(hours * 60 + minutes);
+        // create the Time Object
+        return(Time(hours * 60 + minutes, format));
+        break;
+    }
+    case DateTimeFormat::TimeFormat::Custom:
+        const auto qTime = QTime::fromString(timeString, format.timeFormatString());
+        return Time(qTime, format);
+        break;
+    }
 }
 
 Time Time::blockTime(const Time &offBlocks, const Time &onBlocks)
@@ -57,16 +88,16 @@ Time Time::blockTime(const Time &offBlocks, const Time &onBlocks)
     // make sure both times are in 24h range
     bool bothTimesAreValid = offBlocks.isValidTimeOfDay() && onBlocks.isValidTimeOfDay();
     if(!bothTimesAreValid)
-        return {};
+        return {-1, offBlocks.m_format};
 
     // calculate the block time
     if(onBlocks.m_minutes > offBlocks.m_minutes) {
         // take-off and landing on the same day
-        return Time(onBlocks.m_minutes - offBlocks.m_minutes);
+        return Time(onBlocks.m_minutes - offBlocks.m_minutes, offBlocks.m_format);
     } else {
         // landing the day after take off
         int minutesToMidnight = MINUTES_PER_DAY - offBlocks.m_minutes;
-        return Time(minutesToMidnight + onBlocks.m_minutes);
+        return Time(minutesToMidnight + onBlocks.m_minutes, offBlocks.m_format);
     }
 }
 

+ 51 - 22
src/classes/time.h

@@ -1,6 +1,7 @@
 #ifndef TIME_H
 #define TIME_H
 
+#include "src/opl.h"
 #include <QtCore>
 namespace OPL {
 
@@ -8,18 +9,15 @@ namespace OPL {
  * \brief The Time class handles conversions between user input / user-facing time data display and
  * database format.
  * \details Time data in the database is stored as an integer value of minutes, whereas the user-facing
- * time data is normally displayed in the Qt::ISODATE format. A database value of 72 would for example be
- * displayed as 01:12 (1 hour and 12 minutes).
+ * time data is normally displayed in accordance with the selected DateTimeFormat, by default "hh:mm".
  */
 class Time
 {
-private:
-    const static inline int MINUTES_PER_DAY = 24 * 60;
-    int32_t m_minutes = 0;
-
 public:
-    Time();
-    Time(int32_t minutes) : m_minutes(minutes) {};
+    Time() = delete;
+    Time(const DateTimeFormat &format);
+    Time(const QTime &qTime, const DateTimeFormat &format);
+    Time(int32_t minutes, const DateTimeFormat &format);;
 
     enum TimeFrame {Day, Week, Year};
 
@@ -29,6 +27,11 @@ public:
      */
     bool isValidTimeOfDay() const;
 
+    /*!
+     * \brief a time is considered valid if it has a time value of >= 0
+     */
+    bool isValid() const;
+
     /**
      * @brief toString returns the time as hh:mm
      */
@@ -39,29 +42,55 @@ public:
      */
     int32_t toMinutes() const;
 
-    /*!
-     * \brief toMinutes returns the number of minutes in the given time frame
-     * \param count - The number of time frames (e.g. '7' days)
-     * \return
-     */
-    static int toMinutes(TimeFrame timeFrame, int count);
-
     /**
      * @brief fromString create a Time Object from a String formatted as hh:mm
      * @param timeString the input string
      * @return the Time Object corresponding to the string, equivalent to 0 minutes if conversion fails.
      */
-    static Time fromString(const QString& timeString);
+    static Time fromString(const QString& timeString, const DateTimeFormat &format);
 
-    /**
-     * @brief timeDifference returns the time difference between this time and another time object.
-     * @param other - The other time object
-     * @return the number of minutes of time difference, or 0 if one of the two objects is greater than 24h
+    /*!
+     * \brief Calculate the elapsed time between two events
+     * \param offBlocks - The start tmie
+     * \param onBlocks - the end time
+     * \return The elapsed time
      */
-    int32_t timeElapsed(const Time &other);
-
     static Time blockTime(const Time &offBlocks, const Time& onBlocks);
+
+    /*!
+     * \brief Calculate elapsed time between two events
+     * \param offBlocks - The start time
+     * \param onBlocks - The end time
+     * \return the elapsed time in minutes
+     */
     static int32_t blockMinutes(const Time &offBlocks, const Time& onBlocks);
+
+    /*!
+     * \brief toMinutes returns the number of minutes in the given time frame
+     * \param count - The number of time frames (e.g. '7' days)
+     * \return
+     */
+    static constexpr int timeFrameToMinutes(TimeFrame timeFrame, int count) {
+        switch (timeFrame) {
+        case Day:
+            return count * MINUTES_PER_DAY;
+        case Week:
+            return count * 7 * MINUTES_PER_DAY;
+        case Year:
+            return count * 7 * 52 * MINUTES_PER_DAY;
+        default:
+            return 0;
+        }
+    }
+
+
+private:
+    static constexpr int MINUTES_PER_DAY = 24 * 60;
+    static constexpr QLatin1Char DECIMAL_SEPERATOR = QLatin1Char('.');
+
+    DateTimeFormat m_format;
+    int32_t m_minutes;
+
 };
 
 }// namespace OPL

+ 0 - 2
src/database/currencyentry.h

@@ -46,8 +46,6 @@ public:
     void setExpiryDate(const OPL::Date &date);
     const OPL::Date getExpiryDate(const OPL::DateTimeFormat &format) const;
 
-
-
 private:
 
     /*!

+ 7 - 6
src/database/flightentry.cpp

@@ -40,19 +40,20 @@ const QString FlightEntry::getTableName() const
 
 const QString FlightEntry::getFlightSummary() const
 {
+    using namespace OPL;
     if(!isValid())
         return QString();
 
     auto tableData = getData();
     QString flight_summary;
-    auto space = QLatin1Char(' ');
-    flight_summary.append(OPL::Date(tableData.value(OPL::FlightEntry::DOFT).toInt(), DateTimeFormat()).toString() + space);
-    flight_summary.append(tableData.value(OPL::FlightEntry::DEPT).toString() + space);
-    flight_summary.append(OPL::Time(tableData.value(OPL::FlightEntry::TOFB).toInt()).toString()
+    const auto space = QLatin1Char(' ');
+    flight_summary.append(Date(tableData.value(FlightEntry::DOFT).toInt(), DateTimeFormat()).toString() + space);
+    flight_summary.append(tableData.value(FlightEntry::DEPT).toString() + space);
+    flight_summary.append(Time(tableData.value(FlightEntry::TOFB).toInt(), DateTimeFormat()).toString()
                           + space);
-    flight_summary.append(OPL::Time(tableData.value(OPL::FlightEntry::TONB).toInt()).toString()
+    flight_summary.append(Time(tableData.value(FlightEntry::TONB).toInt(), DateTimeFormat()).toString()
                           + space);
-    flight_summary.append(tableData.value(OPL::FlightEntry::DEST).toString());
+    flight_summary.append(tableData.value(FlightEntry::DEST).toString());
 
     return flight_summary;
 }

+ 6 - 6
src/functions/calc.h

@@ -144,8 +144,8 @@ struct NightTimeValues{
     {
         nightMinutes = calculateNightTime(dept, dest, departure_time, block_minutes, night_angle);
 
-        nightTime = OPL::Time(nightMinutes);
-        totalTime = OPL::Time(block_minutes);
+        OPL::Time nightTime = OPL::Time(nightMinutes, DateTimeFormat());
+        OPL::Time totalTime = OPL::Time(block_minutes, DateTimeFormat());
 
         if (nightMinutes == 0) { // all day
             takeOffNight = false;
@@ -167,13 +167,13 @@ struct NightTimeValues{
 
     };
 
-    NightTimeValues(bool to_night, bool ldg_night, int night_minutes, OPL::Time night_time, OPL::Time total_time)
-        : takeOffNight(to_night), landingNight(ldg_night), nightMinutes(night_minutes), nightTime(night_time), totalTime(total_time){};
+//    NightTimeValues(bool to_night, bool ldg_night, int night_minutes, OPL::Time night_time, OPL::Time total_time)
+//        : takeOffNight(to_night), landingNight(ldg_night), nightMinutes(night_minutes), nightTime(night_time), totalTime(total_time){};
     bool takeOffNight;
     bool landingNight;
     int nightMinutes;
-    OPL::Time nightTime;
-    OPL::Time totalTime;
+//    OPL::Time nightTime;
+//    OPL::Time totalTime;
 
     inline bool isAllDay()      {return (!takeOffNight  && !landingNight);}
     inline bool isAllNight()    {return ( takeOffNight  &&  landingNight);}

+ 7 - 0
src/functions/datetime.h

@@ -1,10 +1,17 @@
 #ifndef DATETIME_H
 #define DATETIME_H
 #include "src/opl.h"
+#include "src/classes/date.h"
+#include "src/classes/time.h"
 
 namespace OPL {
 
 class DateTime {
+
+public:
+//    DateTime(const OPL::Date date, const OPL::Time &time);
+
+
 public:
     const inline static QString ISO_FORMAT_STRING = QStringLiteral("yyyy-MM-dd");
     const inline static QString DE_FORMAT_STRING = QStringLiteral("dd.MM.yyyy");

+ 6 - 6
src/gui/dialogues/newflightdialog.cpp

@@ -213,8 +213,8 @@ void NewFlightDialog::fillWithEntryData()
     ui->deptLocationLineEdit->setText(flight_data.value(OPL::FlightEntry::DEPT).toString());
     ui->destLocationLineEdit->setText(flight_data.value(OPL::FlightEntry::DEST).toString());
     // Times
-    ui->tofbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TOFB).toInt()).toString());
-    ui->tonbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TONB).toInt()).toString());
+    ui->tofbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TOFB).toInt(), m_format).toString());
+    ui->tonbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::FlightEntry::TONB).toInt(), m_format).toString());
     ui->acftLineEdit->setText(DBCache->getTailsMap().value(flight_data.value(OPL::FlightEntry::ACFT).toInt()));
     ui->picNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::FlightEntry::PIC).toInt()));
     ui->sicNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::FlightEntry::SECONDPILOT).toInt()));
@@ -277,8 +277,8 @@ void NewFlightDialog::onGoodInputReceived(QLineEdit *line_edit)
         validationState.validate(mandatoryLineEdits->indexOf(line_edit));
 
     if (validationState.timesValid()) {
-        const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
-        const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
+        const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text(), m_format);
+        const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text(), m_format);
         const OPL::Time tblk = OPL::Time::blockTime(tofb, tonb);
         ui->tblkDisplayLabel->setText(tblk.toString());
     }
@@ -396,8 +396,8 @@ OPL::RowData_T NewFlightDialog::prepareFlightEntryData()
     OPL::RowData_T new_data;
 
     // Calculate Block and Night Time
-    const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
-    const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
+    const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text(), m_format);
+    const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text(), m_format);
     const int block_minutes = OPL::Time::blockMinutes(tofb, tonb);
 
     QDateTime departure_date_time = OPL::DateTime::fromString(ui->doftLineEdit->text() + ui->tofbTimeLineEdit->text());

+ 3 - 3
src/gui/dialogues/newsimdialog.cpp

@@ -58,7 +58,7 @@ void NewSimDialog::fillEntryData()
 {
     const auto& data = entry.getData();
     ui->dateLineEdit->setText(OPL::Date(data.value(OPL::SimulatorEntry::DATE).toInt(), m_format).toString());
-    ui->totalTimeLineEdit->setText(OPL::Time(data.value(OPL::SimulatorEntry::TIME).toInt()).toString());
+    ui->totalTimeLineEdit->setText(OPL::Time(data.value(OPL::SimulatorEntry::TIME).toInt(), m_format).toString());
     ui->deviceTypeComboBox->setCurrentIndex(data.value(OPL::SimulatorEntry::TYPE).toInt());
     ui->aircraftTypeLineEdit->setText(data.value(OPL::SimulatorEntry::ACFT).toString());
     ui->registrationLineEdit->setText(data.value(OPL::SimulatorEntry::REG).toString());
@@ -133,7 +133,7 @@ bool NewSimDialog::verifyInput(QString& error_msg)
     if(!TimeInput(ui->totalTimeLineEdit->text()).isValid())
         return false;
 
-    const OPL::Time time = OPL::Time::fromString(ui->totalTimeLineEdit->text());
+    const OPL::Time time = OPL::Time::fromString(ui->totalTimeLineEdit->text(), m_format);
 
     if (!time.isValidTimeOfDay()) {
         ui->totalTimeLineEdit->setStyleSheet(OPL::CssStyles::RED_BORDER);
@@ -159,7 +159,7 @@ OPL::RowData_T NewSimDialog::collectInput()
     const auto date = OPL::Date(ui->dateLineEdit->text(), m_format);
     new_entry.insert(OPL::SimulatorEntry::DATE, date.toJulianDay());
     // Time
-    new_entry.insert(OPL::SimulatorEntry::TIME, OPL::Time::fromString(ui->totalTimeLineEdit->text()).toMinutes());
+    new_entry.insert(OPL::SimulatorEntry::TIME, OPL::Time::fromString(ui->totalTimeLineEdit->text(), m_format).toMinutes());
     // Device Type
     new_entry.insert(OPL::SimulatorEntry::TYPE, ui->deviceTypeComboBox->currentText());
     // Aircraft Type

+ 3 - 3
src/gui/widgets/currencywidget.cpp

@@ -16,7 +16,7 @@
 CurrencyWidget::CurrencyWidget(QWidget *parent)
     : QWidget{parent}
 {
-    dateFormat = QStringLiteral("yyyy-MM-dd"); // TODO implement date formats
+    m_format = Settings::getDisplayFormat();
     setupModelAndView();
     setupUI();
 
@@ -159,7 +159,7 @@ void CurrencyWidget::fillFlightTimeLimitations()
     for (const auto &pair : limits) {
         int accruedMinutes = OPL::Statistics::totalTime(pair.second);
         int limitMinutes = EasaFTL::getLimit(pair.second);
-        pair.first->setText(OPL::Time(accruedMinutes).toString());
+        pair.first->setText(OPL::Time(accruedMinutes, m_format).toString());
 
 
         if (accruedMinutes >= limitMinutes)
@@ -212,7 +212,7 @@ void CurrencyWidget::displayNameEditRequested(const QModelIndex &index)
 void CurrencyWidget::expiryDateEditRequested(const QModelIndex &index)
 {
     const QString selection = index.data().toString();
-    const QDate selectedDate = QDate::fromString(selection, dateFormat);
+    const QDate selectedDate = QDate::fromString(selection, Qt::ISODate);
     if(selectedDate.isValid()) {
         const QSignalBlocker blocker(calendar);
         calendar->setSelectedDate(selectedDate);

+ 2 - 1
src/gui/widgets/currencywidget.h

@@ -1,6 +1,7 @@
 #ifndef CURRENCYWIDGET_H
 #define CURRENCYWIDGET_H
 
+#include "src/opl.h"
 #include <QWidget>
 #include <QCalendarWidget>
 #include <QTableView>
@@ -13,8 +14,8 @@ class CurrencyWidget : public QWidget
     QTableView *view;
     QSqlTableModel *model;
     QCalendarWidget *calendar;
-    QString dateFormat;
     QModelIndex lastSelection;
+    OPL::DateTimeFormat m_format;
 
     int ROWID_COLUMN = 0;
     int CURRENCY_NAME_COLUMN = 1;

+ 2 - 5
src/gui/widgets/logbooktableeditwidget.cpp

@@ -48,6 +48,7 @@ void LogbookTableEditWidget::setupUI()
     m_deleteEntryPushButton->setText(tr("Delete selected Entry"));
     m_filterWidget->hide();
     m_stackedWidget->hide();
+    m_format = Settings::getDisplayFormat();
 }
 
 QString LogbookTableEditWidget::deleteErrorString(int rowId)
@@ -140,10 +141,6 @@ void LogbookTableEditWidget::deleteEntryRequested()
                 WARN(deleteErrorString(rowId));
         }
     }
-
-    // re-set stackedWidget for Vertical Layout
-//    m_stackedWidget->setCurrentWidget(m_filterWidget);
-//    m_stackedWidget->show();
 }
 
 // private implementations
@@ -151,7 +148,7 @@ void LogbookTableEditWidget::deleteEntryRequested()
 void LogbookTableEditWidget::setupDelegates()
 {
     // minutes to hh:mm
-    const auto timeDelegate = new StyledTimeDelegate(m_model);
+    const auto timeDelegate = new StyledTimeDelegate(m_format, m_model);
     m_view->setItemDelegateForColumn(-1, timeDelegate); // shut up ctidy
     for(const auto col : OPL::LogbookViewInfo::getTimeColumns(m_logbookView)) {
         m_view->setItemDelegateForColumn(col, timeDelegate);

+ 1 - 0
src/gui/widgets/logbooktableeditwidget.h

@@ -27,6 +27,7 @@ public:
 
 private:
     OPL::LogbookView m_logbookView;
+    OPL::DateTimeFormat m_format;
 
     /*!
      * \brief Set up the QStyledItemDelegate instances that transform the database values to user-readable values.

+ 4 - 4
src/gui/widgets/logbookwidget.cpp

@@ -102,10 +102,10 @@ const QString LogbookWidget::getFlightSummary(const OPL::FlightEntry &flight) co
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::FlightEntry::DOFT).toString() + space);
     flight_summary.append(tableData.value(OPL::FlightEntry::DEPT).toString() + space);
-    flight_summary.append(OPL::Time(tableData.value(OPL::FlightEntry::TOFB).toInt()).toString()
-                          + space);
-    flight_summary.append(OPL::Time(tableData.value(OPL::FlightEntry::TONB).toInt()).toString()
-                          + space);
+//    flight_summary.append(OPL::Time(tableData.value(OPL::FlightEntry::TOFB).toInt()).toString()
+//                          + space);
+//    flight_summary.append(OPL::Time(tableData.value(OPL::FlightEntry::TONB).toInt()).toString()
+//                          + space);
     flight_summary.append(tableData.value(OPL::FlightEntry::DEST).toString());
 
     return flight_summary;

+ 5 - 3
src/gui/widgets/totalswidget.cpp

@@ -22,6 +22,7 @@
 #include "src/opl.h"
 #include "src/classes/time.h"
 #include "ui_totalswidget.h"
+#include "src/classes/settings.h"
 
 TotalsWidget::TotalsWidget(WidgetType widgetType, QWidget *parent) :
     QWidget(parent),
@@ -43,6 +44,7 @@ TotalsWidget::~TotalsWidget()
  */
 void TotalsWidget::setup(const WidgetType widgetType)
 {
+    m_format = Settings::getDisplayFormat();
     const QList<QLineEdit *> lineEdits = this->findChildren<QLineEdit *>();
 
     switch (widgetType) {
@@ -106,7 +108,7 @@ void TotalsWidget::fillTotals(const WidgetType widgetType)
                 line_edit->setText(field.toString());
             } else {
                 // line edits for total time
-                OPL::Time time = OPL::Time(field.toInt());// = Time(field.toInt());
+                OPL::Time time = OPL::Time(field.toInt(), m_format);// = Time(field.toInt());
                 line_edit->setText(time.toString());
             }
         }
@@ -171,7 +173,7 @@ void TotalsWidget::timeLineEditEditingFinished()
 
     // write the updated value to the database
     const QString db_field = line_edit->objectName().remove(QLatin1String("LineEdit"));
-    const QVariant value = OPL::Time::fromString(line_edit->text()).toMinutes();
+    const QVariant value = OPL::Time::fromString(line_edit->text(), m_format).toMinutes();
 
     m_rowData.insert(db_field, value);
     LOG << "Added row data: " + db_field + ": " + value.toString();
@@ -181,7 +183,7 @@ void TotalsWidget::timeLineEditEditingFinished()
 
     // Read back the value and set the line edit to confirm input is correct and provide user feedback
     m_rowData = DB->getRowData(OPL::DbTable::PreviousExperience, ROW_ID);
-    OPL::Time new_time = OPL::Time(m_rowData.value(db_field).toInt());
+    OPL::Time new_time = OPL::Time(m_rowData.value(db_field).toInt(), m_format);
     line_edit->setText(new_time.toString());
 }
 

+ 2 - 0
src/gui/widgets/totalswidget.h

@@ -48,6 +48,8 @@ private:
     /*!
      * \brief ROW_ID the row ID for previous experience entries (1)
      */
+
+    OPL::DateTimeFormat m_format;
     const static int ROW_ID = 1;
     void fillTotals(const WidgetType widgetType);
     void setup(const WidgetType widgetType);

+ 4 - 3
src/opl.h

@@ -148,17 +148,18 @@ struct DateTimeFormat {
         m_dateFormatString(QStringLiteral("yyyy-MM-dd")),
         m_timeFormat(TimeFormat::Default),
         m_timeFormatString(QStringLiteral("hh:mm"))
-        {}
+    {}
 
     DateTimeFormat(DateFormat dateFormat_,
                    const QString &dateFormatString_,
                    TimeFormat timeFormat_,
                    const QString &timeFormatString_)
         :
-            m_dateFormat(dateFormat_),
+        m_dateFormat(dateFormat_),
         m_dateFormatString(dateFormatString_),
         m_timeFormat(timeFormat_),
-            m_timeFormatString(timeFormatString_) {}
+        m_timeFormatString(timeFormatString_)
+    {}
 
 
 public:

+ 2 - 2
src/testing/importCrewlounge/processflights.cpp

@@ -54,14 +54,14 @@ void ProcessFlights::processParsedData()
         auto time_off = QTime::fromString(row[4], QStringLiteral("hh:mm"));
         if (!time_off.isValid())
             time_off = QTime::fromString(row[4], QStringLiteral("h:mm"));
-        int tofb = OPL::Time::fromString(time_off.toString()).toMinutes();
+        int tofb = OPL::Time::fromString(time_off.toString(), OPL::DateTimeFormat()).toMinutes();
         new_flight_data.insert(OPL::FlightEntry::TOFB, tofb);
 
         auto time_on = QTime::fromString(row[5], QStringLiteral("hh:mm"));
         if (!time_on.isValid())
             time_on = QTime::fromString(row[5], QStringLiteral("h:mm"));
 
-        int tonb = OPL::Time::fromString(time_on.toString()).toMinutes();
+        int tonb = OPL::Time::fromString(time_on.toString(), OPL::DateTimeFormat()).toMinutes();
         new_flight_data.insert(OPL::FlightEntry::TONB, tonb);
 
         // map pilots

+ 2 - 2
src/testing/randomgenerator.cpp

@@ -19,8 +19,8 @@ const FlightEntry RandomGenerator::randomFlight()
     const QDateTime dest_dt = dept_dt.addSecs(QRandomGenerator::global()->bounded(900, 50000));
 
     const QString doft = dept_dt.date().toString(Qt::ISODate);
-    OPL::Time tofb = OPL::Time::fromString(dept_dt.time().toString());
-    OPL::Time tonb = OPL::Time::fromString(dest_dt.time().toString());
+    OPL::Time tofb = OPL::Time::fromString(dept_dt.time().toString(Qt::ISODate), OPL::DateTimeFormat());
+    OPL::Time tonb = OPL::Time::fromString(dest_dt.time().toString(Qt::ISODate), OPL::DateTimeFormat());
 
     int pic = randomPilot();
     int acft = randomTail();