فهرست منبع

Replaced Time class

Felix Turowsky 1 سال پیش
والد
کامیت
b5eef153bf

+ 25 - 2
src/classes/time.cpp

@@ -6,7 +6,7 @@ Time::Time()
 {
 }
 
-bool Time::isValidTimeOfDay()
+bool Time::isValidTimeOfDay() const
 {
     return m_minutes <= MINUTES_PER_DAY;
 }
@@ -17,7 +17,7 @@ const QString Time::toString() const
     return QString::number(m_minutes / 60).rightJustified(2, '0') + QLatin1Char(':') + QString::number(m_minutes % 60).rightJustified(2, '0');
 }
 
-int32_t Time::toMinutes()
+int32_t Time::toMinutes() const
 {
     return m_minutes;
 }
@@ -38,4 +38,27 @@ Time Time::fromString(const QString &timeString)
     return Time(hours * 60 + minutes);
 }
 
+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 {};
+
+    // 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);
+    } else {
+        // landing the day after take off
+        int minutesToMidnight = MINUTES_PER_DAY - offBlocks.m_minutes;
+        return Time(minutesToMidnight + onBlocks.m_minutes);
+    }
+}
+
+int32_t Time::blockMinutes(const Time &offBlocks, const Time &onBlocks)
+{
+    return blockTime(offBlocks, onBlocks).toMinutes();
+}
+
 } // namespace OPL

+ 12 - 2
src/classes/time.h

@@ -25,7 +25,7 @@ public:
      * @brief isValidTimeOfDay - determines whether the instance can be converted to a time hh:mm
      * @return true if the total amount of minutes does not exceed one day.
      */
-    bool isValidTimeOfDay();
+    bool isValidTimeOfDay() const;
 
     /**
      * @brief toString returns the time as hh:mm
@@ -35,7 +35,7 @@ public:
     /**
      * @brief toMinutes - returns the number of minutes in the time Object
      */
-    int32_t toMinutes();
+    int32_t toMinutes() const;
 
     /**
      * @brief fromString create a Time Object from a String formatted as hh:mm
@@ -43,6 +43,16 @@ public:
      * @return the Time Object corresponding to the string, equivalent to 0 minutes if conversion fails.
      */
     static Time fromString(const QString& timeString);
+
+    /**
+     * @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
+     */
+    int32_t timeElapsed(const Time &other);
+
+    static Time blockTime(const Time &offBlocks, const Time& onBlocks);
+    static int32_t blockMinutes(const Time &offBlocks, const Time& onBlocks);
 };
 
 }// namespace OPL

+ 7 - 6
src/functions/calc.h

@@ -24,7 +24,7 @@
 #include <cmath>
 #include <QDateTime>
 #include <QDebug>
