Warning, file /libraries/kopeninghours/src/lib/interval.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOPENINGHOURS_INTERVAL_H 0008 #define KOPENINGHOURS_INTERVAL_H 0009 0010 #include "kopeninghours_export.h" 0011 0012 #include <QDateTime> 0013 #include <QDebug> 0014 #include <QExplicitlySharedDataPointer> 0015 #include <QMetaType> 0016 0017 class QDateTime; 0018 0019 namespace KOpeningHours { 0020 0021 class IntervalPrivate; 0022 0023 /** A time interval for which an opening hours expression has been evaluated. */ 0024 class KOPENINGHOURS_EXPORT Interval 0025 { 0026 Q_GADGET 0027 Q_PROPERTY(State state READ state) 0028 Q_PROPERTY(QDateTime begin READ begin) 0029 Q_PROPERTY(bool hasOpenBegin READ hasOpenBegin) 0030 Q_PROPERTY(QDateTime end READ end) 0031 Q_PROPERTY(bool hasOpenEnd READ hasOpenEnd) 0032 Q_PROPERTY(bool hasOpenEndTime READ hasOpenEndTime) 0033 Q_PROPERTY(QString comment READ comment) 0034 Q_PROPERTY(QDateTime estimatedEnd READ estimatedEnd) 0035 public: 0036 Interval(); 0037 Interval(const Interval&); 0038 Interval(Interval&&); 0039 ~Interval(); 0040 Interval& operator=(const Interval&); 0041 Interval& operator=(Interval&&); 0042 0043 /** Check whether this interval starts before @p other. */ 0044 bool operator<(const Interval &other) const; 0045 0046 /** Default constructed empty/invalid interval. */ 0047 bool isValid() const; 0048 0049 /** Checks whether this interval overlaps with @p other. */ 0050 bool intersects(const Interval &other) const; 0051 0052 /** Begin of the interval. 0053 * This is the first point in time included in the interval, or invalid if this is an interval with an open begin. 0054 */ 0055 QDateTime begin() const; 0056 void setBegin(const QDateTime &begin); 0057 0058 /** Returns @c true if this is an interval with an open begin, ie. starting at the beginning of time. */ 0059 bool hasOpenBegin() const; 0060 0061 /** End of the interval. 0062 * This is the first point in time not included in the interval anymore, or invalid for open-ended intervals. 0063 * That is, the end of an interval describing the year 2020 would be Jan 1st 2021 at midnight (00:00). 0064 */ 0065 QDateTime end() const; 0066 void setEnd(const QDateTime &end); 0067 0068 /** Returns @c true if this is an interval with an open end date, ie. continuing for all eternity. 0069 * @note This is different from an interval with an open end time. 0070 */ 0071 bool hasOpenEnd() const; 0072 0073 /** Returns @c true if this is an interval with an open end time, ie. an interval generated by a selector like "20:00+". 0074 * @note This is different from an interval with an open end. 0075 */ 0076 bool hasOpenEndTime() const; 0077 void setOpenEndTime(bool openEndTime); 0078 0079 /** Returns an estimated end time for intervals with an open end time. 0080 * By default this is the same as end() would return, unless higher-level 0081 * logic with a view on multiple intervals and/or other context actually sets this. 0082 */ 0083 QDateTime estimatedEnd() const; 0084 void setEstimatedEnd(const QDateTime &estimatedEnd); 0085 0086 /** Check if this interval contains @p dt. */ 0087 bool contains(const QDateTime &dt) const; 0088 0089 /** Opening state during a time interval */ 0090 enum State { 0091 Invalid, 0092 Open, 0093 Closed, 0094 Unknown 0095 }; 0096 Q_ENUM(State) 0097 0098 /** The opening state for this time interval. */ 0099 State state() const; 0100 void setState(State state); 0101 0102 /** Comment. */ 0103 QString comment() const; 0104 void setComment(const QString &comment); 0105 0106 private: 0107 QExplicitlySharedDataPointer<IntervalPrivate> d; 0108 }; 0109 0110 } 0111 0112 Q_DECLARE_METATYPE(KOpeningHours::Interval) 0113 0114 KOPENINGHOURS_EXPORT QDebug operator<<(QDebug debug, const KOpeningHours::Interval &interval); 0115 0116 #endif // KOPENINGHOURS_INTERVAL_H