MOBILISIS-Calculator/library/include/mobilisis/time_range_header.h

71 lines
2.6 KiB
C
Raw Normal View History

2023-12-15 13:28:34 +01:00
#ifndef TIME_RANGE_HEADER_H_INCLUDED
#define TIME_RANGE_HEADER_H_INCLUDED
#include <QString>
#include <QDateTime>
#include <QDebug>
#include <QDebugStateSaver>
struct ATBTimeRange {
int time_range_id;
QTime time_range_from;
QTime time_range_to;
int time_range_from_in_minutes_from_start;
int time_range_to_in_minutes_from_start;
int time_range_tbase_id;
int time_range_payment_type_id;
2023-12-15 13:28:34 +01:00
explicit ATBTimeRange()
: time_range_id(-1)
, time_range_from(QTime())
, time_range_to(QTime())
, time_range_from_in_minutes_from_start(-1)
, time_range_to_in_minutes_from_start(-1)
, time_range_tbase_id(-1)
, time_range_payment_type_id(-1) {
}
QTime const &getTimeFrom() const { return time_range_from; }
QTime const &getTimeUntil() const { return time_range_to; }
bool computeQTimeFrom(QTime const &t) {
if (time_range_from_in_minutes_from_start != -1) {
time_range_from = t.addSecs(time_range_from_in_minutes_from_start * 60);
return time_range_from.isValid();
}
return false;
}
bool computeQTimeTo(QTime const &t) {
if (time_range_to_in_minutes_from_start != -1) {
time_range_to = t.addSecs(time_range_to_in_minutes_from_start * 60);
return time_range_to.isValid();
}
return false;
}
bool computeQTimes(QTime const &t) {
if (!t.isNull() && t.isValid()) {
return computeQTimeFrom(t) && computeQTimeTo(t);
}
return false;
}
2023-12-15 13:28:34 +01:00
friend QDebug operator<<(QDebug debug, ATBTimeRange const &timeRange) {
QDebugStateSaver saver(debug);
debug.nospace()
<< " time_range_id: " << timeRange.time_range_id << "\n"
<< " time_range_from: " << timeRange.time_range_from.toString(Qt::ISODate) << "\n"
<< " time_range_to: " << timeRange.time_range_to.toString(Qt::ISODate) << "\n"
<< " time_range_from_in_minutes_from_start: " << timeRange.time_range_from_in_minutes_from_start << "\n"
<< " time_range_to_in_minutes_from_start: " << timeRange.time_range_to_in_minutes_from_start << "\n"
<< " time_range_tbase_id: " << timeRange.time_range_tbase_id << "\n"
<< " time_range_payment_type_id: " << timeRange.time_range_payment_type_id << "\n";
2023-12-15 13:28:34 +01:00
return debug;
}
};
#endif // TIME_RANGE_HEADER_H_INCLUDED