-#include "src/functions/time.h"
+#include "src/classes/time.h"
 /*!
  * \brief The ACalc namespace provides various functions for calculations that are performed
  * outside of the database. This includes tasks like converting different units and formats,
@@ -144,8 +144,8 @@ struct NightTimeValues{
     {
         nightMinutes = calculateNightTime(dept, dest, departure_time, block_minutes, night_angle);
 
-        nightTime = OPL::Time::qTimefromMinutes(nightMinutes);
-        totalTime = OPL::Time::qTimefromMinutes(block_minutes);
+        nightTime = OPL::Time(nightMinutes);
+        totalTime = OPL::Time(block_minutes);
 
         if (nightMinutes == 0) { // all day
             takeOffNight = false;
@@ -166,13 +166,14 @@ struct NightTimeValues{
         }
 
     };
-    NightTimeValues(bool to_night, bool ldg_night, int night_minutes, QTime night_time, QTime 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;
-    QTime nightTime;
-    QTime totalTime;
+    OPL::Time nightTime;
+    OPL::Time totalTime;
 
     inline bool isAllDay()      {return (!takeOffNight  && !landingNight);}
     inline bool isAllNight()    {return ( takeOffNight  &&  landingNight);}

+ 192 - 192
src/functions/time.h

@@ -22,197 +22,197 @@
 #include <QTime>
 #include "src/opl.h"
 
-namespace OPL::Time {
-
-/*!
- * \brief Converts a QTime to a String to be used in the UI
- */
-inline const QString toString(const QTime &time, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
-{
-    switch (format) {
-    case OPL::FlightTimeFormat::Default:
-        return time.toString(QStringLiteral("hh:mm"));
-        break;
-    case OPL::FlightTimeFormat::Decimal:
-        return QString::number(((time.hour() * 60 + time.minute() )/60.0), 'f', 2);
-        break;
-    default:
-        return QString();
-    }
-}
-
-/*!
- * \brief Converts an integer of minutes as received from the Datbase to a String
- */
-inline const QString toString(int minutes_in, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
-{
-    switch (format) {
-    case OPL::FlightTimeFormat::Default:
-    {
-        QString hour = QString::number(minutes_in / 60);
-        if (hour.size() < 2) {
-            hour.prepend(QStringLiteral("0"));
-        }
-        QString minute = QString::number(minutes_in % 60);
-        if (minute.size() < 2) {
-            minute.prepend(QStringLiteral("0"));
-        }
-        return hour + QLatin1Char(':') + minute;
-    }
-    case OPL::FlightTimeFormat::Decimal:
-    {
-        int hour = minutes_in / 60;
-        double minute = (minutes_in % 60) / 60.0;
-        return QString::number((hour + minute), 'f', 2);
-    }
-    default:
-        return QString();
-    }
-
-}
-
-inline double toDecimalHours(const QTime &time){
-    return (time.hour() * 60 + time.minute()) / 60.0;
-}
-
-inline QTime qTimefromMinutes(int total_minutes)
-{
-    int minute = total_minutes % 60;
-    int hour = total_minutes / 60;
-
-    return QTime(hour, minute, 0);
-}
-
-inline const QTime fromString(QString time_string, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
-{
-    switch (format) {
-    case OPL::FlightTimeFormat::Default:
-        return QTime::fromString(time_string, QStringLiteral("hh:mm"));
-        break;
-    case OPL::FlightTimeFormat::Decimal:
-    {
-        double decimal_time = time_string.toDouble();
-        int hour = decimal_time;
-        int minute = round((decimal_time - hour) * 60);
-        return QTime(hour, minute, 0);
-        break;
-    }
-    default:
-        return QTime();
-    }
-}
-
-inline const QTime fromString(const char* time_string, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
-{
-    switch (format) {
-    case OPL::FlightTimeFormat::Default:
-        return QTime::fromString(time_string, QStringLiteral("hh:mm"));
-        break;
-    case OPL::FlightTimeFormat::Decimal:
-    {
-        double decimal_time = QString(time_string).toDouble();
-        int hour = decimal_time;
-        int minute = round((decimal_time - hour) * 60);
-        return QTime(hour, minute, 0);
-        break;
-    }
-    default:
-        return QTime();
-    }
-}
-
-inline int toMinutes(const QTime &time) {return time.hour() * 60 + time.minute();}
-inline int toMinutes(const QString &time_string) {return toMinutes(fromString(time_string));}
-
-inline QTime blocktime(const QTime &tofb, const QTime &tonb)
-{
-    QTime blocktime_out(0, 0); // initialise return value at midnight
-
-    if (tonb > tofb) { // landing same day
-        int block_seconds = tofb.secsTo(tonb);
-        blocktime_out = blocktime_out.addSecs(block_seconds);
-    } else { // landing next day
-        QTime midnight(0, 0);
-        int seconds = tofb.secsTo(midnight);
-        blocktime_out = blocktime_out.addSecs(seconds);
-        seconds = midnight.secsTo(tonb);
-        blocktime_out = blocktime_out.addSecs(seconds);
-    }
-    return blocktime_out;
-}
-
-inline QTime blocktime(const QString& tofb, const QString& tonb)
-{
-    QTime t_tofb = OPL::Time::fromString(tofb);
-    QTime t_tonb = OPL::Time::fromString(tonb);
-    return blocktime(t_tofb, t_tonb);
-}
-
-/*!
- * \brief blockMinutes calculates the total amount of minutes elapsed between
- * tofb and tonb
- */
-inline int blockMinutes(const QString& tofb, const QString& tonb)
-{
-    const QTime t_tofb = OPL::Time::fromString(tofb);
-    const QTime t_tonb = OPL::Time::fromString(tonb);
-    if (t_tofb.isValid() && t_tonb.isValid()) {
-        const auto tblk = OPL::Time::blocktime(t_tofb, t_tonb);
-        return OPL::Time::toMinutes(tblk);
-    } else
-        return 0;
-}
-
-/*!
- * \brief blockMinutes calculates the total amount of minutes elapsed between
- * tofb and tonb
- */
-inline int blockMinutes(const QTime& tofb, const QTime& tonb)
-{
-    if (tofb.isValid() && tonb.isValid()) {
-        const auto tblk = OPL::Time::blocktime(tofb, tonb);
-        return OPL::Time::toMinutes(tblk);
-    } else
-        return 0;
-}
-
-/*!
- * \brief verifies user input and formats to hh:mm
- * if the output is not a valid time, an empty string is returned. Accepts
- * input as hh:mm, h:mm, hhmm or hmm.
- * \param userinput from a QLineEdit
- * \return formatted QString "hh:mm" or Empty String
- */
-QT_DEPRECATED
-inline const QString formatTimeInput(QString user_input)
-{
-    LOG << "DEPRECATED";
-    QTime temp_time; //empty time object is invalid by default
-
-    bool contains_seperator = user_input.contains(':');
-    if (user_input.length() == 4 && !contains_seperator) {
-        temp_time = QTime::fromString(user_input, QStringLiteral("hhmm"));
-    } else if (user_input.length() == 3 && !contains_seperator) {
-        if (user_input.toInt() < 240) { //Qtime is invalid if time is between 000 and 240 for this case
-            QString tempstring = user_input.prepend(QStringLiteral("0"));
-            temp_time = QTime::fromString(tempstring, QStringLiteral("hhmm"));
-        } else {
-            temp_time = QTime::fromString(user_input, QStringLiteral("Hmm"));
-        }
-    } else if (user_input.length() == 4 && contains_seperator) {
-        temp_time = QTime::fromString(user_input, QStringLiteral("h:mm"));
-    } else if (user_input.length() == 5 && contains_seperator) {
-        temp_time = QTime::fromString(user_input, QStringLiteral("hh:mm"));
-    }
-
-    auto output = temp_time.toString(QStringLiteral("hh:mm"));
-
-    if (output.isEmpty()) {
-        DEB << "Time input is invalid.";
-    }
-    return output;
-}
-
-} // namespace OPL::Time
+//namespace OPL::Time {
+
+///*!
+// * \brief Converts a QTime to a String to be used in the UI
+// */
+//inline const QString toString(const QTime &time, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
+//{
+//    switch (format) {
+//    case OPL::FlightTimeFormat::Default:
+//        return time.toString(QStringLiteral("hh:mm"));
+//        break;
+//    case OPL::FlightTimeFormat::Decimal:
+//        return QString::number(((time.hour() * 60 + time.minute() )/60.0), 'f', 2);
+//        break;
+//    default:
+//        return QString();
+//    }
+//}
+
+///*!
+// * \brief Converts an integer of minutes as received from the Datbase to a String
+// */
+//inline const QString toString(int minutes_in, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
+//{
+//    switch (format) {
+//    case OPL::FlightTimeFormat::Default:
+//    {
+//        QString hour = QString::number(minutes_in / 60);
+//        if (hour.size() < 2) {
+//            hour.prepend(QStringLiteral("0"));
+//        }
+//        QString minute = QString::number(minutes_in % 60);
+//        if (minute.size() < 2) {
+//            minute.prepend(QStringLiteral("0"));
+//        }
+//        return hour + QLatin1Char(':') + minute;
+//    }
+//    case OPL::FlightTimeFormat::Decimal:
+//    {
+//        int hour = minutes_in / 60;
+//        double minute = (minutes_in % 60) / 60.0;
+//        return QString::number((hour + minute), 'f', 2);
+//    }
+//    default:
+//        return QString();
+//    }
+
+//}
+
+//inline double toDecimalHours(const QTime &time){
+//    return (time.hour() * 60 + time.minute()) / 60.0;
+//}
+
+//inline QTime qTimefromMinutes(int total_minutes)
+//{
+//    int minute = total_minutes % 60;
+//    int hour = total_minutes / 60;
+
+//    return QTime(hour, minute, 0);
+//}
+
+//inline const QTime fromString(QString time_string, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
+//{
+//    switch (format) {
+//    case OPL::FlightTimeFormat::Default:
+//        return QTime::fromString(time_string, QStringLiteral("hh:mm"));
+//        break;
+//    case OPL::FlightTimeFormat::Decimal:
+//    {
+//        double decimal_time = time_string.toDouble();
+//        int hour = decimal_time;
+//        int minute = round((decimal_time - hour) * 60);
+//        return QTime(hour, minute, 0);
+//        break;
+//    }
+//    default:
+//        return QTime();
+//    }
+//}
+
+//inline const QTime fromString(const char* time_string, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
+//{
+//    switch (format) {
+//    case OPL::FlightTimeFormat::Default:
+//        return QTime::fromString(time_string, QStringLiteral("hh:mm"));
+//        break;
+//    case OPL::FlightTimeFormat::Decimal:
+//    {
+//        double decimal_time = QString(time_string).toDouble();
+//        int hour = decimal_time;
+//        int minute = round((decimal_time - hour) * 60);
+//        return QTime(hour, minute, 0);
+//        break;
+//    }
+//    default:
+//        return QTime();
+//    }
+//}
+
+//inline int toMinutes(const QTime &time) {return time.hour() * 60 + time.minute();}
+//inline int toMinutes(const QString &time_string) {return toMinutes(fromString(time_string));}
+
+////inline QTime blocktime(const QTime &tofb, const QTime &tonb)
+////{
+////    QTime blocktime_out(0, 0); // initialise return value at midnight
+
+////    if (tonb > tofb) { // landing same day
+////        int block_seconds = tofb.secsTo(tonb);
+////        blocktime_out = blocktime_out.addSecs(block_seconds);
+////    } else { // landing next day
+////        QTime midnight(0, 0);
+////        int seconds = tofb.secsTo(midnight);
+////        blocktime_out = blocktime_out.addSecs(seconds);
+////        seconds = midnight.secsTo(tonb);
+////        blocktime_out = blocktime_out.addSecs(seconds);
+////    }
+////    return blocktime_out;
+////}
+
+////inline QTime blocktime(const QString& tofb, const QString& tonb)
+////{
+////    QTime t_tofb = OPL::Time::fromString(tofb);
+////    QTime t_tonb = OPL::Time::fromString(tonb);
+////    return blocktime(t_tofb, t_tonb);
+////}
+
+/////*!
+//// * \brief blockMinutes calculates the total amount of minutes elapsed between
+//// * tofb and tonb
+//// */
+////inline int blockMinutes(const QString& tofb, const QString& tonb)
+////{
+////    const QTime t_tofb = OPL::Time::fromString(tofb);
+////    const QTime t_tonb = OPL::Time::fromString(tonb);
+////    if (t_tofb.isValid() && t_tonb.isValid()) {
+////        const auto tblk = OPL::Time::blocktime(t_tofb, t_tonb);
+////        return OPL::Time::toMinutes(tblk);
+////    } else
+////        return 0;
+////}
+
+/////*!
+//// * \brief blockMinutes calculates the total amount of minutes elapsed between
+//// * tofb and tonb
+//// */
+////inline int blockMinutes(const QTime& tofb, const QTime& tonb)
+////{
+////    if (tofb.isValid() && tonb.isValid()) {
+////        const auto tblk = OPL::Time::blocktime(tofb, tonb);
+////        return OPL::Time::toMinutes(tblk);
+////    } else
+////        return 0;
+////}
+
+///*!
+// * \brief verifies user input and formats to hh:mm
+// * if the output is not a valid time, an empty string is returned. Accepts
+// * input as hh:mm, h:mm, hhmm or hmm.
+// * \param userinput from a QLineEdit
+// * \return formatted QString "hh:mm" or Empty String
+// */
+//QT_DEPRECATED
+//inline const QString formatTimeInput(QString user_input)
+//{
+//    LOG << "DEPRECATED";
+//    QTime temp_time; //empty time object is invalid by default
+
+//    bool contains_seperator = user_input.contains(':');
+//    if (user_input.length() == 4 && !contains_seperator) {
+//        temp_time = QTime::fromString(user_input, QStringLiteral("hhmm"));
+//    } else if (user_input.length() == 3 && !contains_seperator) {
+//        if (user_input.toInt() < 240) { //Qtime is invalid if time is between 000 and 240 for this case
+//            QString tempstring = user_input.prepend(QStringLiteral("0"));
+//            temp_time = QTime::fromString(tempstring, QStringLiteral("hhmm"));
+//        } else {
+//            temp_time = QTime::fromString(user_input, QStringLiteral("Hmm"));
+//        }
+//    } else if (user_input.length() == 4 && contains_seperator) {
+//        temp_time = QTime::fromString(user_input, QStringLiteral("h:mm"));
+//    } else if (user_input.length() == 5 && contains_seperator) {
+//        temp_time = QTime::fromString(user_input, QStringLiteral("hh:mm"));
+//    }
+
+//    auto output = temp_time.toString(QStringLiteral("hh:mm"));
+
+//    if (output.isEmpty()) {
+//        DEB << "Time input is invalid.";
+//    }
+//    return output;
+//}
+
+//} // namespace OPL::Time
 
 #endif // TIME_H

+ 21 - 8
src/gui/dialogues/newflightdialog.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "newflightdialog.h"
+#include "src/classes/time.h"
 #include "src/database/databasecache.h"
 #include "src/gui/verification/airportinput.h"
 #include "src/gui/verification/completerprovider.h"
@@ -189,8 +190,8 @@ void NewFlightDialog::fillWithEntryData()
     ui->deptLocationLineEdit->setText(flight_data.value(OPL::Db::FLIGHTS_DEPT).toString());
     ui->destLocationLineEdit->setText(flight_data.value(OPL::Db::FLIGHTS_DEST).toString());
     // Times
-    ui->tofbTimeLineEdit->setText(OPL::Time::toString(flight_data.value(OPL::Db::FLIGHTS_TOFB).toInt()));
-    ui->tonbTimeLineEdit->setText(OPL::Time::toString(flight_data.value(OPL::Db::FLIGHTS_TONB).toInt()));
+    ui->tofbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::Db::FLIGHTS_TOFB).toInt()).toString());
+    ui->tonbTimeLineEdit->setText(OPL::Time(flight_data.value(OPL::Db::FLIGHTS_TONB).toInt()).toString());
     ui->acftLineEdit->setText(DBCache->getTailsMap().value(flight_data.value(OPL::Db::FLIGHTS_ACFT).toInt()));
     ui->picNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::Db::FLIGHTS_PIC).toInt()));
     ui->sicNameLineEdit->setText(DBCache->getPilotNamesMap().value(flight_data.value(OPL::Db::FLIGHTS_SECONDPILOT).toInt()));
