KOpeningHours

interval.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
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
17class QDateTime;
18
19namespace KOpeningHours {
20
21class IntervalPrivate;
22
23/** A time interval for which an opening hours expression has been evaluated. */
24class 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 Q_PROPERTY(int dstOffset READ dstOffset)
36public:
37 Interval();
38 Interval(const Interval&);
40 ~Interval();
41 Interval& operator=(const Interval&);
42 Interval& operator=(Interval&&);
43
44 /** Check whether this interval starts before @p other. */
45 bool operator<(const Interval &other) const;
46
47 /** Default constructed empty/invalid interval. */
48 bool isValid() const;
49
50 /** Checks whether this interval overlaps with @p other. */
51 bool intersects(const Interval &other) const;
52
53 /** Begin of the interval.
54 * This is the first point in time included in the interval, or invalid if this is an interval with an open begin.
55 */
56 QDateTime begin() const;
57 void setBegin(const QDateTime &begin);
58
59 /** Returns @c true if this is an interval with an open begin, ie. starting at the beginning of time. */
60 bool hasOpenBegin() const;
61
62 /** End of the interval.
63 * This is the first point in time not included in the interval anymore, or invalid for open-ended intervals.
64 * That is, the end of an interval describing the year 2020 would be Jan 1st 2021 at midnight (00:00).
65 */
66 QDateTime end() const;
67 void setEnd(const QDateTime &end);
68
69 /** Returns @c true if this is an interval with an open end date, ie. continuing for all eternity.
70 * @note This is different from an interval with an open end time.
71 */
72 bool hasOpenEnd() const;
73
74 /** Returns @c true if this is an interval with an open end time, ie. an interval generated by a selector like "20:00+".
75 * @note This is different from an interval with an open end.
76 */
77 bool hasOpenEndTime() const;
78 void setOpenEndTime(bool openEndTime);
79
80 /** Returns an estimated end time for intervals with an open end time.
81 * By default this is the same as end() would return, unless higher-level
82 * logic with a view on multiple intervals and/or other context actually sets this.
83 */
84 QDateTime estimatedEnd() const;
85 void setEstimatedEnd(const QDateTime &estimatedEnd);
86
87 /** Returns the UTC offset change between estimatedEnd() and begin().
88 * This is 0, unless there is a DST transition happening in that interval.
89 * @since 23.04.0
90 */
91 int dstOffset() const;
92
93 /** Check if this interval contains @p dt. */
94 bool contains(const QDateTime &dt) const;
95
96 /** Opening state during a time interval */
97 enum State {
98 Invalid,
99 Open,
100 Closed,
101 Unknown
102 };
103 Q_ENUM(State)
104
105 /** The opening state for this time interval. */
106 State state() const;
107 void setState(State state);
108
109 /** Comment. */
110 QString comment() const;
111 void setComment(const QString &comment);
112
113private:
115};
116
117}
118
119Q_DECLARE_METATYPE(KOpeningHours::Interval)
120
121KOPENINGHOURS_EXPORT QDebug operator<<(QDebug debug, const KOpeningHours::Interval &interval);
122
123#endif // KOPENINGHOURS_INTERVAL_H
A time interval for which an opening hours expression has been evaluated.
Definition interval.h:25
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
OSM opening hours parsing and evaluation.
Definition display.h:16
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:58:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.