KOpeningHours

interval.h
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KOPENINGHOURS_INTERVAL_H
8 #define KOPENINGHOURS_INTERVAL_H
9 
10 #include "kopeninghours_export.h"
11 
12 #include <QDateTime>
13 #include <QDebug>
14 #include <QExplicitlySharedDataPointer>
15 #include <QMetaType>
16 
17 class QDateTime;
18 
19 namespace KOpeningHours {
20 
21 class IntervalPrivate;
22 
23 /** A time interval for which an opening hours expression has been evaluated. */
24 class KOPENINGHOURS_EXPORT Interval
25 {
26  Q_GADGET
27  Q_PROPERTY(State state READ state)
28  Q_PROPERTY(QDateTime begin READ begin)
29  Q_PROPERTY(bool hasOpenBegin READ hasOpenBegin)
30  Q_PROPERTY(QDateTime end READ end)
31  Q_PROPERTY(bool hasOpenEnd READ hasOpenEnd)
32  Q_PROPERTY(bool hasOpenEndTime READ hasOpenEndTime)
33  Q_PROPERTY(QString comment READ comment)
34  Q_PROPERTY(QDateTime estimatedEnd READ estimatedEnd)
35 public:
36  Interval();
37  Interval(const Interval&);
38  Interval(Interval&&);
39  ~Interval();
40  Interval& operator=(const Interval&);
41  Interval& operator=(Interval&&);
42 
43  /** Check whether this interval starts before @p other. */
44  bool operator<(const Interval &other) const;
45 
46  /** Default constructed empty/invalid interval. */
47  bool isValid() const;
48 
49  /** Checks whether this interval overlaps with @p other. */
50  bool intersects(const Interval &other) const;
51 
52  /** Begin of the interval.
53  * This is the first point in time included in the interval, or invalid if this is an interval with an open begin.
54  */
55  QDateTime begin() const;
56  void setBegin(const QDateTime &begin);
57 
58  /** Returns @c true if this is an interval with an open begin, ie. starting at the beginning of time. */
59  bool hasOpenBegin() const;
60 
61  /** End of the interval.
62  * This is the first point in time not included in the interval anymore, or invalid for open-ended intervals.
63  * That is, the end of an interval describing the year 2020 would be Jan 1st 2021 at midnight (00:00).
64  */
65  QDateTime end() const;
66  void setEnd(const QDateTime &end);
67 
68  /** Returns @c true if this is an interval with an open end date, ie. continuing for all eternity.
69  * @note This is different from an interval with an open end time.
70  */
71  bool hasOpenEnd() const;
72 
73  /** Returns @c true if this is an interval with an open end time, ie. an interval generated by a selector like "20:00+".
74  * @note This is different from an interval with an open end.
75  */
76  bool hasOpenEndTime() const;
77  void setOpenEndTime(bool openEndTime);
78 
79  /** Returns an estimated end time for intervals with an open end time.
80  * By default this is the same as end() would return, unless higher-level
81  * logic with a view on multiple intervals and/or other context actually sets this.
82  */
83  QDateTime estimatedEnd() const;
84  void setEstimatedEnd(const QDateTime &estimatedEnd);
85 
86  /** Check if this interval contains @p dt. */
87  bool contains(const QDateTime &dt) const;
88 
89  /** Opening state during a time interval */
90  enum State {
91  Invalid,
92  Open,
93  Closed,
94  Unknown
95  };
96  Q_ENUM(State)
97 
98  /** The opening state for this time interval. */
99  State state() const;
100  void setState(State state);
101 
102  /** Comment. */
103  QString comment() const;
104  void setComment(const QString &comment);
105 
106 private:
108 };
109 
110 }
111 
112 Q_DECLARE_METATYPE(KOpeningHours::Interval)
113 
114 KOPENINGHOURS_EXPORT QDebug operator<<(QDebug debug, const KOpeningHours::Interval &interval);
115 
116 #endif // KOPENINGHOURS_INTERVAL_H
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
OSM opening hours parsing and evaluation.
Definition: display.h:14
A time interval for which an opening hours expression has been evaluated.
Definition: interval.h:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 04:07:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.