@@ -283,8 +284,11 @@ void NewFlightDialog::onBadInputReceived(QLineEdit *line_edit)
 
 void NewFlightDialog::updateBlockTimeLabel()
 {
-    QTime tblk = OPL::Time::blocktime(ui->tofbTimeLineEdit->text(), ui->tonbTimeLineEdit->text());
-    ui->tblkDisplayLabel->setText(OPL::Time::toString(tblk));
+    const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
+    const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
+    const OPL::Time tblk = OPL::Time::blockTime(tofb, tonb);
+
+    ui->tblkDisplayLabel->setText(tblk.toString());
 }
 
 /*!
@@ -365,18 +369,23 @@ OPL::RowData_T NewFlightDialog::prepareFlightEntryData()
     if(!validationState.allValid())
         return {};
 
+    // prepare the entry data
     OPL::RowData_T new_data;
+
     // Calculate Block and Night Time
-    const int block_minutes = OPL::Time::blockMinutes(ui->tofbTimeLineEdit->text(), ui->tonbTimeLineEdit->text());
+    const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
+    const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
+    const int block_minutes = OPL::Time::blockMinutes(tofb, tonb);
+
     QDateTime departure_date_time = OPL::DateTime::fromString(ui->doftLineEdit->text() + ui->tofbTimeLineEdit->text());
     const auto night_time_data = OPL::Calc::NightTimeValues(ui->deptLocationLineEdit->text(), ui->destLocationLineEdit->text(),
                            departure_date_time, block_minutes, Settings::read(Settings::FlightLogging::NightAngle).toInt());
     // Mandatory data
     new_data.insert(OPL::Db::FLIGHTS_DOFT, ui->doftLineEdit->text());
     new_data.insert(OPL::Db::FLIGHTS_DEPT, ui->deptLocationLineEdit->text());
-    new_data.insert(OPL::Db::FLIGHTS_TOFB, OPL::Time::toMinutes(ui->tofbTimeLineEdit->text()));
+    new_data.insert(OPL::Db::FLIGHTS_TOFB, tofb.toMinutes());
     new_data.insert(OPL::Db::FLIGHTS_DEST, ui->destLocationLineEdit->text());
-    new_data.insert(OPL::Db::FLIGHTS_TONB, OPL::Time::toMinutes(ui->tonbTimeLineEdit->text()));
+    new_data.insert(OPL::Db::FLIGHTS_TONB, tonb.toMinutes());
     new_data.insert(OPL::Db::FLIGHTS_TBLK, block_minutes);
     // Night
     new_data.insert(OPL::Db::FLIGHTS_TNIGHT, night_time_data.nightMinutes);
@@ -475,10 +484,14 @@ OPL::RowData_T NewFlightDialog::prepareFlightEntryData()
  */
 void NewFlightDialog::updateNightCheckBoxes()
 {
+    // calculate Block Time
+    const OPL::Time tofb = OPL::Time::fromString(ui->tofbTimeLineEdit->text());
+    const OPL::Time tonb = OPL::Time::fromString(ui->tonbTimeLineEdit->text());
+    const int block_minutes = OPL::Time::blockMinutes(tofb, tonb);
+
     // Calculate Night Time
     const QString dept_date = (ui->doftLineEdit->text() + ui->tofbTimeLineEdit->text());
     const auto dept_date_time = OPL::DateTime::fromString(dept_date);
-    const int block_minutes = OPL::Time::blockMinutes(ui->tofbTimeLineEdit->text(), ui->tonbTimeLineEdit->text());
     const int night_angle = Settings::read(Settings::FlightLogging::NightAngle).toInt();
     const auto night_values = OPL::Calc::NightTimeValues(
                 ui->deptLocationLineEdit->text(),

+ 6 - 5
src/gui/dialogues/newsimdialog.cpp

@@ -3,7 +3,7 @@
 #include "src/gui/verification/timeinput.h"
 #include "ui_newsimdialog.h"
 #include "src/opl.h"
-#include "src/functions/time.h"
+#include "src/classes/time.h"
 #include "src/functions/datetime.h"
 #include "src/database/database.h"
 #include <QCompleter>
@@ -56,7 +56,7 @@ void NewSimDialog::fillEntryData()
 {
     const auto& data = entry.getData();
     ui->dateLineEdit->setText(data.value(OPL::Db::SIMULATORS_DATE).toString());
-    ui->totalTimeLineEdit->setText(OPL::Time::toString(data.value(OPL::Db::SIMULATORS_TIME).toInt()));
+    ui->totalTimeLineEdit->setText(OPL::Time(data.value(OPL::Db::SIMULATORS_TIME).toInt()).toString());
     ui->deviceTypeComboBox->setCurrentIndex(data.value(OPL::Db::SIMULATORS_TYPE).toInt());
     ui->aircraftTypeLineEdit->setText(data.value(OPL::Db::SIMULATORS_ACFT).toString());
     ui->registrationLineEdit->setText(data.value(OPL::Db::SIMULATORS_REG).toString());
@@ -135,9 +135,10 @@ bool NewSimDialog::verifyInput(QString& error_msg)
     // Time
     if(!TimeInput(ui->totalTimeLineEdit->text()).isValid())
         return false;
-    const QTime time = OPL::Time::fromString(ui->totalTimeLineEdit->text());
 
-    if (!time.isValid()) {
+    const OPL::Time time = OPL::Time::fromString(ui->totalTimeLineEdit->text());
+
+    if (!time.isValidTimeOfDay()) {
         ui->totalTimeLineEdit->setStyleSheet(OPL::Styles::RED_BORDER);
         ui->totalTimeLineEdit->setText(QString());
         error_msg = tr("Invalid time");
@@ -160,7 +161,7 @@ OPL::RowData_T NewSimDialog::collectInput()
     // Date
     new_entry.insert(OPL::Db::SIMULATORS_DATE, ui->dateLineEdit->text());
     // Time
-    new_entry.insert(OPL::Db::SIMULATORS_TIME, OPL::Time::toMinutes(ui->totalTimeLineEdit->text()));
+    new_entry.insert(OPL::Db::SIMULATORS_TIME, OPL::Time::fromString(ui->totalTimeLineEdit->text()).toMinutes());
     // Device Type
     new_entry.insert(OPL::Db::SIMULATORS_TYPE, ui->deviceTypeComboBox->currentText());
     // Aircraft Type

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

@@ -19,7 +19,7 @@
 #include "src/gui/widgets/totalswidget.h"
 #include "ui_homewidget.h"
 #include "src/database/database.h"
-#include "src/functions/time.h"
+#include "src/classes/time.h"
 #include "src/classes/settings.h"
 #include "src/database/row.h"
 
@@ -200,7 +200,7 @@ void HomeWidget::fillCurrencyTakeOffLanding()
 void HomeWidget::fillLimitations()
 {
     int minutes = OPL::Statistics::totalTime(OPL::Statistics::TimeFrame::Rolling28Days);
-    ui->FlightTime28dDisplayLabel->setText(OPL::Time::toString(minutes));
+    ui->FlightTime28dDisplayLabel->setText(OPL::Time(minutes).toString());
     if (minutes >= ROLLING_28_DAYS) {
         setLabelColour(ui->FlightTime28dDisplayLabel, Colour::Red);
     } else if (minutes >= ROLLING_28_DAYS * ftlWarningThreshold) {
@@ -208,7 +208,7 @@ void HomeWidget::fillLimitations()
     }
 
     minutes = OPL::Statistics::totalTime(OPL::Statistics::TimeFrame::Rolling12Months);
-    ui->FlightTime12mDisplayLabel->setText(OPL::Time::toString(minutes));
+    ui->FlightTime12mDisplayLabel->setText(OPL::Time(minutes).toString());
     if (minutes >= ROLLING_12_MONTHS) {
         setLabelColour(ui->FlightTime12mDisplayLabel, Colour::Red);
     } else if (minutes >= ROLLING_12_MONTHS * ftlWarningThreshold) {
@@ -216,7 +216,7 @@ void HomeWidget::fillLimitations()
     }
 
     minutes = OPL::Statistics::totalTime(OPL::Statistics::TimeFrame::CalendarYear);
-    ui->FlightTimeCalYearDisplayLabel->setText(OPL::Time::toString(minutes));
+    ui->FlightTimeCalYearDisplayLabel->setText(OPL::Time(minutes).toString());
     if (minutes >= CALENDAR_YEAR) {
         setLabelColour(ui->FlightTimeCalYearDisplayLabel, Colour::Red);
     } else if (minutes >= CALENDAR_YEAR * ftlWarningThreshold) {

+ 3 - 2
src/gui/widgets/logbookwidget.cpp

@@ -15,6 +15,7 @@
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
+#include "src/classes/time.h"
 #include "src/database/database.h"
 #include "logbookwidget.h"
 #include "ui_logbookwidget.h"
@@ -98,9 +99,9 @@ const QString LogbookWidget::getFlightSummary(const OPL::FlightEntry &flight) co
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DOFT).toString() + space);
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DEPT).toString() + space);
-    flight_summary.append(OPL::Time::toString(tableData.value(OPL::Db::FLIGHTS_TOFB).toInt())
+    flight_summary.append(OPL::Time(tableData.value(OPL::Db::FLIGHTS_TOFB).toInt()).toString()
                           + space);
-    flight_summary.append(OPL::Time::toString(tableData.value(OPL::Db::FLIGHTS_TONB).toInt())
+    flight_summary.append(OPL::Time(tableData.value(OPL::Db::FLIGHTS_TONB).toInt()).toString()
                           + space);
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DEST).toString());
 

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

@@ -21,7 +21,7 @@
 #include "src/opl.h"
 #include "src/database/database.h"
 #include "src/database/row.h"
-#include "src/functions/time.h"
+#include "src/classes/time.h"
 #include "src/classes/settings.h"
 
 PilotsWidget::PilotsWidget(QWidget *parent) :
@@ -258,9 +258,9 @@ const QString PilotsWidget::getFlightSummary(const OPL::FlightEntry &flight) con
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DOFT).toString() + space);
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DEPT).toString() + space);
-    flight_summary.append(OPL::Time::toString(tableData.value(OPL::Db::FLIGHTS_TOFB).toInt())
+    flight_summary.append(OPL::Time(tableData.value(OPL::Db::FLIGHTS_TOFB).toInt()).toString()
                           + space);
-    flight_summary.append(OPL::Time::toString(tableData.value(OPL::Db::FLIGHTS_TONB).toInt())
+    flight_summary.append(OPL::Time(tableData.value(OPL::Db::FLIGHTS_TONB).toInt()).toString()
                           + space);
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DEST).toString());
 

