30 inline const QString toString(
const QTime &time, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
33 case OPL::FlightTimeFormat::Default:
34 return time.toString(QStringLiteral(
"hh:mm"));
36 case OPL::FlightTimeFormat::Decimal:
37 return QString::number(((time.hour() * 60 + time.minute() )/60.0),
'f', 2);
47 inline const QString toString(
int minutes_in, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
50 case OPL::FlightTimeFormat::Default:
52 QString hour = QString::number(minutes_in / 60);
53 if (hour.size() < 2) {
54 hour.prepend(QStringLiteral(
"0"));
56 QString minute = QString::number(minutes_in % 60);
57 if (minute.size() < 2) {
58 minute.prepend(QStringLiteral(
"0"));
60 return hour +
':' + minute;
62 case OPL::FlightTimeFormat::Decimal:
64 int hour = minutes_in / 60;
65 double minute = (minutes_in % 60) / 60.0;
66 return QString::number((hour + minute),
'f', 2);
74 inline double toDecimalHours(
const QTime &time){
75 return (time.hour() * 60 + time.minute()) / 60.0;
78 inline QTime qTimefromMinutes(
int total_minutes)
80 int minute = total_minutes % 60;
81 int hour = total_minutes / 60;
83 return QTime(hour, minute, 0);
86 inline const QTime fromString(QString time_string, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
89 case OPL::FlightTimeFormat::Default:
90 return QTime::fromString(time_string, QStringLiteral(
"hh:mm"));
92 case OPL::FlightTimeFormat::Decimal:
94 double decimal_time = time_string.toDouble();
95 int hour = decimal_time;
96 int minute = round((decimal_time - hour) * 60);
97 return QTime(hour, minute, 0);
105 inline const QTime fromString(
const char* time_string, OPL::FlightTimeFormat format = OPL::FlightTimeFormat::Default)
108 case OPL::FlightTimeFormat::Default:
109 return QTime::fromString(time_string, QStringLiteral(
"hh:mm"));
111 case OPL::FlightTimeFormat::Decimal:
113 double decimal_time = QString(time_string).toDouble();
114 int hour = decimal_time;
115 int minute = round((decimal_time - hour) * 60);
116 return QTime(hour, minute, 0);
124 inline int toMinutes(
const QTime &time) {
return time.hour() * 60 + time.minute();}
125 inline int toMinutes(
const QString &time_string) {
return toMinutes(fromString(time_string));}
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;
144 inline QTime blocktime(
const QString& tofb,
const QString& tonb)
146 QTime t_tofb = OPL::Time::fromString(tofb);
147 QTime t_tonb = OPL::Time::fromString(tonb);
148 return blocktime(t_tofb, t_tonb);
155 inline int blockMinutes(
const QString& tofb,
const QString& tonb)
157 const QTime t_tofb = OPL::Time::fromString(tofb);
158 const QTime t_tonb = OPL::Time::fromString(tonb);
159 if (t_tofb.isValid() && t_tonb.isValid()) {
160 const auto tblk = OPL::Time::blocktime(t_tofb, t_tonb);
161 return OPL::Time::toMinutes(tblk);
170 inline int blockMinutes(
const QTime& tofb,
const QTime& tonb)
172 if (tofb.isValid() && tonb.isValid()) {
173 const auto tblk = OPL::Time::blocktime(tofb, tonb);
174 return OPL::Time::toMinutes(tblk);
190 bool contains_seperator = user_input.contains(
':');
191 if (user_input.length() == 4 && !contains_seperator) {
192 temp_time = QTime::fromString(user_input, QStringLiteral(
"hhmm"));
193 }
else if (user_input.length() == 3 && !contains_seperator) {
194 if (user_input.toInt() < 240) {
195 QString tempstring = user_input.prepend(QStringLiteral(
"0"));
196 temp_time = QTime::fromString(tempstring, QStringLiteral(
"hhmm"));
198 temp_time = QTime::fromString(user_input, QStringLiteral(
"Hmm"));
200 }
else if (user_input.length() == 4 && contains_seperator) {
201 temp_time = QTime::fromString(user_input, QStringLiteral(
"h:mm"));
202 }
else if (user_input.length() == 5 && contains_seperator) {
203 temp_time = QTime::fromString(user_input, QStringLiteral(
"hh:mm"));
206 auto output = temp_time.toString(QStringLiteral(
"hh:mm"));
208 if (output.isEmpty()) {
209 DEB <<
"Time input is invalid.";
QString formatTimeInput(QString user_input)
OPL::Calc::formatTimeInput verifies user input and formats to hh:mm if the output is not a valid time...
Definition: calc.cpp:31