24 #include "src/functions/alog.h"
31 inline const QString toString(
const QTime &time, Opl::Time::FlightTimeFormat format = Opl::Time::Default)
34 case Opl::Time::Default:
35 return time.toString(QStringLiteral(
"hh:mm"));
37 case Opl::Time::Decimal:
38 return QString::number(((time.hour() * 60 + time.minute() )/60.0),
'f', 2);
48 inline const QString toString(
int minutes_in, Opl::Time::FlightTimeFormat format = Opl::Time::Default)
51 case Opl::Time::Default:
53 QString hour = QString::number(minutes_in / 60);
54 if (hour.size() < 2) {
55 hour.prepend(QStringLiteral(
"0"));
57 QString minute = QString::number(minutes_in % 60);
58 if (minute.size() < 2) {
59 minute.prepend(QStringLiteral(
"0"));
61 return hour +
':' + minute;
63 case Opl::Time::Decimal:
65 int hour = minutes_in / 60;
66 double minute = (minutes_in % 60) / 60.0;
67 return QString::number((hour + minute),
'f', 2);
75 inline double toDecimalHours(
const QTime &time){
76 return (time.hour() * 60 + time.minute()) / 60.0;
79 inline int toMinutes(
const QTime &time) {
return time.hour() * 60 + time.minute();}
81 inline QTime fromMinutes(
int total_minutes)
83 int minute = total_minutes % 60;
84 int hour = total_minutes / 60;
86 return QTime(hour, minute, 0);
89 inline const QTime fromString(QString time_string, Opl::Time::FlightTimeFormat format = Opl::Time::Default)
92 case Opl::Time::Default:
93 return QTime::fromString(time_string, QStringLiteral(
"hh:mm"));
95 case Opl::Time::Decimal:
97 double decimal_time = time_string.toDouble();
98 int hour = decimal_time;
99 int minute = round((decimal_time - hour) * 60);
100 return QTime(hour, minute, 0);
108 inline const QTime fromString(
const char* time_string, Opl::Time::FlightTimeFormat format = Opl::Time::Default)
111 case Opl::Time::Default:
112 return QTime::fromString(time_string, QStringLiteral(
"hh:mm"));
114 case Opl::Time::Decimal:
116 double decimal_time = QString(time_string).toDouble();
117 int hour = decimal_time;
118 int minute = round((decimal_time - hour) * 60);
119 return QTime(hour, minute, 0);
127 inline QTime
blocktime(
const QTime &tofb,
const QTime &tonb)
129 QTime blocktime_out(0, 0);
132 int block_seconds = tofb.secsTo(tonb);
133 blocktime_out = blocktime_out.addSecs(block_seconds);
135 QTime midnight(0, 0);
136 int seconds = tofb.secsTo(midnight);
137 blocktime_out = blocktime_out.addSecs(seconds);
138 seconds = midnight.secsTo(tonb);
139 blocktime_out = blocktime_out.addSecs(seconds);
141 return blocktime_out;
155 bool contains_seperator = user_input.contains(
':');
156 if (user_input.length() == 4 && !contains_seperator) {
157 temp_time = QTime::fromString(user_input, QStringLiteral(
"hhmm"));
158 }
else if (user_input.length() == 3 && !contains_seperator) {
159 if (user_input.toInt() < 240) {
160 QString tempstring = user_input.prepend(QStringLiteral(
"0"));
161 temp_time = QTime::fromString(tempstring, QStringLiteral(
"hhmm"));
163 temp_time = QTime::fromString(user_input, QStringLiteral(
"Hmm"));
165 }
else if (user_input.length() == 4 && contains_seperator) {
166 temp_time = QTime::fromString(user_input, QStringLiteral(
"h:mm"));
167 }
else if (user_input.length() == 5 && contains_seperator) {
168 temp_time = QTime::fromString(user_input, QStringLiteral(
"hh:mm"));
171 auto output = temp_time.toString(QStringLiteral(
"hh:mm"));
173 if (output.isEmpty()) {
174 DEB <<
"Time input is invalid.";