+ 2 - 2
src/gui/widgets/tailswidget.cpp

@@ -284,9 +284,9 @@ const QString TailsWidget::getFlightSummary(const OPL::FlightEntry &flight) cons
     auto space = QLatin1Char(' ');
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DOFT).toString() + space);
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DEPT).toString() + space);
-    flight_summary.append(OPL::Time::toString(tableData.value(OPL::Db::FLIGHTS_TOFB).toInt())
+    flight_summary.append(OPL::Time(tableData.value(OPL::Db::FLIGHTS_TOFB).toInt()).toString()
                           + space);
-    flight_summary.append(OPL::Time::toString(tableData.value(OPL::Db::FLIGHTS_TONB).toInt())
+    flight_summary.append(OPL::Time(tableData.value(OPL::Db::FLIGHTS_TONB).toInt()).toString()
                           + space);
     flight_summary.append(tableData.value(OPL::Db::FLIGHTS_DEST).toString());
 

+ 0 - 10
src/gui/widgets/totalswidget.cpp

@@ -1,7 +1,6 @@
 #include "totalswidget.h"
 #include "QtWidgets/qlineedit.h"
 #include "src/database/database.h"
-#include "src/gui/verification/timeinput.h"
 #include "src/opl.h"
 #include "src/classes/time.h"
 #include "src/database/row.h"
@@ -165,15 +164,6 @@ void TotalsWidget::connectSignalsAndSlots()
             this, &TotalsWidget::movementLineEditEditingFinished);
 }
 
