Debian Codegraph @

t/samples/kdelibs/daterange.h

raw symbols SCIP
1 /*
2
3 **ANALIZO NOTE**
4
5 This file was copied from kdelibs project for testing analizo features.
6
7 The original file was copied as-is to create automated tests on analizo side
8 fixing the bug below.
9
10 - https://github.com/analizo/analizo/issues/148
11
12 GitHub kdelibs repository:
13
14 - https://github.com/KDE/kdelibs.git
15
16 Original file was copied from the commit 668ef94b2b from kdelibs git repository
17 and it is located inside kdelibs repository on the path below.
18
19 - nepomuk/utils/daterange.h
20
21 Link to the original file on GitHub:
22
23 - https://github.com/KDE/kdelibs/blob/668ef94b2b861f7ec4aa20941bcb6493bc4367be/nepomuk/utils/daterange.h
24
25 */
26
27 /*
28 Copyright (c) 2009-2010 Sebastian Trueg <[email protected]>
29
30 This program is free software; you can redistribute it and/or
31 modify it under the terms of the GNU General Public License as
32 published by the Free Software Foundation; either version 2 of
33 the License or (at your option) version 3 or any later version
34 accepted by the membership of KDE e.V. (or its successor approved
35 by the membership of KDE e.V.), which shall act as a proxy
36 defined in Section 14 of version 3 of the license.
37
38 This program is distributed in the hope that it will be useful,
39 but WITHOUT ANY WARRANTY; without even the implied warranty of
40 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 GNU General Public License for more details.
42
43 You should have received a copy of the GNU General Public License
44 along with this program. If not, see <http://www.gnu.org/licenses/>.
45
46 */
47
48 #ifndef _DATE_RANGE_H_
49 #define _DATE_RANGE_H_
50
51 #include <QtCore/QDate>
52 #include <QtCore/QSharedDataPointer>
53
54 class QDebug;
55
56 /**
57 * \class DateRange daterange.h DateRange
58 *
59 * \brief A simple data structure storing a start and an end date.
60 *
61 * %DateRange is a very simple data structure storing a start and an end date.
62 * The really interesting parts are the static factory methods which take the
63 * current calendar system into account and, thus, create accurate values.
64 *
65 * \author Sebastian Trueg <[email protected]>
66 */
67 class DateRange
68 {
69 public:
70 /**
71 * Create a new range
72 */
73 DateRange( const QDate& s = QDate(),
74 const QDate& e = QDate() );
75
76 /**
77 * Copy constructor
78 */
79 DateRange( const DateRange& other );
80
81 /**
82 * Destructor
83 */
84 ~DateRange();
85
86 /**
87 * Make this range a copy of \p other
88 */
89 DateRange& operator=( const DateRange& other );
90
91 /**
92 * Start date of the range.
93 */
94 QDate start() const;
95
96 /**
97 * End date of the range.
98 */
99 QDate end() const;
100
101 /**
102 * Checks if both start and end are valid dates
103 * and if end is after start.
104 */
105 bool isValid() const;
106
107 /**
108 * Set the start to \p date.
109 */
110 void setStart( const QDate& date );
111
112 /**
113 * Set the end to \p date.
114 */
115 void setEnd( const QDate& date );
116
117 /**
118 * \returns a DateRange with both start and end
119 * dates set to QDate::currentDate()
120 */
121 static DateRange today();
122
123 /**
124 * The flags allow to change the result returned by several of the
125 * static factory methods provided by DateRange such as thisWeek()
126 * or thisMonth().
127 */
128 enum DateRangeFlag {
129 /**
130 * No flags.
131 */
132 NoDateRangeFlags = 0x0,
133
134 /**
135 * Exclude days that are in the future. thisWeek() for example
136 * will not include the days in the week that come after the current
137 * day.
138 */
139 ExcludeFutureDays = 0x1
140 };
141 Q_DECLARE_FLAGS( DateRangeFlags, DateRangeFlag )
142
143 /**
144 * Takes KLocale::weekStartDay() into account.
145 * \sa DateRangeFlag
146 */
147 static DateRange thisWeek( DateRangeFlags flags = NoDateRangeFlags );
148
149 /**
150 * Takes KLocale::weekStartDay() into account.
151 * \param flags ExcludeFutureDays does only makes sense for a date in the current week. For
152 * future weeks it is ignored.
153 * \sa DateRangeFlag
154 */
155 static DateRange weekOf( const QDate& date, DateRangeFlags flags = NoDateRangeFlags );
156
157 /**
158 * \return A DateRange which includes all days of the current month.
159 *
160 * \sa DateRangeFlag
161 */
162 static DateRange thisMonth( DateRangeFlags flags = NoDateRangeFlags );
163
164 /**
165 * \param flags ExcludeFutureDays does only makes sense for a date in the current month. For
166 * future months it is ignored.
167 * \return A DateRange which includes all days of the month in which
168 * \p date falls.
169 * \sa DateRangeFlag
170 */
171 static DateRange monthOf( const QDate& date, DateRangeFlags flags = NoDateRangeFlags );
172
173 /**
174 * \return A DateRange which includes all days of the current year.
175 * \sa DateRangeFlag
176 */
177 static DateRange thisYear( DateRangeFlags flags = NoDateRangeFlags );
178
179 /**
180 * \param flags ExcludeFutureDays does only makes sense for a date in the current year. For
181 * future years it is ignored.
182 * \return A DateRange which includes all days of the year in which
183 * \p date falls.
184 * \sa DateRangeFlags
185 */
186 static DateRange yearOf( const QDate& date, DateRangeFlags flags = NoDateRangeFlags );
187
188 /**
189 * \return A DateRange which spans the last \p n days.
190 */
191 static DateRange lastNDays( int n );
192
193 /**
194 * \return A DateRange which spans the last \p n weeks,
195 * including the already passed days in the current week.
196 */
197 static DateRange lastNWeeks( int n );
198
199 /**
200 * \return A DateRange which spans the last \p n months,
201 * including the already passed days in the current month.
202 */
203 static DateRange lastNMonths( int n );
204
205 private:
206 class Private;
207 QSharedDataPointer<Private> d;
208 };
209
210 /**
211 * Comparison operator
212 *
213 * \related DateRange
214 */
215 bool operator==( const DateRange& r1, const DateRange& r2 );
216
217 /**
218 * Comparison operator
219 *
220 * \related DateRange
221 */
222 bool operator!=( const DateRange& r1, const DateRange& r2 );
223
224 /**
225 * Allows using DateRange in hashed structures such as QHash or QMap.
226 *
227 * \related DateRange
228 */
229 uint qHash( const DateRange& range );
230
231 /**
232 * Debug streaming operator
233 *
234 * \relates DateRange
235 */
236 QDebug operator<<( QDebug dbg, const DateRange& range );
237
238 Q_DECLARE_OPERATORS_FOR_FLAGS( DateRange::DateRangeFlags )
239
240 #endif