-/*!
- * \brief TotalsWidget::updateMovementEntry Updates the DB with a movement (TO or LDG) entry
- * \param line_edit The line edit that has been edited
- * \return true on success
- */
-bool TotalsWidget::updateMovementEntry(const QLineEdit *line_edit)
-{
-
-}
 
 void TotalsWidget::timeLineEditEditingFinished()
 {

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

@@ -1,5 +1,5 @@
 #include "processflights.h"
-#include <src/functions/time.h>
+#include "src/classes/time.h"
 
 void ProcessFlights::parseRawData()
 {
@@ -53,14 +53,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::toMinutes(time_off);
+        int tofb = OPL::Time::fromString(time_off.toString()).toMinutes();
         new_flight_data.insert(OPL::Db::FLIGHTS_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::toMinutes(time_on);
+        int tonb = OPL::Time::fromString(time_on.toString()).toMinutes();
         new_flight_data.insert(OPL::Db::FLIGHTS_TONB, tonb);
 
         // map pilots

+ 5 - 5
src/testing/randomgenerator.cpp

@@ -20,8 +20,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);
-    int tofb = OPL::Time::toMinutes(dept_dt.time());
-    int tonb = OPL::Time::toMinutes(dest_dt.time());
+    OPL::Time tofb = OPL::Time::fromString(dept_dt.time().toString());
+    OPL::Time tonb = OPL::Time::fromString(dest_dt.time().toString());
 
     int pic = randomPilot();
     int acft = randomTail();
@@ -29,7 +29,7 @@ const FlightEntry RandomGenerator::randomFlight()
     const QString dept = randomAirport();
     const QString dest = randomAirport();
 
-    int tblk = OPL::Time::blockMinutes(dept_dt.time(), dest_dt.time());
+    int tblk = OPL::Time::blockMinutes(tofb, tonb);
     int tNight = OPL::Calc::calculateNightTime(dept, dest, dept_dt, tblk, 6);
 
     auto flt_data = OPL::RowData_T();
@@ -38,8 +38,8 @@ const FlightEntry RandomGenerator::randomFlight()
     flt_data.insert(OPL::Db::FLIGHTS_DEST, dest);
     flt_data.insert(OPL::Db::FLIGHTS_PIC, pic);
     flt_data.insert(OPL::Db::FLIGHTS_ACFT, acft);
-    flt_data.insert(OPL::Db::FLIGHTS_TOFB, tofb);
-    flt_data.insert(OPL::Db::FLIGHTS_TONB, tonb);
+    flt_data.insert(OPL::Db::FLIGHTS_TOFB, tofb.toMinutes());
+    flt_data.insert(OPL::Db::FLIGHTS_TONB, tonb.toMinutes());
     flt_data.insert(OPL::Db::FLIGHTS_TBLK, tblk);
 
     if (tNight > 0) flt_data.insert(OPL::Db::FLIGHTS_TNIGHT, tNight);