Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qdatetime.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | namespace { namespace Q_QGS_defaultDateTimePrivate { typedef QSharedDataPointer<QDateTimePrivate> Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
executed 326 times by 128 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 326 times by 128 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type (new QDateTimePrivate()))) : value (new QDateTimePrivate()) { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 7100330 times by 127 tests: &holder.value;return &holder.value; Executed by:
executed 7100330 times by 127 tests: } } } static QGlobalStatic<QSharedDataPointer<QDateTimePrivate>, Q_QGS_defaultDateTimePrivate::innerFunction, Q_QGS_defaultDateTimePrivate::guard> defaultDateTimePrivate;return &holder.value; Executed by:
| 0-7100330 | ||||||||||||||||||||||||
9 | - | |||||||||||||||||||||||||
10 | - | |||||||||||||||||||||||||
11 | - | |||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||
14 | enum { | - | ||||||||||||||||||||||||
15 | SECS_PER_DAY = 86400, | - | ||||||||||||||||||||||||
16 | MSECS_PER_DAY = 86400000, | - | ||||||||||||||||||||||||
17 | SECS_PER_HOUR = 3600, | - | ||||||||||||||||||||||||
18 | MSECS_PER_HOUR = 3600000, | - | ||||||||||||||||||||||||
19 | SECS_PER_MIN = 60, | - | ||||||||||||||||||||||||
20 | MSECS_PER_MIN = 60000, | - | ||||||||||||||||||||||||
21 | TIME_T_MAX = 2145916799, | - | ||||||||||||||||||||||||
22 | JULIAN_DAY_FOR_EPOCH = 2440588 | - | ||||||||||||||||||||||||
23 | }; | - | ||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||
25 | - | |||||||||||||||||||||||||
26 | - | |||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | static inline QDate fixedDate(int y, int m, int d) | - | ||||||||||||||||||||||||
30 | { | - | ||||||||||||||||||||||||
31 | QDate result(y, m, 1); | - | ||||||||||||||||||||||||
32 | result.setDate(y, m, qMin(d, result.daysInMonth())); | - | ||||||||||||||||||||||||
33 | return result; | - | ||||||||||||||||||||||||
34 | } | - | ||||||||||||||||||||||||
35 | static inline qint64 floordiv(qint64 a, int b) | - | ||||||||||||||||||||||||
36 | { | - | ||||||||||||||||||||||||
37 | return executed 96372952 times by 106 tests: (a - (a % b< 0 ? b - 1 : 0)) / b;return (a - (a < 0 ? b - 1 : 0)) / b; Executed by:
executed 96372952 times by 106 tests: return (a - (a < 0 ? b - 1 : 0)) / b; Executed by:
| 96372952 | ||||||||||||||||||||||||
38 | } | - | ||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | static inline int floordiv(int a, int b) | - | ||||||||||||||||||||||||
41 | { | - | ||||||||||||||||||||||||
42 | return executed 138065546 times by 106 tests: (a - (a % b< 0 ? b - 1 : 0)) / b;return (a - (a < 0 ? b - 1 : 0)) / b; Executed by:
executed 138065546 times by 106 tests: return (a - (a < 0 ? b - 1 : 0)) / b; Executed by:
| 138065546 | ||||||||||||||||||||||||
43 | } | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | static inline qint64 julianDayFromDate(int year, int month, int day) | - | ||||||||||||||||||||||||
46 | { | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | if (year < 0) | - | ||||||||||||||||||||||||
49 | ++year; | - | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | - | |||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | int a = floordiv(14 - month, 12); | - | ||||||||||||||||||||||||
57 | qint64 y = (qint64)year + 4800 - a; | - | ||||||||||||||||||||||||
58 | int m = month + 12 * a - 3; | - | ||||||||||||||||||||||||
59 | return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045; | - | ||||||||||||||||||||||||
60 | } | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | struct ParsedDate | - | ||||||||||||||||||||||||
63 | { | - | ||||||||||||||||||||||||
64 | int year, month, day; | - | ||||||||||||||||||||||||
65 | }; | - | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | __attribute__((noinline)) | - | ||||||||||||||||||||||||
69 | static ParsedDate getDateFromJulianDay(qint64 julianDay) | - | ||||||||||||||||||||||||
70 | { | - | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | qint64 a = julianDay + 32044; | - | ||||||||||||||||||||||||
77 | qint64 b = floordiv(4 * a + 3, 146097); | - | ||||||||||||||||||||||||
78 | int c = a - floordiv(146097 * b, 4); | - | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | int d = floordiv(4 * c + 3, 1461); | - | ||||||||||||||||||||||||
81 | int e = c - floordiv(1461 * d, 4); | - | ||||||||||||||||||||||||
82 | int m = floordiv(5 * e + 2, 153); | - | ||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | int day = e - floordiv(153 * m + 2, 5) + 1; | - | ||||||||||||||||||||||||
85 | int month = m + 3 - 12 * floordiv(m, 10); | - | ||||||||||||||||||||||||
86 | int year = 100 * b + d - 4800 + floordiv(m, 10); | - | ||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | if (year <= 0) | - | ||||||||||||||||||||||||
90 | --year ; | - | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | const ParsedDate result = { year, month, day }; | - | ||||||||||||||||||||||||
93 | return result; | - | ||||||||||||||||||||||||
94 | } | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | - | |||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||
98 | - | |||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | static const char monthDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | - | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||
103 | static const char qt_shortMonthNames[][4] = { | - | ||||||||||||||||||||||||
104 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | - | ||||||||||||||||||||||||
105 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | static int qt_monthNumberFromShortName(QStringRef shortName) | - | ||||||||||||||||||||||||
108 | { | - | ||||||||||||||||||||||||
109 | for (unsigned int i = 0; i < sizeof(qt_shortMonthNames) / sizeof(qt_shortMonthNames[0]); ++i) { | - | ||||||||||||||||||||||||
110 | if (shortName == QLatin1String(qt_shortMonthNames[i], 3)) | - | ||||||||||||||||||||||||
111 | return i + 1; | - | ||||||||||||||||||||||||
112 | } | - | ||||||||||||||||||||||||
113 | return -1; | - | ||||||||||||||||||||||||
114 | } | - | ||||||||||||||||||||||||
115 | static int qt_monthNumberFromShortName(const QString &shortName) | - | ||||||||||||||||||||||||
116 | { return qt_monthNumberFromShortName(QStringRef(&shortName)); } | - | ||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | static int fromShortMonthName(const QStringRef &monthName) | - | ||||||||||||||||||||||||
119 | { | - | ||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||
121 | int month = qt_monthNumberFromShortName(monthName); | - | ||||||||||||||||||||||||
122 | if (month != -1) | - | ||||||||||||||||||||||||
123 | return month; | - | ||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | for (int i = 1; i <= 12; ++i) { | - | ||||||||||||||||||||||||
126 | if (monthName == QDate::shortMonthName(i)) | - | ||||||||||||||||||||||||
127 | return i; | - | ||||||||||||||||||||||||
128 | } | - | ||||||||||||||||||||||||
129 | return -1; | - | ||||||||||||||||||||||||
130 | } | - | ||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||
132 | - | |||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||
134 | struct ParsedRfcDateTime { | - | ||||||||||||||||||||||||
135 | QDate date; | - | ||||||||||||||||||||||||
136 | QTime time; | - | ||||||||||||||||||||||||
137 | int utcOffset; | - | ||||||||||||||||||||||||
138 | }; | - | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | static ParsedRfcDateTime rfcDateImpl(const QString &s) | - | ||||||||||||||||||||||||
141 | { | - | ||||||||||||||||||||||||
142 | ParsedRfcDateTime result; | - | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | QRegExp rex(([]() -> QString { enum { Size = sizeof(u"" "^(?:[A-Z][a-z]+,)?[ \\t]*(\\d{1,2})[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d)(?::(\\d\\d))?)?[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "^(?:[A-Z][a-z]+,)?[ \\t]*(\\d{1,2})[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d)(?::(\\d\\d))?)?[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||||||||
146 | if (s.indexOf(rex) == 0) { | - | ||||||||||||||||||||||||
147 | const QStringList cap = rex.capturedTexts(); | - | ||||||||||||||||||||||||
148 | result.date = QDate(cap[3].toInt(), qt_monthNumberFromShortName(cap[2]), cap[1].toInt()); | - | ||||||||||||||||||||||||
149 | if (!cap[4].isEmpty()) | - | ||||||||||||||||||||||||
150 | result.time = QTime(cap[4].toInt(), cap[5].toInt(), cap[6].toInt()); | - | ||||||||||||||||||||||||
151 | const bool positiveOffset = (cap[7] == QLatin1String("+")); | - | ||||||||||||||||||||||||
152 | const int hourOffset = cap[8].toInt(); | - | ||||||||||||||||||||||||
153 | const int minOffset = cap[9].toInt(); | - | ||||||||||||||||||||||||
154 | result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); | - | ||||||||||||||||||||||||
155 | } else { | - | ||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||
157 | QRegExp rex(([]() -> QString { enum { Size = sizeof(u"" "^[A-Z][a-z]+[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d):(\\d\\d))?[ \\t]+(\\d\\d\\d\\d)[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "^[A-Z][a-z]+[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d):(\\d\\d))?[ \\t]+(\\d\\d\\d\\d)[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||||||||
158 | if (s.indexOf(rex) == 0) { | - | ||||||||||||||||||||||||
159 | const QStringList cap = rex.capturedTexts(); | - | ||||||||||||||||||||||||
160 | result.date = QDate(cap[6].toInt(), qt_monthNumberFromShortName(cap[1]), cap[2].toInt()); | - | ||||||||||||||||||||||||
161 | if (!cap[3].isEmpty()) | - | ||||||||||||||||||||||||
162 | result.time = QTime(cap[3].toInt(), cap[4].toInt(), cap[5].toInt()); | - | ||||||||||||||||||||||||
163 | const bool positiveOffset = (cap[7] == QLatin1String("+")); | - | ||||||||||||||||||||||||
164 | const int hourOffset = cap[8].toInt(); | - | ||||||||||||||||||||||||
165 | const int minOffset = cap[9].toInt(); | - | ||||||||||||||||||||||||
166 | result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); | - | ||||||||||||||||||||||||
167 | } | - | ||||||||||||||||||||||||
168 | } | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | return result; | - | ||||||||||||||||||||||||
171 | } | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | static QString toOffsetString(Qt::DateFormat format, int offset) | - | ||||||||||||||||||||||||
176 | { | - | ||||||||||||||||||||||||
177 | return QString::asprintf("%c%02d%s%02d", | - | ||||||||||||||||||||||||
178 | offset >= 0 ? '+' : '-', | - | ||||||||||||||||||||||||
179 | qAbs(offset) / SECS_PER_HOUR, | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | format == Qt::TextDate ? "" : ":", | - | ||||||||||||||||||||||||
182 | (qAbs(offset) / 60) % 60); | - | ||||||||||||||||||||||||
183 | } | - | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||
186 | static int fromOffsetString(const QStringRef &offsetString, bool *valid) noexcept | - | ||||||||||||||||||||||||
187 | { | - | ||||||||||||||||||||||||
188 | *valid = false; | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | const int size = offsetString.size(); | - | ||||||||||||||||||||||||
191 | if (size < 2
| 0-22 | ||||||||||||||||||||||||
192 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | int sign; | - | ||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | const QChar signChar = offsetString.at(0); | - | ||||||||||||||||||||||||
199 | if (signChar == QLatin1Char('+')
| 11 | ||||||||||||||||||||||||
200 | sign = 1; executed 11 times by 1 test: sign = 1; Executed by:
| 11 | ||||||||||||||||||||||||
201 | else if (signChar == QLatin1Char('-')
| 1-10 | ||||||||||||||||||||||||
202 | sign = -1; executed 10 times by 1 test: sign = -1; Executed by:
| 10 | ||||||||||||||||||||||||
203 | else | - | ||||||||||||||||||||||||
204 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | - | |||||||||||||||||||||||||
207 | QVector<const QStringRef > partstime = offsetString.mid(1).split); | - | ||||||||||||||||||||||||
208 | int hhLen = time.indexOf(QLatin1Char(':')); | - | ||||||||||||||||||||||||
209 | int mmIndex; | - | ||||||||||||||||||||||||
210 | if (parts.count()hhLen
| 8-13 | ||||||||||||||||||||||||
211 | { | 13 | ||||||||||||||||||||||||
parts.append(parts.first().mid(mmIndex = hhLen = executed 13 times by 1 test: 2));mmIndex = hhLen = 2; Executed by:
executed 13 times by 1 test: mmIndex = hhLen = 2; Executed by:
| ||||||||||||||||||||||||||
parts[0] executed 13 times by 1 test: mmIndex = hhLen = 2; Executed by:
executed 13 times by 1 test: ;mmIndex = hhLen = 2; Executed by:
executed 13 times by 1 test: mmIndex = hhLen = 2; Executed by:
| ||||||||||||||||||||||||||
212 | else | - | ||||||||||||||||||||||||
213 | mmIndex executed 8 times by 1 test: mmIndex = hhLen + 1; Executed by:
executed 8 times by 1 test: = partshhLen + 1;mmIndex = hhLen + 1; Executed by:
executed 8 times by 1 test: mmIndex = hhLen + 1; Executed by:
| 8 | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | const QStringRef hhRef = time.first().left(2hhLen); | - | ||||||||||||||||||||||||
216 | }bool ok = false; | - | ||||||||||||||||||||||||
217 | const int hour = partshhRef.first().toInt(&ok); | - | ||||||||||||||||||||||||
218 | if (!ok
| 2-19 | ||||||||||||||||||||||||
219 | return executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||
221 | const QStringRef mmRef = time.mid(mmIndex); | - | ||||||||||||||||||||||||
222 | const int minute = (partsmmRef
| 4-15 | ||||||||||||||||||||||||
223 | if (!ok
| 0-18 | ||||||||||||||||||||||||
224 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||
226 | *valid = true; | - | ||||||||||||||||||||||||
227 | return executed 18 times by 1 test: sign * ((hour * 60) + minute) * 60;return sign * ((hour * 60) + minute) * 60; Executed by:
executed 18 times by 1 test: return sign * ((hour * 60) + minute) * 60; Executed by:
| 18 | ||||||||||||||||||||||||
228 | } | - | ||||||||||||||||||||||||
229 | QDate::QDate(int y, int m, int d) | - | ||||||||||||||||||||||||
230 | { | - | ||||||||||||||||||||||||
231 | setDate(y, m, d); | - | ||||||||||||||||||||||||
232 | } | - | ||||||||||||||||||||||||
233 | int QDate::year() const | - | ||||||||||||||||||||||||
234 | { | - | ||||||||||||||||||||||||
235 | if (isNull()) | - | ||||||||||||||||||||||||
236 | return 0; | - | ||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||
238 | return getDateFromJulianDay(jd).year; | - | ||||||||||||||||||||||||
239 | } | - | ||||||||||||||||||||||||
240 | int QDate::month() const | - | ||||||||||||||||||||||||
241 | { | - | ||||||||||||||||||||||||
242 | if (isNull()) | - | ||||||||||||||||||||||||
243 | return 0; | - | ||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||
245 | return getDateFromJulianDay(jd).month; | - | ||||||||||||||||||||||||
246 | } | - | ||||||||||||||||||||||||
247 | int QDate::day() const | - | ||||||||||||||||||||||||
248 | { | - | ||||||||||||||||||||||||
249 | if (isNull()) | - | ||||||||||||||||||||||||
250 | return 0; | - | ||||||||||||||||||||||||
251 | - | |||||||||||||||||||||||||
252 | return getDateFromJulianDay(jd).day; | - | ||||||||||||||||||||||||
253 | } | - | ||||||||||||||||||||||||
254 | int QDate::dayOfWeek() const | - | ||||||||||||||||||||||||
255 | { | - | ||||||||||||||||||||||||
256 | if (isNull()) | - | ||||||||||||||||||||||||
257 | return 0; | - | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | if (jd >= 0) | - | ||||||||||||||||||||||||
260 | return (jd % 7) + 1; | - | ||||||||||||||||||||||||
261 | else | - | ||||||||||||||||||||||||
262 | return ((jd + 1) % 7) + 7; | - | ||||||||||||||||||||||||
263 | } | - | ||||||||||||||||||||||||
264 | int QDate::dayOfYear() const | - | ||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||
266 | if (isNull()) | - | ||||||||||||||||||||||||
267 | return 0; | - | ||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||
269 | return jd - julianDayFromDate(year(), 1, 1) + 1; | - | ||||||||||||||||||||||||
270 | } | - | ||||||||||||||||||||||||
271 | int QDate::daysInMonth() const | - | ||||||||||||||||||||||||
272 | { | - | ||||||||||||||||||||||||
273 | if (isNull()) | - | ||||||||||||||||||||||||
274 | return 0; | - | ||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||
276 | const ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||
277 | if (pd.month == 2 && isLeapYear(pd.year)) | - | ||||||||||||||||||||||||
278 | return 29; | - | ||||||||||||||||||||||||
279 | else | - | ||||||||||||||||||||||||
280 | return monthDays[pd.month]; | - | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
282 | int QDate::daysInYear() const | - | ||||||||||||||||||||||||
283 | { | - | ||||||||||||||||||||||||
284 | if (isNull()) | - | ||||||||||||||||||||||||
285 | return 0; | - | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365; | - | ||||||||||||||||||||||||
288 | } | - | ||||||||||||||||||||||||
289 | int QDate::weekNumber(int *yearNumber) const | - | ||||||||||||||||||||||||
290 | { | - | ||||||||||||||||||||||||
291 | if (!isValid()) | - | ||||||||||||||||||||||||
292 | return 0; | - | ||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||
294 | int year = QDate::year(); | - | ||||||||||||||||||||||||
295 | int yday = dayOfYear(); | - | ||||||||||||||||||||||||
296 | int wday = dayOfWeek(); | - | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | int week = (yday - wday + 10) / 7; | - | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | if (week == 0) { | - | ||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||
302 | --year; | - | ||||||||||||||||||||||||
303 | week = (yday + 365 + (QDate::isLeapYear(year) ? 1 : 0) - wday + 10) / 7; | - | ||||||||||||||||||||||||
304 | ((!(week == 52 || week == 53)) ? qt_assert("week == 52 || week == 53",__FILE__,594602) : qt_noop()); | - | ||||||||||||||||||||||||
305 | } else if (week == 53) { | - | ||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | int w = (yday - 365 - (QDate::isLeapYear(year) ? 1 : 0) - wday + 10) / 7; | - | ||||||||||||||||||||||||
308 | if (w > 0) { | - | ||||||||||||||||||||||||
309 | ++year; | - | ||||||||||||||||||||||||
310 | week = w; | - | ||||||||||||||||||||||||
311 | } | - | ||||||||||||||||||||||||
312 | ((!(week == 53 || week == 1)) ? qt_assert("week == 53 || week == 1",__FILE__,602610) : qt_noop()); | - | ||||||||||||||||||||||||
313 | } | - | ||||||||||||||||||||||||
314 | - | |||||||||||||||||||||||||
315 | if (yearNumber != 0) | - | ||||||||||||||||||||||||
316 | *yearNumber = year; | - | ||||||||||||||||||||||||
317 | return week; | - | ||||||||||||||||||||||||
318 | } | - | ||||||||||||||||||||||||
319 | QString QDate::shortMonthName(int month, QDate::MonthNameType type) | - | ||||||||||||||||||||||||
320 | { | - | ||||||||||||||||||||||||
321 | if (month >= 1 || month <= 12) { | - | ||||||||||||||||||||||||
322 | switch (type) { | - | ||||||||||||||||||||||||
323 | case QDate::DateFormat: | - | ||||||||||||||||||||||||
324 | return QLocale::system().monthName(month, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
325 | case QDate::StandaloneFormat: | - | ||||||||||||||||||||||||
326 | return QLocale::system().standaloneMonthName(month, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
327 | } | - | ||||||||||||||||||||||||
328 | } | - | ||||||||||||||||||||||||
329 | return QString(); | - | ||||||||||||||||||||||||
330 | } | - | ||||||||||||||||||||||||
331 | QString QDate::longMonthName(int month, MonthNameType type) | - | ||||||||||||||||||||||||
332 | { | - | ||||||||||||||||||||||||
333 | if (month >= 1 && month <= 12) { | - | ||||||||||||||||||||||||
334 | switch (type) { | - | ||||||||||||||||||||||||
335 | case QDate::DateFormat: | - | ||||||||||||||||||||||||
336 | return QLocale::system().monthName(month, QLocale::LongFormat); | - | ||||||||||||||||||||||||
337 | case QDate::StandaloneFormat: | - | ||||||||||||||||||||||||
338 | return QLocale::system().standaloneMonthName(month, QLocale::LongFormat); | - | ||||||||||||||||||||||||
339 | } | - | ||||||||||||||||||||||||
340 | } | - | ||||||||||||||||||||||||
341 | return QString(); | - | ||||||||||||||||||||||||
342 | } | - | ||||||||||||||||||||||||
343 | QString QDate::shortDayName(int weekday, MonthNameType type) | - | ||||||||||||||||||||||||
344 | { | - | ||||||||||||||||||||||||
345 | if (weekday >= 1 && weekday <= 7) { | - | ||||||||||||||||||||||||
346 | switch (type) { | - | ||||||||||||||||||||||||
347 | case QDate::DateFormat: | - | ||||||||||||||||||||||||
348 | return QLocale::system().dayName(weekday, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
349 | case QDate::StandaloneFormat: | - | ||||||||||||||||||||||||
350 | return QLocale::system().standaloneDayName(weekday, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||
352 | } | - | ||||||||||||||||||||||||
353 | return QString(); | - | ||||||||||||||||||||||||
354 | } | - | ||||||||||||||||||||||||
355 | QString QDate::longDayName(int weekday, MonthNameType type) | - | ||||||||||||||||||||||||
356 | { | - | ||||||||||||||||||||||||
357 | if (weekday >= 1 && weekday <= 7) { | - | ||||||||||||||||||||||||
358 | switch (type) { | - | ||||||||||||||||||||||||
359 | case QDate::DateFormat: | - | ||||||||||||||||||||||||
360 | return QLocale::system().dayName(weekday, QLocale::LongFormat); | - | ||||||||||||||||||||||||
361 | case QDate::StandaloneFormat: | - | ||||||||||||||||||||||||
362 | return QLocale::system().standaloneDayName(weekday, QLocale::LongFormat); | - | ||||||||||||||||||||||||
363 | } | - | ||||||||||||||||||||||||
364 | } | - | ||||||||||||||||||||||||
365 | return QString(); | - | ||||||||||||||||||||||||
366 | } | - | ||||||||||||||||||||||||
367 | - | |||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||
370 | - | |||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||
372 | static QString toStringTextDate(QDate date) | - | ||||||||||||||||||||||||
373 | { | - | ||||||||||||||||||||||||
374 | const ParsedDate pd = getDateFromJulianDay(date.toJulianDay()); | - | ||||||||||||||||||||||||
375 | static const QLatin1Char sp(' '); | - | ||||||||||||||||||||||||
376 | return date.shortDayName(date.dayOfWeek()) + sp | - | ||||||||||||||||||||||||
377 | + date.shortMonthName(pd.month) + sp | - | ||||||||||||||||||||||||
378 | + QString::number(pd.day) + sp | - | ||||||||||||||||||||||||
379 | + QString::number(pd.year); | - | ||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||
383 | static QString toStringIsoDate(qint64 jd) | - | ||||||||||||||||||||||||
384 | { | - | ||||||||||||||||||||||||
385 | const ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||
386 | if (pd.year >= 0 && pd.year <= 9999) | - | ||||||||||||||||||||||||
387 | return QString::asprintf("%04d-%02d-%02d", pd.year, pd.month, pd.day); | - | ||||||||||||||||||||||||
388 | else | - | ||||||||||||||||||||||||
389 | return QString(); | - | ||||||||||||||||||||||||
390 | } | - | ||||||||||||||||||||||||
391 | QString QDate::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||
392 | { | - | ||||||||||||||||||||||||
393 | if (!isValid()) | - | ||||||||||||||||||||||||
394 | return QString(); | - | ||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||
396 | switch (format) { | - | ||||||||||||||||||||||||
397 | case Qt::SystemLocaleDate: | - | ||||||||||||||||||||||||
398 | case Qt::SystemLocaleShortDate: | - | ||||||||||||||||||||||||
399 | return QLocale::system().toString(*this, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
400 | case Qt::SystemLocaleLongDate: | - | ||||||||||||||||||||||||
401 | return QLocale::system().toString(*this, QLocale::LongFormat); | - | ||||||||||||||||||||||||
402 | case Qt::LocaleDate: | - | ||||||||||||||||||||||||
403 | case Qt::DefaultLocaleShortDate: | - | ||||||||||||||||||||||||
404 | return QLocale().toString(*this, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
405 | case Qt::DefaultLocaleLongDate: | - | ||||||||||||||||||||||||
406 | return QLocale().toString(*this, QLocale::LongFormat); | - | ||||||||||||||||||||||||
407 | case Qt::RFC2822Date: | - | ||||||||||||||||||||||||
408 | return QLocale::c().toString(*this, ([]() -> QString { enum { Size = sizeof(u"" "dd MMM yyyy")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "dd MMM yyyy" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||||||||
409 | default: | - | ||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||
411 | case Qt::TextDate: | - | ||||||||||||||||||||||||
412 | return toStringTextDate(*this); | - | ||||||||||||||||||||||||
413 | - | |||||||||||||||||||||||||
414 | case Qt::ISODate: | - | ||||||||||||||||||||||||
415 | return toStringIsoDate(jd); | - | ||||||||||||||||||||||||
416 | } | - | ||||||||||||||||||||||||
417 | } | - | ||||||||||||||||||||||||
418 | QString QDate::toString(const QString& format) const | - | ||||||||||||||||||||||||
419 | { | - | ||||||||||||||||||||||||
420 | return QLocale::system().toString(*this, format); | - | ||||||||||||||||||||||||
421 | } | - | ||||||||||||||||||||||||
422 | bool QDate::setDate(int year, int month, int day) | - | ||||||||||||||||||||||||
423 | { | - | ||||||||||||||||||||||||
424 | if (isValid(year, month, day)) | - | ||||||||||||||||||||||||
425 | jd = julianDayFromDate(year, month, day); | - | ||||||||||||||||||||||||
426 | else | - | ||||||||||||||||||||||||
427 | jd = nullJd(); | - | ||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||
429 | return isValid(); | - | ||||||||||||||||||||||||
430 | } | - | ||||||||||||||||||||||||
431 | void QDate::getDate(int *year, int *month, int *day) const | - | ||||||||||||||||||||||||
432 | { | - | ||||||||||||||||||||||||
433 | ParsedDate pd = { 0, 0, 0 }; | - | ||||||||||||||||||||||||
434 | if (isValid()
| 3-13951235 | ||||||||||||||||||||||||
435 | pd = getDateFromJulianDay(jd); executed 13956030 times by 101 tests: pd = getDateFromJulianDay(jd); Executed by:
| 13956030 | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | if (year
| 3-13956030 | ||||||||||||||||||||||||
438 | * executed 13956030 times by 101 tests: year = pd.year;*year = pd.year; Executed by:
executed 13956030 times by 101 tests: *year = pd.year; Executed by:
| 13956030 | ||||||||||||||||||||||||
439 | if (month
| 3-13955044 | ||||||||||||||||||||||||
440 | * executed 13956030 times by 101 tests: month = pd.month;*month = pd.month; Executed by:
executed 13956030 times by 101 tests: *month = pd.month; Executed by:
| 13956030 | ||||||||||||||||||||||||
441 | if (day
| 3-13942777 | ||||||||||||||||||||||||
442 | * executed 13954660 times by 101 tests: day = pd.day;*day = pd.day; Executed by:
executed 13954660 times by 101 tests: *day = pd.day; Executed by:
| 13954660 | ||||||||||||||||||||||||
443 | } executed 13941005 times by 101 tests: end of block Executed by:
| 13941005 | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | - | |||||||||||||||||||||||||
446 | - | |||||||||||||||||||||||||
447 | - | |||||||||||||||||||||||||
448 | - | |||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||
450 | void QDate::getDate(int *year, int *month, int *day) | - | ||||||||||||||||||||||||
451 | { | - | ||||||||||||||||||||||||
452 | qAsConst(*this).getDate(year, month, day); | - | ||||||||||||||||||||||||
453 | } executed 13947892 times by 101 tests: end of block Executed by:
| 13947892 | ||||||||||||||||||||||||
454 | QDate QDate::addDays(qint64 ndays) const | - | ||||||||||||||||||||||||
455 | { | - | ||||||||||||||||||||||||
456 | if (isNull()) | - | ||||||||||||||||||||||||
457 | return QDate(); | - | ||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||
461 | return fromJulianDay(jd + ndays); | - | ||||||||||||||||||||||||
462 | } | - | ||||||||||||||||||||||||
463 | QDate QDate::addMonths(int nmonths) const | - | ||||||||||||||||||||||||
464 | { | - | ||||||||||||||||||||||||
465 | if (!isValid()) | - | ||||||||||||||||||||||||
466 | return QDate(); | - | ||||||||||||||||||||||||
467 | if (!nmonths) | - | ||||||||||||||||||||||||
468 | return *this; | - | ||||||||||||||||||||||||
469 | - | |||||||||||||||||||||||||
470 | int old_y, y, m, d; | - | ||||||||||||||||||||||||
471 | { | - | ||||||||||||||||||||||||
472 | const ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||
473 | y = pd.year; | - | ||||||||||||||||||||||||
474 | m = pd.month; | - | ||||||||||||||||||||||||
475 | d = pd.day; | - | ||||||||||||||||||||||||
476 | } | - | ||||||||||||||||||||||||
477 | old_y = y; | - | ||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||
479 | bool increasing = nmonths > 0; | - | ||||||||||||||||||||||||
480 | - | |||||||||||||||||||||||||
481 | while (nmonths != 0) { | - | ||||||||||||||||||||||||
482 | if (nmonths < 0 && nmonths + 12 <= 0) { | - | ||||||||||||||||||||||||
483 | y--; | - | ||||||||||||||||||||||||
484 | nmonths+=12; | - | ||||||||||||||||||||||||
485 | } else if (nmonths < 0) { | - | ||||||||||||||||||||||||
486 | m+= nmonths; | - | ||||||||||||||||||||||||
487 | nmonths = 0; | - | ||||||||||||||||||||||||
488 | if (m <= 0) { | - | ||||||||||||||||||||||||
489 | --y; | - | ||||||||||||||||||||||||
490 | m += 12; | - | ||||||||||||||||||||||||
491 | } | - | ||||||||||||||||||||||||
492 | } else if (nmonths - 12 >= 0) { | - | ||||||||||||||||||||||||
493 | y++; | - | ||||||||||||||||||||||||
494 | nmonths -= 12; | - | ||||||||||||||||||||||||
495 | } else if (m == 12) { | - | ||||||||||||||||||||||||
496 | y++; | - | ||||||||||||||||||||||||
497 | m = 0; | - | ||||||||||||||||||||||||
498 | } else { | - | ||||||||||||||||||||||||
499 | m += nmonths; | - | ||||||||||||||||||||||||
500 | nmonths = 0; | - | ||||||||||||||||||||||||
501 | if (m > 12) { | - | ||||||||||||||||||||||||
502 | ++y; | - | ||||||||||||||||||||||||
503 | m -= 12; | - | ||||||||||||||||||||||||
504 | } | - | ||||||||||||||||||||||||
505 | } | - | ||||||||||||||||||||||||
506 | } | - | ||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||
509 | if ((old_y > 0 && y <= 0) || | - | ||||||||||||||||||||||||
510 | (old_y < 0 && y >= 0)) | - | ||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | y += increasing ? +1 : -1; | - | ||||||||||||||||||||||||
513 | - | |||||||||||||||||||||||||
514 | return fixedDate(y, m, d); | - | ||||||||||||||||||||||||
515 | } | - | ||||||||||||||||||||||||
516 | QDate QDate::addYears(int nyears) const | - | ||||||||||||||||||||||||
517 | { | - | ||||||||||||||||||||||||
518 | if (!isValid()) | - | ||||||||||||||||||||||||
519 | return QDate(); | - | ||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||
521 | ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||
523 | int old_y = pd.year; | - | ||||||||||||||||||||||||
524 | pd.year += nyears; | - | ||||||||||||||||||||||||
525 | - | |||||||||||||||||||||||||
526 | - | |||||||||||||||||||||||||
527 | if ((old_y > 0 && pd.year <= 0) || | - | ||||||||||||||||||||||||
528 | (old_y < 0 && pd.year >= 0)) | - | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | pd.year += nyears > 0 ? +1 : -1; | - | ||||||||||||||||||||||||
531 | - | |||||||||||||||||||||||||
532 | return fixedDate(pd.year, pd.month, pd.day); | - | ||||||||||||||||||||||||
533 | } | - | ||||||||||||||||||||||||
534 | qint64 QDate::daysTo(const QDate &d) const | - | ||||||||||||||||||||||||
535 | { | - | ||||||||||||||||||||||||
536 | if (isNull() || d.isNull()) | - | ||||||||||||||||||||||||
537 | return 0; | - | ||||||||||||||||||||||||
538 | - | |||||||||||||||||||||||||
539 | - | |||||||||||||||||||||||||
540 | return d.jd - jd; | - | ||||||||||||||||||||||||
541 | } | - | ||||||||||||||||||||||||
542 | QDate QDate::fromString(const QString& string, Qt::DateFormat format) | - | ||||||||||||||||||||||||
543 | { | - | ||||||||||||||||||||||||
544 | if (string.isEmpty()) | - | ||||||||||||||||||||||||
545 | return QDate(); | - | ||||||||||||||||||||||||
546 | - | |||||||||||||||||||||||||
547 | switch (format) { | - | ||||||||||||||||||||||||
548 | case Qt::SystemLocaleDate: | - | ||||||||||||||||||||||||
549 | case Qt::SystemLocaleShortDate: | - | ||||||||||||||||||||||||
550 | return QLocale::system().toDate(string, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
551 | case Qt::SystemLocaleLongDate: | - | ||||||||||||||||||||||||
552 | return QLocale::system().toDate(string, QLocale::LongFormat); | - | ||||||||||||||||||||||||
553 | case Qt::LocaleDate: | - | ||||||||||||||||||||||||
554 | case Qt::DefaultLocaleShortDate: | - | ||||||||||||||||||||||||
555 | return QLocale().toDate(string, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
556 | case Qt::DefaultLocaleLongDate: | - | ||||||||||||||||||||||||
557 | return QLocale().toDate(string, QLocale::LongFormat); | - | ||||||||||||||||||||||||
558 | case Qt::RFC2822Date: | - | ||||||||||||||||||||||||
559 | return rfcDateImpl(string).date; | - | ||||||||||||||||||||||||
560 | default: | - | ||||||||||||||||||||||||
561 | - | |||||||||||||||||||||||||
562 | case Qt::TextDate: { | - | ||||||||||||||||||||||||
563 | QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||
564 | - | |||||||||||||||||||||||||
565 | if (parts.count() != 4) | - | ||||||||||||||||||||||||
566 | return QDate(); | - | ||||||||||||||||||||||||
567 | - | |||||||||||||||||||||||||
568 | QStringRef monthName = parts.at(1); | - | ||||||||||||||||||||||||
569 | const int month = fromShortMonthName(monthName); | - | ||||||||||||||||||||||||
570 | if (month == -1) { | - | ||||||||||||||||||||||||
571 | - | |||||||||||||||||||||||||
572 | return QDate(); | - | ||||||||||||||||||||||||
573 | } | - | ||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||
575 | bool ok = false; | - | ||||||||||||||||||||||||
576 | int year = parts.at(3).toInt(&ok); | - | ||||||||||||||||||||||||
577 | if (!ok) | - | ||||||||||||||||||||||||
578 | return QDate(); | - | ||||||||||||||||||||||||
579 | - | |||||||||||||||||||||||||
580 | return QDate(year, month, parts.at(2).toInt()); | - | ||||||||||||||||||||||||
581 | } | - | ||||||||||||||||||||||||
582 | - | |||||||||||||||||||||||||
583 | case Qt::ISODate: { | - | ||||||||||||||||||||||||
584 | - | |||||||||||||||||||||||||
585 | if (string.size() < 10 || string.at(4).isDigit() || string.at(7).isDigit() | - | ||||||||||||||||||||||||
586 | || (string.size() > 10 && string.at(10).isDigit())) { | - | ||||||||||||||||||||||||
587 | return QDate(); | - | ||||||||||||||||||||||||
588 | } | - | ||||||||||||||||||||||||
589 | const int year = string.midRef(0, 4).toInt(); | - | ||||||||||||||||||||||||
590 | if (year <= 0 || year > 9999) | - | ||||||||||||||||||||||||
591 | return QDate(); | - | ||||||||||||||||||||||||
592 | return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt()); | - | ||||||||||||||||||||||||
593 | } | - | ||||||||||||||||||||||||
594 | } | - | ||||||||||||||||||||||||
595 | return QDate(); | - | ||||||||||||||||||||||||
596 | } | - | ||||||||||||||||||||||||
597 | QDate QDate::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||
598 | { | - | ||||||||||||||||||||||||
599 | QDate date; | - | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||
602 | if (dt.parseFormat(format)) | - | ||||||||||||||||||||||||
603 | dt.fromString(string, &date, 0); | - | ||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||
605 | - | |||||||||||||||||||||||||
606 | - | |||||||||||||||||||||||||
607 | - | |||||||||||||||||||||||||
608 | return date; | - | ||||||||||||||||||||||||
609 | } | - | ||||||||||||||||||||||||
610 | bool QDate::isValid(int year, int month, int day) | - | ||||||||||||||||||||||||
611 | { | - | ||||||||||||||||||||||||
612 | - | |||||||||||||||||||||||||
613 | if (year == 0) | - | ||||||||||||||||||||||||
614 | return false; | - | ||||||||||||||||||||||||
615 | - | |||||||||||||||||||||||||
616 | return (day > 0 && month > 0 && month <= 12) && | - | ||||||||||||||||||||||||
617 | (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year))); | - | ||||||||||||||||||||||||
618 | } | - | ||||||||||||||||||||||||
619 | bool QDate::isLeapYear(int y) | - | ||||||||||||||||||||||||
620 | { | - | ||||||||||||||||||||||||
621 | - | |||||||||||||||||||||||||
622 | if ( y < 1) | - | ||||||||||||||||||||||||
623 | ++y; | - | ||||||||||||||||||||||||
624 | - | |||||||||||||||||||||||||
625 | return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; | - | ||||||||||||||||||||||||
626 | } | - | ||||||||||||||||||||||||
627 | QTime::QTime(int h, int m, int s, int ms) | - | ||||||||||||||||||||||||
628 | { | - | ||||||||||||||||||||||||
629 | setHMS(h, m, s, ms); | - | ||||||||||||||||||||||||
630 | } | - | ||||||||||||||||||||||||
631 | bool QTime::isValid() const | - | ||||||||||||||||||||||||
632 | { | - | ||||||||||||||||||||||||
633 | return mds > NullTime && mds < MSECS_PER_DAY; | - | ||||||||||||||||||||||||
634 | } | - | ||||||||||||||||||||||||
635 | int QTime::hour() const | - | ||||||||||||||||||||||||
636 | { | - | ||||||||||||||||||||||||
637 | if (!isValid()) | - | ||||||||||||||||||||||||
638 | return -1; | - | ||||||||||||||||||||||||
639 | - | |||||||||||||||||||||||||
640 | return ds() / MSECS_PER_HOUR; | - | ||||||||||||||||||||||||
641 | } | - | ||||||||||||||||||||||||
642 | int QTime::minute() const | - | ||||||||||||||||||||||||
643 | { | - | ||||||||||||||||||||||||
644 | if (!isValid()) | - | ||||||||||||||||||||||||
645 | return -1; | - | ||||||||||||||||||||||||
646 | - | |||||||||||||||||||||||||
647 | return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN; | - | ||||||||||||||||||||||||
648 | } | - | ||||||||||||||||||||||||
649 | int QTime::second() const | - | ||||||||||||||||||||||||
650 | { | - | ||||||||||||||||||||||||
651 | if (!isValid()) | - | ||||||||||||||||||||||||
652 | return -1; | - | ||||||||||||||||||||||||
653 | - | |||||||||||||||||||||||||
654 | return (ds() / 1000)%SECS_PER_MIN; | - | ||||||||||||||||||||||||
655 | } | - | ||||||||||||||||||||||||
656 | int QTime::msec() const | - | ||||||||||||||||||||||||
657 | { | - | ||||||||||||||||||||||||
658 | if (!isValid()) | - | ||||||||||||||||||||||||
659 | return -1; | - | ||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||
661 | return ds() % 1000; | - | ||||||||||||||||||||||||
662 | } | - | ||||||||||||||||||||||||
663 | QString QTime::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||
664 | { | - | ||||||||||||||||||||||||
665 | if (!isValid()) | - | ||||||||||||||||||||||||
666 | return QString(); | - | ||||||||||||||||||||||||
667 | - | |||||||||||||||||||||||||
668 | switch (format) { | - | ||||||||||||||||||||||||
669 | case Qt::SystemLocaleDate: | - | ||||||||||||||||||||||||
670 | case Qt::SystemLocaleShortDate: | - | ||||||||||||||||||||||||
671 | return QLocale::system().toString(*this, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
672 | case Qt::SystemLocaleLongDate: | - | ||||||||||||||||||||||||
673 | return QLocale::system().toString(*this, QLocale::LongFormat); | - | ||||||||||||||||||||||||
674 | case Qt::LocaleDate: | - | ||||||||||||||||||||||||
675 | case Qt::DefaultLocaleShortDate: | - | ||||||||||||||||||||||||
676 | return QLocale().toString(*this, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
677 | case Qt::DefaultLocaleLongDate: | - | ||||||||||||||||||||||||
678 | return QLocale().toString(*this, QLocale::LongFormat); | - | ||||||||||||||||||||||||
679 | case Qt::RFC2822Date: | - | ||||||||||||||||||||||||
680 | case Qt::ISODate: | - | ||||||||||||||||||||||||
681 | case Qt::TextDate: | - | ||||||||||||||||||||||||
682 | default: | - | ||||||||||||||||||||||||
683 | return QString::asprintf("%02d:%02d:%02d", hour(), minute(), second()); | - | ||||||||||||||||||||||||
684 | } | - | ||||||||||||||||||||||||
685 | } | - | ||||||||||||||||||||||||
686 | QString QTime::toString(const QString& format) const | - | ||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||
688 | return QLocale::system().toString(*this, format); | - | ||||||||||||||||||||||||
689 | } | - | ||||||||||||||||||||||||
690 | bool QTime::setHMS(int h, int m, int s, int ms) | - | ||||||||||||||||||||||||
691 | { | - | ||||||||||||||||||||||||
692 | - | |||||||||||||||||||||||||
693 | - | |||||||||||||||||||||||||
694 | - | |||||||||||||||||||||||||
695 | if (!isValid(h,m,s,ms)) { | - | ||||||||||||||||||||||||
696 | mds = NullTime; | - | ||||||||||||||||||||||||
697 | return false; | - | ||||||||||||||||||||||||
698 | } | - | ||||||||||||||||||||||||
699 | mds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms; | - | ||||||||||||||||||||||||
700 | return true; | - | ||||||||||||||||||||||||
701 | } | - | ||||||||||||||||||||||||
702 | QTime QTime::addSecs(int s) const | - | ||||||||||||||||||||||||
703 | { | - | ||||||||||||||||||||||||
704 | s %= SECS_PER_DAY; | - | ||||||||||||||||||||||||
705 | return addMSecs(s * 1000); | - | ||||||||||||||||||||||||
706 | } | - | ||||||||||||||||||||||||
707 | int QTime::secsTo(const QTime &t) const | - | ||||||||||||||||||||||||
708 | { | - | ||||||||||||||||||||||||
709 | if (!isValid() || !t.isValid()) | - | ||||||||||||||||||||||||
710 | return 0; | - | ||||||||||||||||||||||||
711 | - | |||||||||||||||||||||||||
712 | - | |||||||||||||||||||||||||
713 | int ourSeconds = ds() / 1000; | - | ||||||||||||||||||||||||
714 | int theirSeconds = t.ds() / 1000; | - | ||||||||||||||||||||||||
715 | return theirSeconds - ourSeconds; | - | ||||||||||||||||||||||||
716 | } | - | ||||||||||||||||||||||||
717 | QTime QTime::addMSecs(int ms) const | - | ||||||||||||||||||||||||
718 | { | - | ||||||||||||||||||||||||
719 | QTime t; | - | ||||||||||||||||||||||||
720 | if (isValid()) { | - | ||||||||||||||||||||||||
721 | if (ms < 0) { | - | ||||||||||||||||||||||||
722 | - | |||||||||||||||||||||||||
723 | int negdays = (MSECS_PER_DAY - ms) / MSECS_PER_DAY; | - | ||||||||||||||||||||||||
724 | t.mds = (ds() + ms + negdays * MSECS_PER_DAY) % MSECS_PER_DAY; | - | ||||||||||||||||||||||||
725 | } else { | - | ||||||||||||||||||||||||
726 | t.mds = (ds() + ms) % MSECS_PER_DAY; | - | ||||||||||||||||||||||||
727 | } | - | ||||||||||||||||||||||||
728 | } | - | ||||||||||||||||||||||||
729 | - | |||||||||||||||||||||||||
730 | - | |||||||||||||||||||||||||
731 | - | |||||||||||||||||||||||||
732 | - | |||||||||||||||||||||||||
733 | return t; | - | ||||||||||||||||||||||||
734 | } | - | ||||||||||||||||||||||||
735 | int QTime::msecsTo(const QTime &t) const | - | ||||||||||||||||||||||||
736 | { | - | ||||||||||||||||||||||||
737 | if (!isValid() || !t.isValid()) | - | ||||||||||||||||||||||||
738 | return 0; | - | ||||||||||||||||||||||||
739 | - | |||||||||||||||||||||||||
740 | - | |||||||||||||||||||||||||
741 | - | |||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||
743 | - | |||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||
745 | return t.ds() - ds(); | - | ||||||||||||||||||||||||
746 | } | - | ||||||||||||||||||||||||
747 | static QTime fromIsoTimeString(const QStringRef &string, Qt::DateFormat format, bool *isMidnight24) | - | ||||||||||||||||||||||||
748 | { | - | ||||||||||||||||||||||||
749 | if (isMidnight24) | - | ||||||||||||||||||||||||
750 | *isMidnight24 = false; | - | ||||||||||||||||||||||||
751 | - | |||||||||||||||||||||||||
752 | const int size = string.size(); | - | ||||||||||||||||||||||||
753 | if (size < 5) | - | ||||||||||||||||||||||||
754 | return QTime(); | - | ||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||
756 | bool ok = false; | - | ||||||||||||||||||||||||
757 | int hour = string.mid(0, 2).toInt(&ok); | - | ||||||||||||||||||||||||
758 | if (!ok) | - | ||||||||||||||||||||||||
759 | return QTime(); | - | ||||||||||||||||||||||||
760 | const int minute = string.mid(3, 2).toInt(&ok); | - | ||||||||||||||||||||||||
761 | if (!ok) | - | ||||||||||||||||||||||||
762 | return QTime(); | - | ||||||||||||||||||||||||
763 | int second = 0; | - | ||||||||||||||||||||||||
764 | int msec = 0; | - | ||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||
766 | if (size == 5) { | - | ||||||||||||||||||||||||
767 | - | |||||||||||||||||||||||||
768 | second = 0; | - | ||||||||||||||||||||||||
769 | msec = 0; | - | ||||||||||||||||||||||||
770 | } else if (string.at(5) == QLatin1Char(',') || string.at(5) == QLatin1Char('.')) { | - | ||||||||||||||||||||||||
771 | if (format == Qt::TextDate) | - | ||||||||||||||||||||||||
772 | return QTime(); | - | ||||||||||||||||||||||||
773 | const QStringRef minuteFractionStr = string.mid(6, 5); | - | ||||||||||||||||||||||||
774 | const long minuteFractionInt = minuteFractionStr.toLong(&ok); | - | ||||||||||||||||||||||||
775 | if (!ok) | - | ||||||||||||||||||||||||
776 | return QTime(); | - | ||||||||||||||||||||||||
777 | const float minuteFraction = double(minuteFractionInt) / (std::pow(double(10), minuteFractionStr.count())); | - | ||||||||||||||||||||||||
778 | - | |||||||||||||||||||||||||
779 | const float secondWithMs = minuteFraction * 60; | - | ||||||||||||||||||||||||
780 | const float secondNoMs = std::floor(secondWithMs); | - | ||||||||||||||||||||||||
781 | const float secondFraction = secondWithMs - secondNoMs; | - | ||||||||||||||||||||||||
782 | second = secondNoMs; | - | ||||||||||||||||||||||||
783 | msec = qMin(qRound(secondFraction * 1000.0), 999); | - | ||||||||||||||||||||||||
784 | } else { | - | ||||||||||||||||||||||||
785 | - | |||||||||||||||||||||||||
786 | second = string.mid(6, 2).toInt(&ok); | - | ||||||||||||||||||||||||
787 | if (!ok) | - | ||||||||||||||||||||||||
788 | return QTime(); | - | ||||||||||||||||||||||||
789 | if (size > 8 && (string.at(8) == QLatin1Char(',') || string.at(8) == QLatin1Char('.'))) { | - | ||||||||||||||||||||||||
790 | const QStringRef msecStr(string.mid(9, 4)); | - | ||||||||||||||||||||||||
791 | int msecInt = msecStr.isEmpty() ? 0 : msecStr.toInt(&ok); | - | ||||||||||||||||||||||||
792 | if (!ok) | - | ||||||||||||||||||||||||
793 | return QTime(); | - | ||||||||||||||||||||||||
794 | const double secondFraction(msecInt / (std::pow(double(10), msecStr.count()))); | - | ||||||||||||||||||||||||
795 | msec = qMin(qRound(secondFraction * 1000.0), 999); | - | ||||||||||||||||||||||||
796 | } | - | ||||||||||||||||||||||||
797 | } | - | ||||||||||||||||||||||||
798 | - | |||||||||||||||||||||||||
799 | if (format == Qt::ISODate && hour == 24 && minute == 0 && second == 0 && msec == 0) { | - | ||||||||||||||||||||||||
800 | if (isMidnight24) | - | ||||||||||||||||||||||||
801 | *isMidnight24 = true; | - | ||||||||||||||||||||||||
802 | hour = 0; | - | ||||||||||||||||||||||||
803 | } | - | ||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||
805 | return QTime(hour, minute, second, msec); | - | ||||||||||||||||||||||||
806 | } | - | ||||||||||||||||||||||||
807 | QTime QTime::fromString(const QString& string, Qt::DateFormat format) | - | ||||||||||||||||||||||||
808 | { | - | ||||||||||||||||||||||||
809 | if (string.isEmpty()) | - | ||||||||||||||||||||||||
810 | return QTime(); | - | ||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||
812 | switch (format) { | - | ||||||||||||||||||||||||
813 | case Qt::SystemLocaleDate: | - | ||||||||||||||||||||||||
814 | case Qt::SystemLocaleShortDate: | - | ||||||||||||||||||||||||
815 | return QLocale::system().toTime(string, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
816 | case Qt::SystemLocaleLongDate: | - | ||||||||||||||||||||||||
817 | return QLocale::system().toTime(string, QLocale::LongFormat); | - | ||||||||||||||||||||||||
818 | case Qt::LocaleDate: | - | ||||||||||||||||||||||||
819 | case Qt::DefaultLocaleShortDate: | - | ||||||||||||||||||||||||
820 | return QLocale().toTime(string, QLocale::ShortFormat); | - | ||||||||||||||||||||||||
821 | case Qt::DefaultLocaleLongDate: | - | ||||||||||||||||||||||||
822 | return QLocale().toTime(string, QLocale::LongFormat); | - | ||||||||||||||||||||||||
823 | case Qt::RFC2822Date: | - | ||||||||||||||||||||||||
824 | return rfcDateImpl(string).time; | - | ||||||||||||||||||||||||
825 | case Qt::ISODate: | - | ||||||||||||||||||||||||
826 | case Qt::TextDate: | - | ||||||||||||||||||||||||
827 | default: | - | ||||||||||||||||||||||||
828 | return fromIsoTimeString(&string, format, 0); | - | ||||||||||||||||||||||||
829 | } | - | ||||||||||||||||||||||||
830 | } | - | ||||||||||||||||||||||||
831 | QTime QTime::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||
832 | { | - | ||||||||||||||||||||||||
833 | QTime time; | - | ||||||||||||||||||||||||
834 | - | |||||||||||||||||||||||||
835 | QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||
836 | if (dt.parseFormat(format)) | - | ||||||||||||||||||||||||
837 | dt.fromString(string, 0, &time); | - | ||||||||||||||||||||||||
838 | - | |||||||||||||||||||||||||
839 | - | |||||||||||||||||||||||||
840 | - | |||||||||||||||||||||||||
841 | - | |||||||||||||||||||||||||
842 | return time; | - | ||||||||||||||||||||||||
843 | } | - | ||||||||||||||||||||||||
844 | bool QTime::isValid(int h, int m, int s, int ms) | - | ||||||||||||||||||||||||
845 | { | - | ||||||||||||||||||||||||
846 | return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; | - | ||||||||||||||||||||||||
847 | } | - | ||||||||||||||||||||||||
848 | void QTime::start() | - | ||||||||||||||||||||||||
849 | { | - | ||||||||||||||||||||||||
850 | *this = currentTime(); | - | ||||||||||||||||||||||||
851 | } | - | ||||||||||||||||||||||||
852 | int QTime::restart() | - | ||||||||||||||||||||||||
853 | { | - | ||||||||||||||||||||||||
854 | QTime t = currentTime(); | - | ||||||||||||||||||||||||
855 | int n = msecsTo(t); | - | ||||||||||||||||||||||||
856 | if (n < 0) | - | ||||||||||||||||||||||||
857 | n += 86400*1000; | - | ||||||||||||||||||||||||
858 | *this = t; | - | ||||||||||||||||||||||||
859 | return n; | - | ||||||||||||||||||||||||
860 | } | - | ||||||||||||||||||||||||
861 | int QTime::elapsed() const | - | ||||||||||||||||||||||||
862 | { | - | ||||||||||||||||||||||||
863 | int n = msecsTo(currentTime()); | - | ||||||||||||||||||||||||
864 | if (n < 0) | - | ||||||||||||||||||||||||
865 | n += 86400 * 1000; | - | ||||||||||||||||||||||||
866 | return n; | - | ||||||||||||||||||||||||
867 | } | - | ||||||||||||||||||||||||
868 | - | |||||||||||||||||||||||||
869 | - | |||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||
872 | - | |||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||
874 | static void qt_tzset() | - | ||||||||||||||||||||||||
875 | { | - | ||||||||||||||||||||||||
876 | - | |||||||||||||||||||||||||
877 | - | |||||||||||||||||||||||||
878 | - | |||||||||||||||||||||||||
879 | - | |||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||
881 | - | |||||||||||||||||||||||||
882 | tzset(); | - | ||||||||||||||||||||||||
883 | - | |||||||||||||||||||||||||
884 | } | - | ||||||||||||||||||||||||
885 | - | |||||||||||||||||||||||||
886 | - | |||||||||||||||||||||||||
887 | - | |||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | - | |||||||||||||||||||||||||
890 | - | |||||||||||||||||||||||||
891 | static int qt_timezone() | - | ||||||||||||||||||||||||
892 | { | - | ||||||||||||||||||||||||
893 | return executed 7004 times by 16 tests: timezone;return timezone; Executed by:
executed 7004 times by 16 tests: return timezone; Executed by:
| 7004 | ||||||||||||||||||||||||
894 | - | |||||||||||||||||||||||||
895 | } | - | ||||||||||||||||||||||||
896 | - | |||||||||||||||||||||||||
897 | - | |||||||||||||||||||||||||
898 | static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus) | - | ||||||||||||||||||||||||
899 | { | - | ||||||||||||||||||||||||
900 | int isDst = (daylightStatus == QDateTimePrivate::DaylightTime) ? 1 : 0; | - | ||||||||||||||||||||||||
901 | - | |||||||||||||||||||||||||
902 | - | |||||||||||||||||||||||||
903 | - | |||||||||||||||||||||||||
904 | - | |||||||||||||||||||||||||
905 | - | |||||||||||||||||||||||||
906 | - | |||||||||||||||||||||||||
907 | - | |||||||||||||||||||||||||
908 | return QString::fromLocal8Bit(tzname[isDst]); | - | ||||||||||||||||||||||||
909 | - | |||||||||||||||||||||||||
910 | - | |||||||||||||||||||||||||
911 | } | - | ||||||||||||||||||||||||
912 | - | |||||||||||||||||||||||||
913 | - | |||||||||||||||||||||||||
914 | - | |||||||||||||||||||||||||
915 | - | |||||||||||||||||||||||||
916 | - | |||||||||||||||||||||||||
917 | - | |||||||||||||||||||||||||
918 | static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStatus *daylightStatus, | - | ||||||||||||||||||||||||
919 | QString *abbreviation, bool *ok = 0) | - | ||||||||||||||||||||||||
920 | { | - | ||||||||||||||||||||||||
921 | const qint64 msec = time->msec(); | - | ||||||||||||||||||||||||
922 | int yy, mm, dd; | - | ||||||||||||||||||||||||
923 | date->getDate(&yy, &mm, &dd); | - | ||||||||||||||||||||||||
924 | tm local; | - | ||||||||||||||||||||||||
925 | memset(&local, 0, sizeof(local)); | - | ||||||||||||||||||||||||
926 | local.tm_sec = time->second(); | - | ||||||||||||||||||||||||
927 | local.tm_min = time->minute(); | - | ||||||||||||||||||||||||
928 | local.tm_hour = time->hour(); | - | ||||||||||||||||||||||||
929 | local.tm_mday = dd; | - | ||||||||||||||||||||||||
930 | local.tm_mon = mm - 1; | - | ||||||||||||||||||||||||
931 | local.tm_year = yy - 1900; | - | ||||||||||||||||||||||||
932 | if (daylightStatus) | - | ||||||||||||||||||||||||
933 | local.tm_isdst = int(*daylightStatus); | - | ||||||||||||||||||||||||
934 | else | - | ||||||||||||||||||||||||
935 | local.tm_isdst = -1; | - | ||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||
937 | - | |||||||||||||||||||||||||
938 | - | |||||||||||||||||||||||||
939 | - | |||||||||||||||||||||||||
940 | time_t secsSinceEpoch = mktime(&local); | - | ||||||||||||||||||||||||
941 | if (secsSinceEpoch != time_t(-1)) { | - | ||||||||||||||||||||||||
942 | *date = QDate(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday); | - | ||||||||||||||||||||||||
943 | *time = QTime(local.tm_hour, local.tm_min, local.tm_sec, msec); | - | ||||||||||||||||||||||||
944 | if (local.tm_isdst >= 1) { | - | ||||||||||||||||||||||||
945 | if (daylightStatus) | - | ||||||||||||||||||||||||
946 | *daylightStatus = QDateTimePrivate::DaylightTime; | - | ||||||||||||||||||||||||
947 | if (abbreviation) | - | ||||||||||||||||||||||||
948 | *abbreviation = qt_tzname(QDateTimePrivate::DaylightTime); | - | ||||||||||||||||||||||||
949 | } else if (local.tm_isdst == 0) { | - | ||||||||||||||||||||||||
950 | if (daylightStatus) | - | ||||||||||||||||||||||||
951 | *daylightStatus = QDateTimePrivate::StandardTime; | - | ||||||||||||||||||||||||
952 | if (abbreviation) | - | ||||||||||||||||||||||||
953 | *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); | - | ||||||||||||||||||||||||
954 | } else { | - | ||||||||||||||||||||||||
955 | if (daylightStatus) | - | ||||||||||||||||||||||||
956 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | - | ||||||||||||||||||||||||
957 | if (abbreviation) | - | ||||||||||||||||||||||||
958 | *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); | - | ||||||||||||||||||||||||
959 | } | - | ||||||||||||||||||||||||
960 | if (ok) | - | ||||||||||||||||||||||||
961 | *ok = true; | - | ||||||||||||||||||||||||
962 | } else { | - | ||||||||||||||||||||||||
963 | *date = QDate(); | - | ||||||||||||||||||||||||
964 | *time = QTime(); | - | ||||||||||||||||||||||||
965 | if (daylightStatus) | - | ||||||||||||||||||||||||
966 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | - | ||||||||||||||||||||||||
967 | if (abbreviation) | - | ||||||||||||||||||||||||
968 | *abbreviation = QString(); | - | ||||||||||||||||||||||||
969 | if (ok) | - | ||||||||||||||||||||||||
970 | *ok = false; | - | ||||||||||||||||||||||||
971 | } | - | ||||||||||||||||||||||||
972 | - | |||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||
974 | return ((qint64)secsSinceEpoch * 1000) + msec; | - | ||||||||||||||||||||||||
975 | } | - | ||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | - | |||||||||||||||||||||||||
978 | - | |||||||||||||||||||||||||
979 | static bool qt_localtime(qint64 msecsSinceEpoch, QDate *localDate, QTime *localTime, | - | ||||||||||||||||||||||||
980 | QDateTimePrivate::DaylightStatus *daylightStatus) | - | ||||||||||||||||||||||||
981 | { | - | ||||||||||||||||||||||||
982 | const time_t secsSinceEpoch = msecsSinceEpoch / 1000; | - | ||||||||||||||||||||||||
983 | const int msec = msecsSinceEpoch % 1000; | - | ||||||||||||||||||||||||
984 | - | |||||||||||||||||||||||||
985 | tm local; | - | ||||||||||||||||||||||||
986 | bool valid = false; | - | ||||||||||||||||||||||||
987 | qt_tzset(); | - | ||||||||||||||||||||||||
988 | - | |||||||||||||||||||||||||
989 | - | |||||||||||||||||||||||||
990 | tm *res = 0; | - | ||||||||||||||||||||||||
991 | res = localtime_r(&secsSinceEpoch, &local); | - | ||||||||||||||||||||||||
992 | if (res) | - | ||||||||||||||||||||||||
993 | valid = true; | - | ||||||||||||||||||||||||
994 | if (valid) { | - | ||||||||||||||||||||||||
995 | *localDate = QDate(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday); | - | ||||||||||||||||||||||||
996 | *localTime = QTime(local.tm_hour, local.tm_min, local.tm_sec, msec); | - | ||||||||||||||||||||||||
997 | if (daylightStatus) { | - | ||||||||||||||||||||||||
998 | if (local.tm_isdst > 0) | - | ||||||||||||||||||||||||
999 | *daylightStatus = QDateTimePrivate::DaylightTime; | - | ||||||||||||||||||||||||
1000 | else if (local.tm_isdst < 0) | - | ||||||||||||||||||||||||
1001 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | - | ||||||||||||||||||||||||
1002 | else | - | ||||||||||||||||||||||||
1003 | *daylightStatus = QDateTimePrivate::StandardTime; | - | ||||||||||||||||||||||||
1004 | } | - | ||||||||||||||||||||||||
1005 | return true; | - | ||||||||||||||||||||||||
1006 | } else { | - | ||||||||||||||||||||||||
1007 | *localDate = QDate(); | - | ||||||||||||||||||||||||
1008 | *localTime = QTime(); | - | ||||||||||||||||||||||||
1009 | if (daylightStatus) | - | ||||||||||||||||||||||||
1010 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | - | ||||||||||||||||||||||||
1011 | return false; | - | ||||||||||||||||||||||||
1012 | } | - | ||||||||||||||||||||||||
1013 | } | - | ||||||||||||||||||||||||
1014 | - | |||||||||||||||||||||||||
1015 | - | |||||||||||||||||||||||||
1016 | static void msecsToTime(qint64 msecs, QDate *date, QTime *time) | - | ||||||||||||||||||||||||
1017 | { | - | ||||||||||||||||||||||||
1018 | qint64 jd = JULIAN_DAY_FOR_EPOCH; | - | ||||||||||||||||||||||||
1019 | qint64 ds = 0; | - | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | if (qAbs(msecs) >= MSECS_PER_DAY) { | - | ||||||||||||||||||||||||
1022 | jd += (msecs / MSECS_PER_DAY); | - | ||||||||||||||||||||||||
1023 | msecs %= MSECS_PER_DAY; | - | ||||||||||||||||||||||||
1024 | } | - | ||||||||||||||||||||||||
1025 | - | |||||||||||||||||||||||||
1026 | if (msecs < 0) { | - | ||||||||||||||||||||||||
1027 | ds = MSECS_PER_DAY - msecs - 1; | - | ||||||||||||||||||||||||
1028 | jd -= ds / MSECS_PER_DAY; | - | ||||||||||||||||||||||||
1029 | ds = ds % MSECS_PER_DAY; | - | ||||||||||||||||||||||||
1030 | ds = MSECS_PER_DAY - ds - 1; | - | ||||||||||||||||||||||||
1031 | } else { | - | ||||||||||||||||||||||||
1032 | ds = msecs; | - | ||||||||||||||||||||||||
1033 | } | - | ||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||
1035 | if (date) | - | ||||||||||||||||||||||||
1036 | *date = QDate::fromJulianDay(jd); | - | ||||||||||||||||||||||||
1037 | if (time) | - | ||||||||||||||||||||||||
1038 | *time = QTime::fromMSecsSinceStartOfDay(ds); | - | ||||||||||||||||||||||||
1039 | } | - | ||||||||||||||||||||||||
1040 | - | |||||||||||||||||||||||||
1041 | - | |||||||||||||||||||||||||
1042 | static qint64 timeToMSecs(const QDate &date, const QTime &time) | - | ||||||||||||||||||||||||
1043 | { | - | ||||||||||||||||||||||||
1044 | return ((date.toJulianDay() - JULIAN_DAY_FOR_EPOCH) * MSECS_PER_DAY) | - | ||||||||||||||||||||||||
1045 | + time.msecsSinceStartOfDay(); | - | ||||||||||||||||||||||||
1046 | } | - | ||||||||||||||||||||||||
1047 | - | |||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | static bool epochMSecsToLocalTime(qint64 msecs, QDate *localDate, QTime *localTime, | - | ||||||||||||||||||||||||
1050 | QDateTimePrivate::DaylightStatus *daylightStatus = 0) | - | ||||||||||||||||||||||||
1051 | { | - | ||||||||||||||||||||||||
1052 | if (msecs < 0) { | - | ||||||||||||||||||||||||
1053 | - | |||||||||||||||||||||||||
1054 | - | |||||||||||||||||||||||||
1055 | qt_tzset(); | - | ||||||||||||||||||||||||
1056 | msecsToTime(msecs - qt_timezone() * 1000, localDate, localTime); | - | ||||||||||||||||||||||||
1057 | if (daylightStatus) | - | ||||||||||||||||||||||||
1058 | *daylightStatus = QDateTimePrivate::StandardTime; | - | ||||||||||||||||||||||||
1059 | return true; | - | ||||||||||||||||||||||||
1060 | } else if (msecs > (qint64(TIME_T_MAX) * 1000)) { | - | ||||||||||||||||||||||||
1061 | - | |||||||||||||||||||||||||
1062 | - | |||||||||||||||||||||||||
1063 | - | |||||||||||||||||||||||||
1064 | - | |||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | QDate utcDate; | - | ||||||||||||||||||||||||
1067 | QTime utcTime; | - | ||||||||||||||||||||||||
1068 | msecsToTime(msecs, &utcDate, &utcTime); | - | ||||||||||||||||||||||||
1069 | int year, month, day; | - | ||||||||||||||||||||||||
1070 | utcDate.getDate(&year, &month, &day); | - | ||||||||||||||||||||||||
1071 | - | |||||||||||||||||||||||||
1072 | if (month == 2 && day == 29) | - | ||||||||||||||||||||||||
1073 | --day; | - | ||||||||||||||||||||||||
1074 | QDate fakeDate(2037, month, day); | - | ||||||||||||||||||||||||
1075 | qint64 fakeMsecs = QDateTime(fakeDate, utcTime, Qt::UTC).toMSecsSinceEpoch(); | - | ||||||||||||||||||||||||
1076 | bool res = qt_localtime(fakeMsecs, localDate, localTime, daylightStatus); | - | ||||||||||||||||||||||||
1077 | *localDate = localDate->addDays(fakeDate.daysTo(utcDate)); | - | ||||||||||||||||||||||||
1078 | return res; | - | ||||||||||||||||||||||||
1079 | } else { | - | ||||||||||||||||||||||||
1080 | - | |||||||||||||||||||||||||
1081 | return qt_localtime(msecs, localDate, localTime, daylightStatus); | - | ||||||||||||||||||||||||
1082 | } | - | ||||||||||||||||||||||||
1083 | } | - | ||||||||||||||||||||||||
1084 | - | |||||||||||||||||||||||||
1085 | - | |||||||||||||||||||||||||
1086 | - | |||||||||||||||||||||||||
1087 | - | |||||||||||||||||||||||||
1088 | static qint64 localMSecsToEpochMSecs(qint64 localMsecs, | - | ||||||||||||||||||||||||
1089 | QDateTimePrivate::DaylightStatus *daylightStatus, | - | ||||||||||||||||||||||||
1090 | QDate *localDate = 0, QTime *localTime = 0, | - | ||||||||||||||||||||||||
1091 | QString *abbreviation = 0) | - | ||||||||||||||||||||||||
1092 | { | - | ||||||||||||||||||||||||
1093 | QDate dt; | - | ||||||||||||||||||||||||
1094 | QTime tm; | - | ||||||||||||||||||||||||
1095 | msecsToTime(localMsecs, &dt, &tm); | - | ||||||||||||||||||||||||
1096 | - | |||||||||||||||||||||||||
1097 | const qint64 msecsMax = qint64(TIME_T_MAX) * 1000; | - | ||||||||||||||||||||||||
1098 | - | |||||||||||||||||||||||||
1099 | if (localMsecs <= qint64(MSECS_PER_DAY)) { | - | ||||||||||||||||||||||||
1100 | - | |||||||||||||||||||||||||
1101 | - | |||||||||||||||||||||||||
1102 | - | |||||||||||||||||||||||||
1103 | - | |||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||
1105 | if (localMsecs >= -qint64(MSECS_PER_DAY)) { | - | ||||||||||||||||||||||||
1106 | bool valid; | - | ||||||||||||||||||||||||
1107 | qint64 utcMsecs = qt_mktime(&dt, &tm, daylightStatus, abbreviation, &valid); | - | ||||||||||||||||||||||||
1108 | if (valid && utcMsecs >= 0) { | - | ||||||||||||||||||||||||
1109 | - | |||||||||||||||||||||||||
1110 | if (localDate) | - | ||||||||||||||||||||||||
1111 | *localDate = dt; | - | ||||||||||||||||||||||||
1112 | if (localTime) | - | ||||||||||||||||||||||||
1113 | *localTime = tm; | - | ||||||||||||||||||||||||
1114 | return utcMsecs; | - | ||||||||||||||||||||||||
1115 | } | - | ||||||||||||||||||||||||
1116 | } else { | - | ||||||||||||||||||||||||
1117 | - | |||||||||||||||||||||||||
1118 | qt_tzset(); | - | ||||||||||||||||||||||||
1119 | } | - | ||||||||||||||||||||||||
1120 | - | |||||||||||||||||||||||||
1121 | qint64 utcMsecs = localMsecs + qt_timezone() * 1000; | - | ||||||||||||||||||||||||
1122 | if (localDate || localTime) | - | ||||||||||||||||||||||||
1123 | msecsToTime(localMsecs, localDate, localTime); | - | ||||||||||||||||||||||||
1124 | if (daylightStatus) | - | ||||||||||||||||||||||||
1125 | *daylightStatus = QDateTimePrivate::StandardTime; | - | ||||||||||||||||||||||||
1126 | if (abbreviation) | - | ||||||||||||||||||||||||
1127 | *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); | - | ||||||||||||||||||||||||
1128 | return utcMsecs; | - | ||||||||||||||||||||||||
1129 | - | |||||||||||||||||||||||||
1130 | } else if (localMsecs >= msecsMax - MSECS_PER_DAY) { | - | ||||||||||||||||||||||||
1131 | - | |||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||
1133 | - | |||||||||||||||||||||||||
1134 | - | |||||||||||||||||||||||||
1135 | - | |||||||||||||||||||||||||
1136 | - | |||||||||||||||||||||||||
1137 | if (localMsecs <= msecsMax + MSECS_PER_DAY) { | - | ||||||||||||||||||||||||
1138 | bool valid; | - | ||||||||||||||||||||||||
1139 | qint64 utcMsecs = qt_mktime(&dt, &tm, daylightStatus, abbreviation, &valid); | - | ||||||||||||||||||||||||
1140 | if (valid && utcMsecs <= msecsMax) { | - | ||||||||||||||||||||||||
1141 | - | |||||||||||||||||||||||||
1142 | if (localDate) | - | ||||||||||||||||||||||||
1143 | *localDate = dt; | - | ||||||||||||||||||||||||
1144 | if (localTime) | - | ||||||||||||||||||||||||
1145 | *localTime = tm; | - | ||||||||||||||||||||||||
1146 | return utcMsecs; | - | ||||||||||||||||||||||||
1147 | } | - | ||||||||||||||||||||||||
1148 | } | - | ||||||||||||||||||||||||
1149 | - | |||||||||||||||||||||||||
1150 | - | |||||||||||||||||||||||||
1151 | - | |||||||||||||||||||||||||
1152 | int year, month, day; | - | ||||||||||||||||||||||||
1153 | dt.getDate(&year, &month, &day); | - | ||||||||||||||||||||||||
1154 | - | |||||||||||||||||||||||||
1155 | if (month == 2 && day == 29) | - | ||||||||||||||||||||||||
1156 | --day; | - | ||||||||||||||||||||||||
1157 | QDate fakeDate(2037, month, day); | - | ||||||||||||||||||||||||
1158 | qint64 fakeDiff = fakeDate.daysTo(dt); | - | ||||||||||||||||||||||||
1159 | qint64 utcMsecs = qt_mktime(&fakeDate, &tm, daylightStatus, abbreviation); | - | ||||||||||||||||||||||||
1160 | if (localDate) | - | ||||||||||||||||||||||||
1161 | *localDate = fakeDate.addDays(fakeDiff); | - | ||||||||||||||||||||||||
1162 | if (localTime) | - | ||||||||||||||||||||||||
1163 | *localTime = tm; | - | ||||||||||||||||||||||||
1164 | QDate utcDate; | - | ||||||||||||||||||||||||
1165 | QTime utcTime; | - | ||||||||||||||||||||||||
1166 | msecsToTime(utcMsecs, &utcDate, &utcTime); | - | ||||||||||||||||||||||||
1167 | utcDate = utcDate.addDays(fakeDiff); | - | ||||||||||||||||||||||||
1168 | utcMsecs = timeToMSecs(utcDate, utcTime); | - | ||||||||||||||||||||||||
1169 | return utcMsecs; | - | ||||||||||||||||||||||||
1170 | - | |||||||||||||||||||||||||
1171 | } else { | - | ||||||||||||||||||||||||
1172 | - | |||||||||||||||||||||||||
1173 | - | |||||||||||||||||||||||||
1174 | qint64 utcMsecs = qt_mktime(&dt, &tm, daylightStatus, abbreviation); | - | ||||||||||||||||||||||||
1175 | if (localDate) | - | ||||||||||||||||||||||||
1176 | *localDate = dt; | - | ||||||||||||||||||||||||
1177 | if (localTime) | - | ||||||||||||||||||||||||
1178 | *localTime = tm; | - | ||||||||||||||||||||||||
1179 | return utcMsecs; | - | ||||||||||||||||||||||||
1180 | - | |||||||||||||||||||||||||
1181 | } | - | ||||||||||||||||||||||||
1182 | } | - | ||||||||||||||||||||||||
1183 | - | |||||||||||||||||||||||||
1184 | - | |||||||||||||||||||||||||
1185 | - | |||||||||||||||||||||||||
1186 | - | |||||||||||||||||||||||||
1187 | - | |||||||||||||||||||||||||
1188 | QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, | - | ||||||||||||||||||||||||
1189 | int offsetSeconds) | - | ||||||||||||||||||||||||
1190 | : m_msecs(0), | - | ||||||||||||||||||||||||
1191 | m_spec(Qt::LocalTime), | - | ||||||||||||||||||||||||
1192 | m_offsetFromUtc(0), | - | ||||||||||||||||||||||||
1193 | m_status(0) | - | ||||||||||||||||||||||||
1194 | { | - | ||||||||||||||||||||||||
1195 | setTimeSpec(toSpec, offsetSeconds); | - | ||||||||||||||||||||||||
1196 | setDateTime(toDate, toTime); | - | ||||||||||||||||||||||||
1197 | } | - | ||||||||||||||||||||||||
1198 | - | |||||||||||||||||||||||||
1199 | - | |||||||||||||||||||||||||
1200 | QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime, | - | ||||||||||||||||||||||||
1201 | const QTimeZone &toTimeZone) | - | ||||||||||||||||||||||||
1202 | : m_spec(Qt::TimeZone), | - | ||||||||||||||||||||||||
1203 | m_offsetFromUtc(0), | - | ||||||||||||||||||||||||
1204 | m_timeZone(toTimeZone), | - | ||||||||||||||||||||||||
1205 | m_status(0) | - | ||||||||||||||||||||||||
1206 | { | - | ||||||||||||||||||||||||
1207 | setDateTime(toDate, toTime); | - | ||||||||||||||||||||||||
1208 | } | - | ||||||||||||||||||||||||
1209 | - | |||||||||||||||||||||||||
1210 | - | |||||||||||||||||||||||||
1211 | void QDateTimePrivate::setTimeSpec(Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||
1212 | { | - | ||||||||||||||||||||||||
1213 | clearValidDateTime(); | - | ||||||||||||||||||||||||
1214 | clearSetToDaylightStatus(); | - | ||||||||||||||||||||||||
1215 | - | |||||||||||||||||||||||||
1216 | - | |||||||||||||||||||||||||
1217 | m_timeZone = QTimeZone(); | - | ||||||||||||||||||||||||
1218 | - | |||||||||||||||||||||||||
1219 | - | |||||||||||||||||||||||||
1220 | switch (spec) { | - | ||||||||||||||||||||||||
1221 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1222 | if (offsetSeconds == 0) { | - | ||||||||||||||||||||||||
1223 | m_spec = Qt::UTC; | - | ||||||||||||||||||||||||
1224 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1225 | } else { | - | ||||||||||||||||||||||||
1226 | m_spec = Qt::OffsetFromUTC; | - | ||||||||||||||||||||||||
1227 | m_offsetFromUtc = offsetSeconds; | - | ||||||||||||||||||||||||
1228 | } | - | ||||||||||||||||||||||||
1229 | break; | - | ||||||||||||||||||||||||
1230 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1231 | - | |||||||||||||||||||||||||
1232 | m_spec = Qt::LocalTime; | - | ||||||||||||||||||||||||
1233 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1234 | break; | - | ||||||||||||||||||||||||
1235 | case Qt::UTC: | - | ||||||||||||||||||||||||
1236 | case Qt::LocalTime: | - | ||||||||||||||||||||||||
1237 | m_spec = spec; | - | ||||||||||||||||||||||||
1238 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1239 | break; | - | ||||||||||||||||||||||||
1240 | } | - | ||||||||||||||||||||||||
1241 | } | - | ||||||||||||||||||||||||
1242 | - | |||||||||||||||||||||||||
1243 | void QDateTimePrivate::setDateTime(const QDate &date, const QTime &time) | - | ||||||||||||||||||||||||
1244 | { | - | ||||||||||||||||||||||||
1245 | - | |||||||||||||||||||||||||
1246 | QTime useTime = time; | - | ||||||||||||||||||||||||
1247 | if (!useTime.isValid() && date.isValid()) | - | ||||||||||||||||||||||||
1248 | useTime = QTime::fromMSecsSinceStartOfDay(0); | - | ||||||||||||||||||||||||
1249 | - | |||||||||||||||||||||||||
1250 | StatusFlags newStatus; | - | ||||||||||||||||||||||||
1251 | - | |||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||
1253 | qint64 days = 0; | - | ||||||||||||||||||||||||
1254 | if (date.isValid()) { | - | ||||||||||||||||||||||||
1255 | days = date.toJulianDay() - JULIAN_DAY_FOR_EPOCH; | - | ||||||||||||||||||||||||
1256 | newStatus = ValidDate; | - | ||||||||||||||||||||||||
1257 | } else if (date.isNull()) { | - | ||||||||||||||||||||||||
1258 | newStatus = NullDate; | - | ||||||||||||||||||||||||
1259 | } | - | ||||||||||||||||||||||||
1260 | - | |||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||
1262 | int ds = 0; | - | ||||||||||||||||||||||||
1263 | if (useTime.isValid()) { | - | ||||||||||||||||||||||||
1264 | ds = useTime.msecsSinceStartOfDay(); | - | ||||||||||||||||||||||||
1265 | newStatus |= ValidTime; | - | ||||||||||||||||||||||||
1266 | } else if (time.isNull()) { | - | ||||||||||||||||||||||||
1267 | newStatus |= NullTime; | - | ||||||||||||||||||||||||
1268 | } | - | ||||||||||||||||||||||||
1269 | - | |||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||
1271 | m_msecs = (days * MSECS_PER_DAY) + ds; | - | ||||||||||||||||||||||||
1272 | m_status = newStatus; | - | ||||||||||||||||||||||||
1273 | - | |||||||||||||||||||||||||
1274 | - | |||||||||||||||||||||||||
1275 | checkValidDateTime(); | - | ||||||||||||||||||||||||
1276 | } | - | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | QPair<QDate, QTime> QDateTimePrivate::getDateTime() const | - | ||||||||||||||||||||||||
1279 | { | - | ||||||||||||||||||||||||
1280 | QPair<QDate, QTime> result; | - | ||||||||||||||||||||||||
1281 | msecsToTime(m_msecs, &result.first, &result.second); | - | ||||||||||||||||||||||||
1282 | - | |||||||||||||||||||||||||
1283 | if (isNullDate()) | - | ||||||||||||||||||||||||
1284 | result.first = QDate(); | - | ||||||||||||||||||||||||
1285 | - | |||||||||||||||||||||||||
1286 | if (isNullTime()) | - | ||||||||||||||||||||||||
1287 | result.second = QTime(); | - | ||||||||||||||||||||||||
1288 | - | |||||||||||||||||||||||||
1289 | return result; | - | ||||||||||||||||||||||||
1290 | } | - | ||||||||||||||||||||||||
1291 | - | |||||||||||||||||||||||||
1292 | - | |||||||||||||||||||||||||
1293 | void QDateTimePrivate::setDaylightStatus(QDateTimePrivate::DaylightStatus status) | - | ||||||||||||||||||||||||
1294 | { | - | ||||||||||||||||||||||||
1295 | if (status == DaylightTime) { | - | ||||||||||||||||||||||||
1296 | m_status = m_status & ~SetToStandardTime; | - | ||||||||||||||||||||||||
1297 | m_status = m_status | SetToDaylightTime; | - | ||||||||||||||||||||||||
1298 | } else if (status == StandardTime) { | - | ||||||||||||||||||||||||
1299 | m_status = m_status & ~SetToDaylightTime; | - | ||||||||||||||||||||||||
1300 | m_status = m_status | SetToStandardTime; | - | ||||||||||||||||||||||||
1301 | } else { | - | ||||||||||||||||||||||||
1302 | clearSetToDaylightStatus(); | - | ||||||||||||||||||||||||
1303 | } | - | ||||||||||||||||||||||||
1304 | } | - | ||||||||||||||||||||||||
1305 | - | |||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||
1307 | QDateTimePrivate::DaylightStatus QDateTimePrivate::daylightStatus() const | - | ||||||||||||||||||||||||
1308 | { | - | ||||||||||||||||||||||||
1309 | if ((m_status & SetToDaylightTime) == SetToDaylightTime) | - | ||||||||||||||||||||||||
1310 | return DaylightTime; | - | ||||||||||||||||||||||||
1311 | if ((m_status & SetToStandardTime) == SetToStandardTime) | - | ||||||||||||||||||||||||
1312 | return StandardTime; | - | ||||||||||||||||||||||||
1313 | return UnknownDaylightTime; | - | ||||||||||||||||||||||||
1314 | } | - | ||||||||||||||||||||||||
1315 | - | |||||||||||||||||||||||||
1316 | qint64 QDateTimePrivate::toMSecsSinceEpoch() const | - | ||||||||||||||||||||||||
1317 | { | - | ||||||||||||||||||||||||
1318 | switch (m_spec) { | - | ||||||||||||||||||||||||
1319 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1320 | case Qt::UTC: | - | ||||||||||||||||||||||||
1321 | return (m_msecs - (m_offsetFromUtc * 1000)); | - | ||||||||||||||||||||||||
1322 | - | |||||||||||||||||||||||||
1323 | case Qt::LocalTime: { | - | ||||||||||||||||||||||||
1324 | - | |||||||||||||||||||||||||
1325 | DaylightStatus status = daylightStatus(); | - | ||||||||||||||||||||||||
1326 | return localMSecsToEpochMSecs(m_msecs, &status); | - | ||||||||||||||||||||||||
1327 | } | - | ||||||||||||||||||||||||
1328 | - | |||||||||||||||||||||||||
1329 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1330 | - | |||||||||||||||||||||||||
1331 | - | |||||||||||||||||||||||||
1332 | - | |||||||||||||||||||||||||
1333 | return zoneMSecsToEpochMSecs(m_msecs, m_timeZone); | - | ||||||||||||||||||||||||
1334 | - | |||||||||||||||||||||||||
1335 | } | - | ||||||||||||||||||||||||
1336 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,27132736) : qt_noop()); __builtin_unreachable(); } while (0); | - | ||||||||||||||||||||||||
1337 | return 0; | - | ||||||||||||||||||||||||
1338 | } | - | ||||||||||||||||||||||||
1339 | - | |||||||||||||||||||||||||
1340 | - | |||||||||||||||||||||||||
1341 | void QDateTimePrivate::checkValidDateTime() | - | ||||||||||||||||||||||||
1342 | { | - | ||||||||||||||||||||||||
1343 | switch (m_spec) { | - | ||||||||||||||||||||||||
1344 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1345 | case Qt::UTC: | - | ||||||||||||||||||||||||
1346 | - | |||||||||||||||||||||||||
1347 | if (isValidDate() && isValidTime()) | - | ||||||||||||||||||||||||
1348 | setValidDateTime(); | - | ||||||||||||||||||||||||
1349 | else | - | ||||||||||||||||||||||||
1350 | clearValidDateTime(); | - | ||||||||||||||||||||||||
1351 | break; | - | ||||||||||||||||||||||||
1352 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1353 | case Qt::LocalTime: | - | ||||||||||||||||||||||||
1354 | - | |||||||||||||||||||||||||
1355 | - | |||||||||||||||||||||||||
1356 | refreshDateTime(); | - | ||||||||||||||||||||||||
1357 | break; | - | ||||||||||||||||||||||||
1358 | } | - | ||||||||||||||||||||||||
1359 | } | - | ||||||||||||||||||||||||
1360 | - | |||||||||||||||||||||||||
1361 | - | |||||||||||||||||||||||||
1362 | void QDateTimePrivate::refreshDateTime() | - | ||||||||||||||||||||||||
1363 | { | - | ||||||||||||||||||||||||
1364 | switch (m_spec) { | - | ||||||||||||||||||||||||
1365 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1366 | case Qt::UTC: | - | ||||||||||||||||||||||||
1367 | - | |||||||||||||||||||||||||
1368 | return; | - | ||||||||||||||||||||||||
1369 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1370 | case Qt::LocalTime: | - | ||||||||||||||||||||||||
1371 | break; | - | ||||||||||||||||||||||||
1372 | } | - | ||||||||||||||||||||||||
1373 | - | |||||||||||||||||||||||||
1374 | - | |||||||||||||||||||||||||
1375 | if (!isValidDate() || !isValidTime()) { | - | ||||||||||||||||||||||||
1376 | clearValidDateTime(); | - | ||||||||||||||||||||||||
1377 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1378 | return; | - | ||||||||||||||||||||||||
1379 | } | - | ||||||||||||||||||||||||
1380 | - | |||||||||||||||||||||||||
1381 | - | |||||||||||||||||||||||||
1382 | - | |||||||||||||||||||||||||
1383 | if (m_spec == Qt::TimeZone && !m_timeZone.isValid()) { | - | ||||||||||||||||||||||||
1384 | clearValidDateTime(); | - | ||||||||||||||||||||||||
1385 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1386 | return; | - | ||||||||||||||||||||||||
1387 | } | - | ||||||||||||||||||||||||
1388 | - | |||||||||||||||||||||||||
1389 | - | |||||||||||||||||||||||||
1390 | - | |||||||||||||||||||||||||
1391 | - | |||||||||||||||||||||||||
1392 | - | |||||||||||||||||||||||||
1393 | QDate testDate; | - | ||||||||||||||||||||||||
1394 | QTime testTime; | - | ||||||||||||||||||||||||
1395 | qint64 epochMSecs = 0; | - | ||||||||||||||||||||||||
1396 | if (m_spec == Qt::LocalTime) { | - | ||||||||||||||||||||||||
1397 | DaylightStatus status = daylightStatus(); | - | ||||||||||||||||||||||||
1398 | epochMSecs = localMSecsToEpochMSecs(m_msecs, &status, &testDate, &testTime); | - | ||||||||||||||||||||||||
1399 | - | |||||||||||||||||||||||||
1400 | } else { | - | ||||||||||||||||||||||||
1401 | epochMSecs = zoneMSecsToEpochMSecs(m_msecs, m_timeZone, &testDate, &testTime); | - | ||||||||||||||||||||||||
1402 | - | |||||||||||||||||||||||||
1403 | } | - | ||||||||||||||||||||||||
1404 | if (timeToMSecs(testDate, testTime) == m_msecs) { | - | ||||||||||||||||||||||||
1405 | setValidDateTime(); | - | ||||||||||||||||||||||||
1406 | - | |||||||||||||||||||||||||
1407 | m_offsetFromUtc = (m_msecs - epochMSecs) / 1000; | - | ||||||||||||||||||||||||
1408 | } else { | - | ||||||||||||||||||||||||
1409 | clearValidDateTime(); | - | ||||||||||||||||||||||||
1410 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1411 | } | - | ||||||||||||||||||||||||
1412 | } | - | ||||||||||||||||||||||||
1413 | - | |||||||||||||||||||||||||
1414 | - | |||||||||||||||||||||||||
1415 | - | |||||||||||||||||||||||||
1416 | qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QTimeZone &zone, | - | ||||||||||||||||||||||||
1417 | QDate *localDate, QTime *localTime) | - | ||||||||||||||||||||||||
1418 | { | - | ||||||||||||||||||||||||
1419 | - | |||||||||||||||||||||||||
1420 | QTimeZonePrivate::Data data = zone.d->dataForLocalTime(zoneMSecs); | - | ||||||||||||||||||||||||
1421 | - | |||||||||||||||||||||||||
1422 | - | |||||||||||||||||||||||||
1423 | if (data.atMSecsSinceEpoch >= 0) { | - | ||||||||||||||||||||||||
1424 | msecsToTime(data.atMSecsSinceEpoch + (data.offsetFromUtc * 1000), localDate, localTime); | - | ||||||||||||||||||||||||
1425 | return data.atMSecsSinceEpoch; | - | ||||||||||||||||||||||||
1426 | } else { | - | ||||||||||||||||||||||||
1427 | msecsToTime(zoneMSecs, localDate, localTime); | - | ||||||||||||||||||||||||
1428 | return zoneMSecs - (data.standardTimeOffset * 1000); | - | ||||||||||||||||||||||||
1429 | } | - | ||||||||||||||||||||||||
1430 | } | - | ||||||||||||||||||||||||
1431 | QDateTime::QDateTime() | - | ||||||||||||||||||||||||
1432 | : d(new QDateTimePrivate)(*defaultDateTimePrivate()) | - | ||||||||||||||||||||||||
1433 | { | - | ||||||||||||||||||||||||
1434 | } executed 7103614 times by 127 tests: end of block Executed by:
| 7103614 | ||||||||||||||||||||||||
1435 | - | |||||||||||||||||||||||||
1436 | - | |||||||||||||||||||||||||
1437 | - | |||||||||||||||||||||||||
1438 | - | |||||||||||||||||||||||||
1439 | - | |||||||||||||||||||||||||
1440 | - | |||||||||||||||||||||||||
1441 | - | |||||||||||||||||||||||||
1442 | QDateTime::QDateTime(const QDate &date) | - | ||||||||||||||||||||||||
1443 | : d(new QDateTimePrivate(date, QTime(0, 0, 0), Qt::LocalTime, 0)) | - | ||||||||||||||||||||||||
1444 | { | - | ||||||||||||||||||||||||
1445 | } | - | ||||||||||||||||||||||||
1446 | QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec) | - | ||||||||||||||||||||||||
1447 | : d(new QDateTimePrivate(date, time, spec, 0)) | - | ||||||||||||||||||||||||
1448 | { | - | ||||||||||||||||||||||||
1449 | } | - | ||||||||||||||||||||||||
1450 | QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||
1451 | : d(new QDateTimePrivate(date, time, spec, offsetSeconds)) | - | ||||||||||||||||||||||||
1452 | { | - | ||||||||||||||||||||||||
1453 | } | - | ||||||||||||||||||||||||
1454 | QDateTime::QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone) | - | ||||||||||||||||||||||||
1455 | : d(new QDateTimePrivate(date, time, timeZone)) | - | ||||||||||||||||||||||||
1456 | { | - | ||||||||||||||||||||||||
1457 | } | - | ||||||||||||||||||||||||
1458 | - | |||||||||||||||||||||||||
1459 | - | |||||||||||||||||||||||||
1460 | - | |||||||||||||||||||||||||
1461 | - | |||||||||||||||||||||||||
1462 | - | |||||||||||||||||||||||||
1463 | - | |||||||||||||||||||||||||
1464 | QDateTime::QDateTime(const QDateTime &other) | - | ||||||||||||||||||||||||
1465 | : d(other.d) | - | ||||||||||||||||||||||||
1466 | { | - | ||||||||||||||||||||||||
1467 | } | - | ||||||||||||||||||||||||
1468 | - | |||||||||||||||||||||||||
1469 | - | |||||||||||||||||||||||||
1470 | - | |||||||||||||||||||||||||
1471 | - | |||||||||||||||||||||||||
1472 | QDateTime::~QDateTime() | - | ||||||||||||||||||||||||
1473 | { | - | ||||||||||||||||||||||||
1474 | } | - | ||||||||||||||||||||||||
1475 | - | |||||||||||||||||||||||||
1476 | - | |||||||||||||||||||||||||
1477 | - | |||||||||||||||||||||||||
1478 | - | |||||||||||||||||||||||||
1479 | - | |||||||||||||||||||||||||
1480 | - | |||||||||||||||||||||||||
1481 | QDateTime &QDateTime::operator=(const QDateTime &other) | - | ||||||||||||||||||||||||
1482 | { | - | ||||||||||||||||||||||||
1483 | d = other.d; | - | ||||||||||||||||||||||||
1484 | return *this; | - | ||||||||||||||||||||||||
1485 | } | - | ||||||||||||||||||||||||
1486 | bool QDateTime::isNull() const | - | ||||||||||||||||||||||||
1487 | { | - | ||||||||||||||||||||||||
1488 | return d->isNullDate() && d->isNullTime(); | - | ||||||||||||||||||||||||
1489 | } | - | ||||||||||||||||||||||||
1490 | bool QDateTime::isValid() const | - | ||||||||||||||||||||||||
1491 | { | - | ||||||||||||||||||||||||
1492 | return (d->isValidDateTime()); | - | ||||||||||||||||||||||||
1493 | } | - | ||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||
1495 | - | |||||||||||||||||||||||||
1496 | - | |||||||||||||||||||||||||
1497 | - | |||||||||||||||||||||||||
1498 | - | |||||||||||||||||||||||||
1499 | - | |||||||||||||||||||||||||
1500 | - | |||||||||||||||||||||||||
1501 | QDate QDateTime::date() const | - | ||||||||||||||||||||||||
1502 | { | - | ||||||||||||||||||||||||
1503 | if (d->isNullDate()) | - | ||||||||||||||||||||||||
1504 | return QDate(); | - | ||||||||||||||||||||||||
1505 | QDate dt; | - | ||||||||||||||||||||||||
1506 | msecsToTime(d->m_msecs, &dt, 0); | - | ||||||||||||||||||||||||
1507 | return dt; | - | ||||||||||||||||||||||||
1508 | } | - | ||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||
1510 | - | |||||||||||||||||||||||||
1511 | - | |||||||||||||||||||||||||
1512 | - | |||||||||||||||||||||||||
1513 | - | |||||||||||||||||||||||||
1514 | - | |||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||
1516 | QTime QDateTime::time() const | - | ||||||||||||||||||||||||
1517 | { | - | ||||||||||||||||||||||||
1518 | if (d->isNullTime()) | - | ||||||||||||||||||||||||
1519 | return QTime(); | - | ||||||||||||||||||||||||
1520 | QTime tm; | - | ||||||||||||||||||||||||
1521 | msecsToTime(d->m_msecs, 0, &tm); | - | ||||||||||||||||||||||||
1522 | return tm; | - | ||||||||||||||||||||||||
1523 | } | - | ||||||||||||||||||||||||
1524 | - | |||||||||||||||||||||||||
1525 | - | |||||||||||||||||||||||||
1526 | - | |||||||||||||||||||||||||
1527 | - | |||||||||||||||||||||||||
1528 | - | |||||||||||||||||||||||||
1529 | - | |||||||||||||||||||||||||
1530 | - | |||||||||||||||||||||||||
1531 | Qt::TimeSpec QDateTime::timeSpec() const | - | ||||||||||||||||||||||||
1532 | { | - | ||||||||||||||||||||||||
1533 | return d->m_spec; | - | ||||||||||||||||||||||||
1534 | } | - | ||||||||||||||||||||||||
1535 | QTimeZone QDateTime::timeZone() const | - | ||||||||||||||||||||||||
1536 | { | - | ||||||||||||||||||||||||
1537 | switch (d->m_spec) { | - | ||||||||||||||||||||||||
1538 | case Qt::UTC: | - | ||||||||||||||||||||||||
1539 | return QTimeZone::utc(); | - | ||||||||||||||||||||||||
1540 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1541 | return QTimeZone(d->m_offsetFromUtc); | - | ||||||||||||||||||||||||
1542 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1543 | ((!(d->m_timeZone.isValid())) ? qt_assert("d->m_timeZone.isValid()",__FILE__,31473169) : qt_noop()); | - | ||||||||||||||||||||||||
1544 | return d->m_timeZone; | - | ||||||||||||||||||||||||
1545 | case Qt::LocalTime: | - | ||||||||||||||||||||||||
1546 | return QTimeZone::systemTimeZone(); | - | ||||||||||||||||||||||||
1547 | } | - | ||||||||||||||||||||||||
1548 | return QTimeZone(); | - | ||||||||||||||||||||||||
1549 | } | - | ||||||||||||||||||||||||
1550 | int QDateTime::offsetFromUtc() const | - | ||||||||||||||||||||||||
1551 | { | - | ||||||||||||||||||||||||
1552 | return d->m_offsetFromUtc; | - | ||||||||||||||||||||||||
1553 | } | - | ||||||||||||||||||||||||
1554 | QString QDateTime::timeZoneAbbreviation() const | - | ||||||||||||||||||||||||
1555 | { | - | ||||||||||||||||||||||||
1556 | switch (d->m_spec) { | - | ||||||||||||||||||||||||
1557 | case Qt::UTC: | - | ||||||||||||||||||||||||
1558 | return QTimeZonePrivate::utcQString(); | - | ||||||||||||||||||||||||
1559 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1560 | return QTimeZonePrivate::utcQString() + toOffsetString(Qt::ISODate, d->m_offsetFromUtc); | - | ||||||||||||||||||||||||
1561 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||
1563 | - | |||||||||||||||||||||||||
1564 | - | |||||||||||||||||||||||||
1565 | return d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch()); | - | ||||||||||||||||||||||||
1566 | - | |||||||||||||||||||||||||
1567 | case Qt::LocalTime: { | - | ||||||||||||||||||||||||
1568 | QString abbrev; | - | ||||||||||||||||||||||||
1569 | QDateTimePrivate::DaylightStatus status = d->daylightStatus(); | - | ||||||||||||||||||||||||
1570 | localMSecsToEpochMSecs(d->m_msecs, &status, 0, 0, &abbrev); | - | ||||||||||||||||||||||||
1571 | return abbrev; | - | ||||||||||||||||||||||||
1572 | } | - | ||||||||||||||||||||||||
1573 | } | - | ||||||||||||||||||||||||
1574 | return QString(); | - | ||||||||||||||||||||||||
1575 | } | - | ||||||||||||||||||||||||
1576 | bool QDateTime::isDaylightTime() const | - | ||||||||||||||||||||||||
1577 | { | - | ||||||||||||||||||||||||
1578 | switch (d->m_spec) { | - | ||||||||||||||||||||||||
1579 | case Qt::UTC: | - | ||||||||||||||||||||||||
1580 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1581 | return false; | - | ||||||||||||||||||||||||
1582 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1583 | - | |||||||||||||||||||||||||
1584 | - | |||||||||||||||||||||||||
1585 | - | |||||||||||||||||||||||||
1586 | return d->m_timeZone.d->isDaylightTime(toMSecsSinceEpoch()); | - | ||||||||||||||||||||||||
1587 | - | |||||||||||||||||||||||||
1588 | case Qt::LocalTime: { | - | ||||||||||||||||||||||||
1589 | QDateTimePrivate::DaylightStatus status = d->daylightStatus(); | - | ||||||||||||||||||||||||
1590 | if (status == QDateTimePrivate::UnknownDaylightTime) | - | ||||||||||||||||||||||||
1591 | localMSecsToEpochMSecs(d->m_msecs, &status); | - | ||||||||||||||||||||||||
1592 | return (status == QDateTimePrivate::DaylightTime); | - | ||||||||||||||||||||||||
1593 | } | - | ||||||||||||||||||||||||
1594 | } | - | ||||||||||||||||||||||||
1595 | return false; | - | ||||||||||||||||||||||||
1596 | } | - | ||||||||||||||||||||||||
1597 | void QDateTime::setDate(const QDate &date) | - | ||||||||||||||||||||||||
1598 | { | - | ||||||||||||||||||||||||
1599 | d->setDateTime(date, time()); | - | ||||||||||||||||||||||||
1600 | } | - | ||||||||||||||||||||||||
1601 | void QDateTime::setTime(const QTime &time) | - | ||||||||||||||||||||||||
1602 | { | - | ||||||||||||||||||||||||
1603 | d->setDateTime(date(), time); | - | ||||||||||||||||||||||||
1604 | } | - | ||||||||||||||||||||||||
1605 | void QDateTime::setTimeSpec(Qt::TimeSpec spec) | - | ||||||||||||||||||||||||
1606 | { | - | ||||||||||||||||||||||||
1607 | QDateTimePrivate *d = this->d.data(); | - | ||||||||||||||||||||||||
1608 | d->setTimeSpec(spec, 0); | - | ||||||||||||||||||||||||
1609 | d->checkValidDateTime(); | - | ||||||||||||||||||||||||
1610 | } | - | ||||||||||||||||||||||||
1611 | void QDateTime::setOffsetFromUtc(int offsetSeconds) | - | ||||||||||||||||||||||||
1612 | { | - | ||||||||||||||||||||||||
1613 | QDateTimePrivate *d = this->d.data(); | - | ||||||||||||||||||||||||
1614 | d->setTimeSpec(Qt::OffsetFromUTC, offsetSeconds); | - | ||||||||||||||||||||||||
1615 | d->checkValidDateTime(); | - | ||||||||||||||||||||||||
1616 | } | - | ||||||||||||||||||||||||
1617 | void QDateTime::setTimeZone(const QTimeZone &toZone) | - | ||||||||||||||||||||||||
1618 | { | - | ||||||||||||||||||||||||
1619 | QDateTimePrivate *d = this->d.data(); | - | ||||||||||||||||||||||||
1620 | d->m_spec = Qt::TimeZone; | - | ||||||||||||||||||||||||
1621 | d->m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||
1622 | d->m_timeZone = toZone; | - | ||||||||||||||||||||||||
1623 | d->refreshDateTime(); | - | ||||||||||||||||||||||||
1624 | } | - | ||||||||||||||||||||||||
1625 | qint64 QDateTime::toMSecsSinceEpoch() const | - | ||||||||||||||||||||||||
1626 | { | - | ||||||||||||||||||||||||
1627 | return d->toMSecsSinceEpoch(); | - | ||||||||||||||||||||||||
1628 | } | - | ||||||||||||||||||||||||
1629 | uint QDateTime::toTime_t() const | - | ||||||||||||||||||||||||
1630 | { | - | ||||||||||||||||||||||||
1631 | if (!isValid()) | - | ||||||||||||||||||||||||
1632 | return uint(-1); | - | ||||||||||||||||||||||||
1633 | qint64 retval = d->toMSecsSinceEpoch() / 1000; | - | ||||||||||||||||||||||||
1634 | if (quint64(retval) >= static_cast<unsigned long long>(0xFFFFFFFFULL)) | - | ||||||||||||||||||||||||
1635 | return uint(-1); | - | ||||||||||||||||||||||||
1636 | return uint(retval); | - | ||||||||||||||||||||||||
1637 | } | - | ||||||||||||||||||||||||
1638 | void QDateTime::setMSecsSinceEpoch(qint64 msecs) | - | ||||||||||||||||||||||||
1639 | { | - | ||||||||||||||||||||||||
1640 | QDateTimePrivate *d = this->d.data(); | - | ||||||||||||||||||||||||
1641 | - | |||||||||||||||||||||||||
1642 | d->m_status = 0; | - | ||||||||||||||||||||||||
1643 | switch (d->m_spec) { | - | ||||||||||||||||||||||||
1644 | case Qt::UTC: | - | ||||||||||||||||||||||||
1645 | d->m_msecs = msecs; | - | ||||||||||||||||||||||||
1646 | d->m_status = d->m_status | - | ||||||||||||||||||||||||
1647 | | QDateTimePrivate::ValidDate | - | ||||||||||||||||||||||||
1648 | | QDateTimePrivate::ValidTime | - | ||||||||||||||||||||||||
1649 | | QDateTimePrivate::ValidDateTime; | - | ||||||||||||||||||||||||
1650 | break; | - | ||||||||||||||||||||||||
1651 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
1652 | d->m_msecs = msecs + (d->m_offsetFromUtc * 1000); | - | ||||||||||||||||||||||||
1653 | d->m_status = d->m_status | - | ||||||||||||||||||||||||
1654 | | QDateTimePrivate::ValidDate | - | ||||||||||||||||||||||||
1655 | | QDateTimePrivate::ValidTime | - | ||||||||||||||||||||||||
1656 | | QDateTimePrivate::ValidDateTime; | - | ||||||||||||||||||||||||
1657 | break; | - | ||||||||||||||||||||||||
1658 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
1659 | - | |||||||||||||||||||||||||
1660 | - | |||||||||||||||||||||||||
1661 | - | |||||||||||||||||||||||||
1662 | if (msecs >= 0) | - | ||||||||||||||||||||||||
1663 | d->m_offsetFromUtc = d->m_timeZone.d->offsetFromUtc(msecs); | - | ||||||||||||||||||||||||
1664 | else | - | ||||||||||||||||||||||||
1665 | d->m_offsetFromUtc = d->m_timeZone.d->standardTimeOffset(msecs); | - | ||||||||||||||||||||||||
1666 | d->m_msecs = msecs + (d->m_offsetFromUtc * 1000); | - | ||||||||||||||||||||||||
1667 | d->m_status = d->m_status | - | ||||||||||||||||||||||||
1668 | | QDateTimePrivate::ValidDate | - | ||||||||||||||||||||||||
1669 | | QDateTimePrivate::ValidTime | - | ||||||||||||||||||||||||
1670 | | QDateTimePrivate::ValidDateTime; | - | ||||||||||||||||||||||||
1671 | d->refreshDateTime(); | - | ||||||||||||||||||||||||
1672 | - | |||||||||||||||||||||||||
1673 | break; | - | ||||||||||||||||||||||||
1674 | case Qt::LocalTime: { | - | ||||||||||||||||||||||||
1675 | QDate dt; | - | ||||||||||||||||||||||||
1676 | QTime tm; | - | ||||||||||||||||||||||||
1677 | QDateTimePrivate::DaylightStatus status; | - | ||||||||||||||||||||||||
1678 | epochMSecsToLocalTime(msecs, &dt, &tm, &status); | - | ||||||||||||||||||||||||
1679 | d->setDateTime(dt, tm); | - | ||||||||||||||||||||||||
1680 | d->setDaylightStatus(status); | - | ||||||||||||||||||||||||
1681 | d->refreshDateTime(); | - | ||||||||||||||||||||||||
1682 | break; | - | ||||||||||||||||||||||||
1683 | } | - | ||||||||||||||||||||||||
1684 | } | - | ||||||||||||||||||||||||
1685 | } | - | ||||||||||||||||||||||||
1686 | void QDateTime::setTime_t(uint secsSince1Jan1970UTC) | - | ||||||||||||||||||||||||
1687 | { | - | ||||||||||||||||||||||||
1688 | setMSecsSinceEpoch((qint64)secsSince1Jan1970UTC * 1000); | - | ||||||||||||||||||||||||
1689 | } | - | ||||||||||||||||||||||||
1690 | QString QDateTime::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||
1691 | { | - | ||||||||||||||||||||||||
1692 | QString buf; | - | ||||||||||||||||||||||||
1693 | if (!isValid()
| 2-3156 | ||||||||||||||||||||||||
1694 | return executed 2 times by 1 test: buf;return buf; Executed by:
executed 2 times by 1 test: return buf; Executed by:
| 2 | ||||||||||||||||||||||||
1695 | - | |||||||||||||||||||||||||
1696 | switch (format) { | - | ||||||||||||||||||||||||
1697 | case executed 2721 times by 8 tests: Qt::SystemLocaleDate:case Qt::SystemLocaleDate: Executed by:
executed 2721 times by 8 tests: case Qt::SystemLocaleDate: Executed by:
| 2721 | ||||||||||||||||||||||||
1698 | case executed 1 time by 1 test: Qt::SystemLocaleShortDate:case Qt::SystemLocaleShortDate: Executed by:
executed 1 time by 1 test: case Qt::SystemLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||
1699 | return executed 2722 times by 8 tests: QLocale::system().toString(*this, QLocale::ShortFormat);return QLocale::system().toString(*this, QLocale::ShortFormat); Executed by:
executed 2722 times by 8 tests: return QLocale::system().toString(*this, QLocale::ShortFormat); Executed by:
| 2722 | ||||||||||||||||||||||||
1700 | case executed 1 time by 1 test: Qt::SystemLocaleLongDate:case Qt::SystemLocaleLongDate: Executed by:
executed 1 time by 1 test: case Qt::SystemLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||
1701 | return executed 1 time by 1 test: QLocale::system().toString(*this, QLocale::LongFormat);return QLocale::system().toString(*this, QLocale::LongFormat); Executed by:
executed 1 time by 1 test: return QLocale::system().toString(*this, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||
1702 | case executed 1 time by 1 test: Qt::LocaleDate:case Qt::LocaleDate: Executed by:
executed 1 time by 1 test: case Qt::LocaleDate: Executed by:
| 1 | ||||||||||||||||||||||||
1703 | case executed 1 time by 1 test: Qt::DefaultLocaleShortDate:case Qt::DefaultLocaleShortDate: Executed by:
executed 1 time by 1 test: case Qt::DefaultLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||
1704 | return executed 2 times by 1 test: QLocale().toString(*this, QLocale::ShortFormat);return QLocale().toString(*this, QLocale::ShortFormat); Executed by:
executed 2 times by 1 test: return QLocale().toString(*this, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||
1705 | case executed 1 time by 1 test: Qt::DefaultLocaleLongDate:case Qt::DefaultLocaleLongDate: Executed by:
executed 1 time by 1 test: case Qt::DefaultLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||
1706 | return executed 1 time by 1 test: QLocale().toString(*this, QLocale::LongFormat);return QLocale().toString(*this, QLocale::LongFormat); Executed by:
executed 1 time by 1 test: return QLocale().toString(*this, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||
1707 | case executed 5 times by 1 test: Qt::RFC2822Date:case Qt::RFC2822Date: Executed by:
executed 5 times by 1 test: {case Qt::RFC2822Date: Executed by:
| 5 | ||||||||||||||||||||||||
1708 | buf = QLocale::c().toString(*this, ([]() -> QString { enum { Size = sizeof(u"" "dd MMM yyyy hh:mm:ss ")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "dd MMM yyyy hh:mm:ss " }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||||||||
1709 | buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc); | - | ||||||||||||||||||||||||
1710 | return executed 5 times by 1 test: buf;return buf; Executed by:
executed 5 times by 1 test: return buf; Executed by:
| 5 | ||||||||||||||||||||||||
1711 | } | - | ||||||||||||||||||||||||
1712 | default never executed: :default: never executed: default: | 0 | ||||||||||||||||||||||||
1713 | - | |||||||||||||||||||||||||
1714 | case executed 399 times by 3 tests: Qt::TextDate:case Qt::TextDate: Executed by:
executed 399 times by 3 tests: {case Qt::TextDate: Executed by:
| 399 | ||||||||||||||||||||||||
1715 | const QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||
1716 | const QDate &dt = p.first; | - | ||||||||||||||||||||||||
1717 | const QTime &tm = p.second; | - | ||||||||||||||||||||||||
1718 | - | |||||||||||||||||||||||||
1719 | buf = QString::fromLatin1("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek())) | - | ||||||||||||||||||||||||
1720 | .arg(dt.shortMonthName(dt.month())) | - | ||||||||||||||||||||||||
1721 | .arg(dt.day()) | - | ||||||||||||||||||||||||
1722 | .arg(tm.toString(Qt::TextDate)) | - | ||||||||||||||||||||||||
1723 | .arg(dt.year()); | - | ||||||||||||||||||||||||
1724 | if (timeSpec() != Qt::LocalTime
| 3-396 | ||||||||||||||||||||||||
1725 | buf += ([]() -> QString { enum { Size = sizeof(u"" " GMT")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeofQLatin1String(QStringData) }, u"" " GMT"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); | - | ||||||||||||||||||||||||
1726 | return qstring_literal_temp; }());if (d->m_spec == Qt::OffsetFromUTC
| 1-2 | ||||||||||||||||||||||||
1727 | buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc); executed 2 times by 1 test: buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc); Executed by:
| 2 | ||||||||||||||||||||||||
1728 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
1729 | return executed 399 times by 3 tests: buf;return buf; Executed by:
executed 399 times by 3 tests: return buf; Executed by:
| 399 | ||||||||||||||||||||||||
1730 | } | - | ||||||||||||||||||||||||
1731 | - | |||||||||||||||||||||||||
1732 | case executed 26 times by 4 tests: Qt::ISODate:case Qt::ISODate: Executed by:
executed 26 times by 4 tests: {case Qt::ISODate: Executed by:
| 26 | ||||||||||||||||||||||||
1733 | const QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||
1734 | const QDate &dt = p.first; | - | ||||||||||||||||||||||||
1735 | const QTime &tm = p.second; | - | ||||||||||||||||||||||||
1736 | buf = dt.toString(Qt::ISODate); | - | ||||||||||||||||||||||||
1737 | if (buf.isEmpty()
| 1-25 | ||||||||||||||||||||||||
1738 | return executed 1 time by 1 test: QString();return QString(); Executed by:
executed 1 time by 1 test: return QString(); Executed by:
| 1 | ||||||||||||||||||||||||
1739 | buf += QLatin1Char('T'); | - | ||||||||||||||||||||||||
1740 | buf += tm.toString(Qt::ISODate); | - | ||||||||||||||||||||||||
1741 | switch (d->m_spec) { | - | ||||||||||||||||||||||||
1742 | case executed 9 times by 2 tests: Qt::UTC:case Qt::UTC: Executed by:
executed 9 times by 2 tests: case Qt::UTC: Executed by:
| 9 | ||||||||||||||||||||||||
1743 | buf += QLatin1Char('Z'); | - | ||||||||||||||||||||||||
1744 | break; executed 9 times by 2 tests: break; Executed by:
| 9 | ||||||||||||||||||||||||
1745 | case executed 3 times by 1 test: Qt::OffsetFromUTC:case Qt::OffsetFromUTC: Executed by:
executed 3 times by 1 test: case Qt::OffsetFromUTC: Executed by:
| 3 | ||||||||||||||||||||||||
1746 | buf += toOffsetString(Qt::ISODate, d->m_offsetFromUtc); | - | ||||||||||||||||||||||||
1747 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||||||||
1748 | default executed 13 times by 3 tests: :default: Executed by:
executed 13 times by 3 tests: default: Executed by:
| 13 | ||||||||||||||||||||||||
1749 | break; executed 13 times by 3 tests: break; Executed by:
| 13 | ||||||||||||||||||||||||
1750 | } | - | ||||||||||||||||||||||||
1751 | return executed 25 times by 4 tests: buf;return buf; Executed by:
executed 25 times by 4 tests: return buf; Executed by:
| 25 | ||||||||||||||||||||||||
1752 | } | - | ||||||||||||||||||||||||
1753 | } | - | ||||||||||||||||||||||||
1754 | } | - | ||||||||||||||||||||||||
1755 | QString QDateTime::toString(const QString& format) const | - | ||||||||||||||||||||||||
1756 | { | - | ||||||||||||||||||||||||
1757 | return QLocale::system().toString(*this, format); | - | ||||||||||||||||||||||||
1758 | } | - | ||||||||||||||||||||||||
1759 | - | |||||||||||||||||||||||||
1760 | - | |||||||||||||||||||||||||
1761 | static void massageAdjustedDateTime(Qt::TimeSpec spec, | - | ||||||||||||||||||||||||
1762 | - | |||||||||||||||||||||||||
1763 | const QTimeZone &zone, | - | ||||||||||||||||||||||||
1764 | - | |||||||||||||||||||||||||
1765 | QDate *date, | - | ||||||||||||||||||||||||
1766 | QTime *time) | - | ||||||||||||||||||||||||
1767 | { | - | ||||||||||||||||||||||||
1768 | if (spec == Qt::LocalTime) { | - | ||||||||||||||||||||||||
1769 | QDateTimePrivate::DaylightStatus status = QDateTimePrivate::UnknownDaylightTime; | - | ||||||||||||||||||||||||
1770 | localMSecsToEpochMSecs(timeToMSecs(*date, *time), &status, date, time); | - | ||||||||||||||||||||||||
1771 | - | |||||||||||||||||||||||||
1772 | } else if (spec == Qt::TimeZone) { | - | ||||||||||||||||||||||||
1773 | QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(*date, *time), zone, date, time); | - | ||||||||||||||||||||||||
1774 | - | |||||||||||||||||||||||||
1775 | } | - | ||||||||||||||||||||||||
1776 | } | - | ||||||||||||||||||||||||
1777 | QDateTime QDateTime::addDays(qint64 ndays) const | - | ||||||||||||||||||||||||
1778 | { | - | ||||||||||||||||||||||||
1779 | QDateTime dt(*this); | - | ||||||||||||||||||||||||
1780 | QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||
1781 | QDate &date = p.first; | - | ||||||||||||||||||||||||
1782 | QTime &time = p.second; | - | ||||||||||||||||||||||||
1783 | date = date.addDays(ndays); | - | ||||||||||||||||||||||||
1784 | massageAdjustedDateTime(d->m_spec, d->m_timeZone, &date, &time); | - | ||||||||||||||||||||||||
1785 | dt.d->setDateTime(date, time); | - | ||||||||||||||||||||||||
1786 | return dt; | - | ||||||||||||||||||||||||
1787 | } | - | ||||||||||||||||||||||||
1788 | QDateTime QDateTime::addMonths(int nmonths) const | - | ||||||||||||||||||||||||
1789 | { | - | ||||||||||||||||||||||||
1790 | QDateTime dt(*this); | - | ||||||||||||||||||||||||
1791 | QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||
1792 | QDate &date = p.first; | - | ||||||||||||||||||||||||
1793 | QTime &time = p.second; | - | ||||||||||||||||||||||||
1794 | date = date.addMonths(nmonths); | - | ||||||||||||||||||||||||
1795 | massageAdjustedDateTime(d->m_spec, d->m_timeZone, &date, &time); | - | ||||||||||||||||||||||||
1796 | dt.d->setDateTime(date, time); | - | ||||||||||||||||||||||||
1797 | return dt; | - | ||||||||||||||||||||||||
1798 | } | - | ||||||||||||||||||||||||
1799 | QDateTime QDateTime::addYears(int nyears) const | - | ||||||||||||||||||||||||
1800 | { | - | ||||||||||||||||||||||||
1801 | QDateTime dt(*this); | - | ||||||||||||||||||||||||
1802 | QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||
1803 | QDate &date = p.first; | - | ||||||||||||||||||||||||
1804 | QTime &time = p.second; | - | ||||||||||||||||||||||||
1805 | date = date.addYears(nyears); | - | ||||||||||||||||||||||||
1806 | massageAdjustedDateTime(d->m_spec, d->m_timeZone, &date, &time); | - | ||||||||||||||||||||||||
1807 | dt.d->setDateTime(date, time); | - | ||||||||||||||||||||||||
1808 | return dt; | - | ||||||||||||||||||||||||
1809 | } | - | ||||||||||||||||||||||||
1810 | QDateTime QDateTime::addSecs(qint64 s) const | - | ||||||||||||||||||||||||
1811 | { | - | ||||||||||||||||||||||||
1812 | return addMSecs(s * 1000); | - | ||||||||||||||||||||||||
1813 | } | - | ||||||||||||||||||||||||
1814 | QDateTime QDateTime::addMSecs(qint64 msecs) const | - | ||||||||||||||||||||||||
1815 | { | - | ||||||||||||||||||||||||
1816 | if (!isValid()) | - | ||||||||||||||||||||||||
1817 | return QDateTime(); | - | ||||||||||||||||||||||||
1818 | - | |||||||||||||||||||||||||
1819 | QDateTime dt(*this); | - | ||||||||||||||||||||||||
1820 | if (d->m_spec == Qt::LocalTime || d->m_spec == Qt::TimeZone) | - | ||||||||||||||||||||||||
1821 | - | |||||||||||||||||||||||||
1822 | dt.setMSecsSinceEpoch(d->toMSecsSinceEpoch() + msecs); | - | ||||||||||||||||||||||||
1823 | else | - | ||||||||||||||||||||||||
1824 | - | |||||||||||||||||||||||||
1825 | dt.d->m_msecs = dt.d->m_msecs + msecs; | - | ||||||||||||||||||||||||
1826 | return dt; | - | ||||||||||||||||||||||||
1827 | } | - | ||||||||||||||||||||||||
1828 | qint64 QDateTime::daysTo(const QDateTime &other) const | - | ||||||||||||||||||||||||
1829 | { | - | ||||||||||||||||||||||||
1830 | return date().daysTo(other.date()); | - | ||||||||||||||||||||||||
1831 | } | - | ||||||||||||||||||||||||
1832 | qint64 QDateTime::secsTo(const QDateTime &other) const | - | ||||||||||||||||||||||||
1833 | { | - | ||||||||||||||||||||||||
1834 | return (msecsTo(other) / 1000); | - | ||||||||||||||||||||||||
1835 | } | - | ||||||||||||||||||||||||
1836 | qint64 QDateTime::msecsTo(const QDateTime &other) const | - | ||||||||||||||||||||||||
1837 | { | - | ||||||||||||||||||||||||
1838 | if (!isValid() || !other.isValid()) | - | ||||||||||||||||||||||||
1839 | return 0; | - | ||||||||||||||||||||||||
1840 | - | |||||||||||||||||||||||||
1841 | return other.d->toMSecsSinceEpoch() - d->toMSecsSinceEpoch(); | - | ||||||||||||||||||||||||
1842 | } | - | ||||||||||||||||||||||||
1843 | QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const | - | ||||||||||||||||||||||||
1844 | { | - | ||||||||||||||||||||||||
1845 | if (d->m_spec == spec && (spec == Qt::UTC || spec == Qt::LocalTime)) | - | ||||||||||||||||||||||||
1846 | return *this; | - | ||||||||||||||||||||||||
1847 | - | |||||||||||||||||||||||||
1848 | if (!isValid()) { | - | ||||||||||||||||||||||||
1849 | QDateTime ret = *this; | - | ||||||||||||||||||||||||
1850 | ret.setTimeSpec(spec); | - | ||||||||||||||||||||||||
1851 | return ret; | - | ||||||||||||||||||||||||
1852 | } | - | ||||||||||||||||||||||||
1853 | - | |||||||||||||||||||||||||
1854 | return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), spec, 0); | - | ||||||||||||||||||||||||
1855 | } | - | ||||||||||||||||||||||||
1856 | QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const | - | ||||||||||||||||||||||||
1857 | { | - | ||||||||||||||||||||||||
1858 | if (d->m_spec == Qt::OffsetFromUTC && d->m_offsetFromUtc == offsetSeconds) | - | ||||||||||||||||||||||||
1859 | return *this; | - | ||||||||||||||||||||||||
1860 | - | |||||||||||||||||||||||||
1861 | if (!isValid()) { | - | ||||||||||||||||||||||||
1862 | QDateTime ret = *this; | - | ||||||||||||||||||||||||
1863 | ret.setOffsetFromUtc(offsetSeconds); | - | ||||||||||||||||||||||||
1864 | return ret; | - | ||||||||||||||||||||||||
1865 | } | - | ||||||||||||||||||||||||
1866 | - | |||||||||||||||||||||||||
1867 | return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), Qt::OffsetFromUTC, offsetSeconds); | - | ||||||||||||||||||||||||
1868 | } | - | ||||||||||||||||||||||||
1869 | QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const | - | ||||||||||||||||||||||||
1870 | { | - | ||||||||||||||||||||||||
1871 | if (d->m_spec == Qt::TimeZone && d->m_timeZone == timeZone) | - | ||||||||||||||||||||||||
1872 | return *this; | - | ||||||||||||||||||||||||
1873 | - | |||||||||||||||||||||||||
1874 | if (!isValid()) { | - | ||||||||||||||||||||||||
1875 | QDateTime ret = *this; | - | ||||||||||||||||||||||||
1876 | ret.setTimeZone(timeZone); | - | ||||||||||||||||||||||||
1877 | return ret; | - | ||||||||||||||||||||||||
1878 | } | - | ||||||||||||||||||||||||
1879 | - | |||||||||||||||||||||||||
1880 | return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), timeZone); | - | ||||||||||||||||||||||||
1881 | } | - | ||||||||||||||||||||||||
1882 | bool QDateTime::operator==(const QDateTime &other) const | - | ||||||||||||||||||||||||
1883 | { | - | ||||||||||||||||||||||||
1884 | if (d->m_spec == Qt::LocalTime | - | ||||||||||||||||||||||||
1885 | && other.d->m_spec == Qt::LocalTime | - | ||||||||||||||||||||||||
1886 | && d->m_status == other.d->m_status) { | - | ||||||||||||||||||||||||
1887 | return (d->m_msecs == other.d->m_msecs); | - | ||||||||||||||||||||||||
1888 | } | - | ||||||||||||||||||||||||
1889 | - | |||||||||||||||||||||||||
1890 | return (toMSecsSinceEpoch() == other.toMSecsSinceEpoch()); | - | ||||||||||||||||||||||||
1891 | } | - | ||||||||||||||||||||||||
1892 | bool QDateTime::operator<(const QDateTime &other) const | - | ||||||||||||||||||||||||
1893 | { | - | ||||||||||||||||||||||||
1894 | if (d->m_spec == Qt::LocalTime | - | ||||||||||||||||||||||||
1895 | && other.d->m_spec == Qt::LocalTime | - | ||||||||||||||||||||||||
1896 | && d->m_status == other.d->m_status) { | - | ||||||||||||||||||||||||
1897 | return (d->m_msecs < other.d->m_msecs); | - | ||||||||||||||||||||||||
1898 | } | - | ||||||||||||||||||||||||
1899 | - | |||||||||||||||||||||||||
1900 | return (toMSecsSinceEpoch() < other.toMSecsSinceEpoch()); | - | ||||||||||||||||||||||||
1901 | } | - | ||||||||||||||||||||||||
1902 | QDate QDate::currentDate() | - | ||||||||||||||||||||||||
1903 | { | - | ||||||||||||||||||||||||
1904 | return QDateTime::currentDateTime().date(); | - | ||||||||||||||||||||||||
1905 | } | - | ||||||||||||||||||||||||
1906 | - | |||||||||||||||||||||||||
1907 | QTime QTime::currentTime() | - | ||||||||||||||||||||||||
1908 | { | - | ||||||||||||||||||||||||
1909 | return QDateTime::currentDateTime().time(); | - | ||||||||||||||||||||||||
1910 | } | - | ||||||||||||||||||||||||
1911 | - | |||||||||||||||||||||||||
1912 | QDateTime QDateTime::currentDateTime() | - | ||||||||||||||||||||||||
1913 | { | - | ||||||||||||||||||||||||
1914 | return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::LocalTime); | - | ||||||||||||||||||||||||
1915 | } | - | ||||||||||||||||||||||||
1916 | - | |||||||||||||||||||||||||
1917 | QDateTime QDateTime::currentDateTimeUtc() | - | ||||||||||||||||||||||||
1918 | { | - | ||||||||||||||||||||||||
1919 | return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::UTC); | - | ||||||||||||||||||||||||
1920 | } | - | ||||||||||||||||||||||||
1921 | - | |||||||||||||||||||||||||
1922 | qint64 QDateTime::currentMSecsSinceEpoch() noexcept | - | ||||||||||||||||||||||||
1923 | { | - | ||||||||||||||||||||||||
1924 | - | |||||||||||||||||||||||||
1925 | - | |||||||||||||||||||||||||
1926 | struct timeval tv; | - | ||||||||||||||||||||||||
1927 | gettimeofday(&tv, 0); | - | ||||||||||||||||||||||||
1928 | return executed 6948773 times by 70 tests: qint64(tv.tv_sec) * static_cast<long long>(1000LL) + tv.tv_usec / 1000;return qint64(tv.tv_sec) * static_cast<long long>(1000LL) + tv.tv_usec / 1000; Executed by:
executed 6948773 times by 70 tests: return qint64(tv.tv_sec) * static_cast<long long>(1000LL) + tv.tv_usec / 1000; Executed by:
| 6948773 | ||||||||||||||||||||||||
1929 | } | - | ||||||||||||||||||||||||
1930 | QDateTime QDateTime::fromTime_t(uint seconds) | - | ||||||||||||||||||||||||
1931 | { | - | ||||||||||||||||||||||||
1932 | return fromMSecsSinceEpoch((qint64)seconds * 1000, Qt::LocalTime); | - | ||||||||||||||||||||||||
1933 | } | - | ||||||||||||||||||||||||
1934 | QDateTime QDateTime::fromTime_t(uint seconds, Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||
1935 | { | - | ||||||||||||||||||||||||
1936 | return fromMSecsSinceEpoch((qint64)seconds * 1000, spec, offsetSeconds); | - | ||||||||||||||||||||||||
1937 | } | - | ||||||||||||||||||||||||
1938 | QDateTime QDateTime::fromTime_t(uint seconds, const QTimeZone &timeZone) | - | ||||||||||||||||||||||||
1939 | { | - | ||||||||||||||||||||||||
1940 | return fromMSecsSinceEpoch((qint64)seconds * 1000, timeZone); | - | ||||||||||||||||||||||||
1941 | } | - | ||||||||||||||||||||||||
1942 | QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs) | - | ||||||||||||||||||||||||
1943 | { | - | ||||||||||||||||||||||||
1944 | return fromMSecsSinceEpoch(msecs, Qt::LocalTime); | - | ||||||||||||||||||||||||
1945 | } | - | ||||||||||||||||||||||||
1946 | QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||
1947 | { | - | ||||||||||||||||||||||||
1948 | QDateTime dt; | - | ||||||||||||||||||||||||
1949 | dt.d->setTimeSpec(spec, offsetSeconds); | - | ||||||||||||||||||||||||
1950 | dt.setMSecsSinceEpoch(msecs); | - | ||||||||||||||||||||||||
1951 | return dt; | - | ||||||||||||||||||||||||
1952 | } | - | ||||||||||||||||||||||||
1953 | QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone) | - | ||||||||||||||||||||||||
1954 | { | - | ||||||||||||||||||||||||
1955 | QDateTime dt; | - | ||||||||||||||||||||||||
1956 | dt.setTimeZone(timeZone); | - | ||||||||||||||||||||||||
1957 | dt.setMSecsSinceEpoch(msecs); | - | ||||||||||||||||||||||||
1958 | return dt; | - | ||||||||||||||||||||||||
1959 | } | - | ||||||||||||||||||||||||
1960 | void QDateTime::setUtcOffset(int seconds) | - | ||||||||||||||||||||||||
1961 | { | - | ||||||||||||||||||||||||
1962 | setOffsetFromUtc(seconds); | - | ||||||||||||||||||||||||
1963 | } | - | ||||||||||||||||||||||||
1964 | int QDateTime::utcOffset() const | - | ||||||||||||||||||||||||
1965 | { | - | ||||||||||||||||||||||||
1966 | return offsetFromUtc(); | - | ||||||||||||||||||||||||
1967 | } | - | ||||||||||||||||||||||||
1968 | QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format) | - | ||||||||||||||||||||||||
1969 | { | - | ||||||||||||||||||||||||
1970 | if (string.isEmpty()
| 5-144 | ||||||||||||||||||||||||
1971 | return executed 5 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 5 times by 1 test: return QDateTime(); Executed by:
| 5 | ||||||||||||||||||||||||
1972 | - | |||||||||||||||||||||||||
1973 | switch (format) { | - | ||||||||||||||||||||||||
1974 | case executed 1 time by 1 test: Qt::SystemLocaleDate:case Qt::SystemLocaleDate: Executed by:
executed 1 time by 1 test: case Qt::SystemLocaleDate: Executed by:
| 1 | ||||||||||||||||||||||||
1975 | case executed 1 time by 1 test: Qt::SystemLocaleShortDate:case Qt::SystemLocaleShortDate: Executed by:
executed 1 time by 1 test: case Qt::SystemLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||
1976 | return executed 2 times by 1 test: QLocale::system().toDateTime(string, QLocale::ShortFormat);return QLocale::system().toDateTime(string, QLocale::ShortFormat); Executed by:
executed 2 times by 1 test: return QLocale::system().toDateTime(string, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||
1977 | case executed 1 time by 1 test: Qt::SystemLocaleLongDate:case Qt::SystemLocaleLongDate: Executed by:
executed 1 time by 1 test: case Qt::SystemLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||
1978 | return executed 1 time by 1 test: QLocale::system().toDateTime(string, QLocale::LongFormat);return QLocale::system().toDateTime(string, QLocale::LongFormat); Executed by:
executed 1 time by 1 test: return QLocale::system().toDateTime(string, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||
1979 | case executed 1 time by 1 test: Qt::LocaleDate:case Qt::LocaleDate: Executed by:
executed 1 time by 1 test: case Qt::LocaleDate: Executed by:
| 1 | ||||||||||||||||||||||||
1980 | case executed 1 time by 1 test: Qt::DefaultLocaleShortDate:case Qt::DefaultLocaleShortDate: Executed by:
executed 1 time by 1 test: case Qt::DefaultLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||
1981 | return executed 2 times by 1 test: QLocale().toDateTime(string, QLocale::ShortFormat);return QLocale().toDateTime(string, QLocale::ShortFormat); Executed by:
executed 2 times by 1 test: return QLocale().toDateTime(string, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||
1982 | case executed 1 time by 1 test: Qt::DefaultLocaleLongDate:case Qt::DefaultLocaleLongDate: Executed by:
executed 1 time by 1 test: case Qt::DefaultLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||
1983 | return executed 1 time by 1 test: QLocale().toDateTime(string, QLocale::LongFormat);return QLocale().toDateTime(string, QLocale::LongFormat); Executed by:
executed 1 time by 1 test: return QLocale().toDateTime(string, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||
1984 | case executed 30 times by 1 test: Qt::RFC2822Date:case Qt::RFC2822Date: Executed by:
executed 30 times by 1 test: {case Qt::RFC2822Date: Executed by:
| 30 | ||||||||||||||||||||||||
1985 | const ParsedRfcDateTime rfc = rfcDateImpl(string); | - | ||||||||||||||||||||||||
1986 | - | |||||||||||||||||||||||||
1987 | if (!rfc.date.isValid()
| 3-19 | ||||||||||||||||||||||||
1988 | return executed 14 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 14 times by 1 test: return QDateTime(); Executed by:
| 14 | ||||||||||||||||||||||||
1989 | - | |||||||||||||||||||||||||
1990 | QDateTime dateTime(rfc.date, rfc.time, Qt::UTC); | - | ||||||||||||||||||||||||
1991 | dateTime.setOffsetFromUtc(rfc.utcOffset); | - | ||||||||||||||||||||||||
1992 | return executed 16 times by 1 test: dateTime;return dateTime; Executed by:
executed 16 times by 1 test: return dateTime; Executed by:
| 16 | ||||||||||||||||||||||||
1993 | } | - | ||||||||||||||||||||||||
1994 | case executed 66 times by 4 tests: Qt::ISODate:case Qt::ISODate: Executed by:
executed 66 times by 4 tests: {case Qt::ISODate: Executed by:
| 66 | ||||||||||||||||||||||||
1995 | const int size = string.size(); | - | ||||||||||||||||||||||||
1996 | if (size < 10
| 4-62 | ||||||||||||||||||||||||
1997 | return executed 4 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 4 times by 1 test: return QDateTime(); Executed by:
| 4 | ||||||||||||||||||||||||
1998 | - | |||||||||||||||||||||||||
1999 | QStringRef isoString(&string); | - | ||||||||||||||||||||||||
2000 | Qt::TimeSpec spec = Qt::LocalTime; | - | ||||||||||||||||||||||||
2001 | - | |||||||||||||||||||||||||
2002 | QDate date = QDate::fromString(string.left(10), Qt::ISODate); | - | ||||||||||||||||||||||||
2003 | if (!date.isValid()
| 7-55 | ||||||||||||||||||||||||
2004 | return executed 7 times by 2 tests: QDateTime();return QDateTime(); Executed by:
executed 7 times by 2 tests: return QDateTime(); Executed by:
| 7 | ||||||||||||||||||||||||
2005 | if (size == 10
| 1-54 | ||||||||||||||||||||||||
2006 | return executed 1 time by 1 test: QDateTime(date);return QDateTime(date); Executed by:
executed 1 time by 1 test: return QDateTime(date); Executed by:
| 1 | ||||||||||||||||||||||||
2007 | - | |||||||||||||||||||||||||
2008 | isoString = isoString.right(isoString.length() - 11); | - | ||||||||||||||||||||||||
2009 | int offset = 0; | - | ||||||||||||||||||||||||
2010 | - | |||||||||||||||||||||||||
2011 | if (isoString.endsWith(QLatin1Char('Z'))
| 6-48 | ||||||||||||||||||||||||
2012 | spec = Qt::UTC; | - | ||||||||||||||||||||||||
2013 | isoString = isoString.left(isoString.size() - 1); | - | ||||||||||||||||||||||||
2014 | } executed 6 times by 1 test: else {end of block Executed by:
| 6 | ||||||||||||||||||||||||
2015 | - | |||||||||||||||||||||||||
2016 | - | |||||||||||||||||||||||||
2017 | int signIndex = isoString.size() - 1; | - | ||||||||||||||||||||||||
2018 | bool found = false; | - | ||||||||||||||||||||||||
2019 | { | - | ||||||||||||||||||||||||
2020 | const QChar plus = QLatin1Char('+'); | - | ||||||||||||||||||||||||
2021 | const QChar minus = QLatin1Char('-'); | - | ||||||||||||||||||||||||
2022 | do { | - | ||||||||||||||||||||||||
2023 | QChar character(isoString.at(signIndex)); | - | ||||||||||||||||||||||||
2024 | found = character == plus
| 5-397 | ||||||||||||||||||||||||
2025 | } executed 402 times by 4 tests: while (--end of block Executed by:
| 13-402 | ||||||||||||||||||||||||
2026 | ++signIndex; | - | ||||||||||||||||||||||||
2027 | } | - | ||||||||||||||||||||||||
2028 | - | |||||||||||||||||||||||||
2029 | if (found
| 13-35 | ||||||||||||||||||||||||
2030 | bool ok; | - | ||||||||||||||||||||||||
2031 | offset = fromOffsetString(isoString.mid(signIndex), &ok); | - | ||||||||||||||||||||||||
2032 | if (!ok
| 0-13 | ||||||||||||||||||||||||
2033 | return never executed: QDateTime();return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||
2034 | isoString = isoString.left(signIndex); | - | ||||||||||||||||||||||||
2035 | spec = Qt::OffsetFromUTC; | - | ||||||||||||||||||||||||
2036 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||
2037 | } executed 48 times by 4 tests: end of block Executed by:
| 48 | ||||||||||||||||||||||||
2038 | - | |||||||||||||||||||||||||
2039 | - | |||||||||||||||||||||||||
2040 | - | |||||||||||||||||||||||||
2041 | bool isMidnight24 = false; | - | ||||||||||||||||||||||||
2042 | QTime time = fromIsoTimeString(isoString, Qt::ISODate, &isMidnight24); | - | ||||||||||||||||||||||||
2043 | if (!time.isValid()
| 0-54 | ||||||||||||||||||||||||
2044 | return never executed: QDateTime();return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||
2045 | if (isMidnight24
| 5-49 | ||||||||||||||||||||||||
2046 | date = date.addDays(1); executed 5 times by 1 test: date = date.addDays(1); Executed by:
| 5 | ||||||||||||||||||||||||
2047 | return executed 54 times by 4 tests: QDateTime(date, time, spec, offset);return QDateTime(date, time, spec, offset); Executed by:
executed 54 times by 4 tests: return QDateTime(date, time, spec, offset); Executed by:
| 54 | ||||||||||||||||||||||||
2048 | } | - | ||||||||||||||||||||||||
2049 | - | |||||||||||||||||||||||||
2050 | case executed 42 times by 3 tests: Qt::TextDate:case Qt::TextDate: Executed by:
executed 42 times by 3 tests: {case Qt::TextDate: Executed by:
| 42 | ||||||||||||||||||||||||
2051 | QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||
2052 | - | |||||||||||||||||||||||||
2053 | if ((
| 1-41 | ||||||||||||||||||||||||
2054 | return executed 2 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 2 times by 1 test: return QDateTime(); Executed by:
| 2 | ||||||||||||||||||||||||
2055 | - | |||||||||||||||||||||||||
2056 | - | |||||||||||||||||||||||||
2057 | int month = 0; | - | ||||||||||||||||||||||||
2058 | int day = 0; | - | ||||||||||||||||||||||||
2059 | bool ok = false; | - | ||||||||||||||||||||||||
2060 | - | |||||||||||||||||||||||||
2061 | - | |||||||||||||||||||||||||
2062 | month = fromShortMonthName(parts.at(1)); | - | ||||||||||||||||||||||||
2063 | if (month
| 0-40 | ||||||||||||||||||||||||
2064 | day = parts.at(2).toInt(); executed 40 times by 3 tests: day = parts.at(2).toInt(); Executed by:
| 40 | ||||||||||||||||||||||||
2065 | - | |||||||||||||||||||||||||
2066 | - | |||||||||||||||||||||||||
2067 | if (!month
| 0-40 | ||||||||||||||||||||||||
2068 | month = fromShortMonthName(parts.at(2)); | - | ||||||||||||||||||||||||
2069 | if (month
| 0-14 | ||||||||||||||||||||||||
2070 | QStringRef dayStr = parts.at(1); | - | ||||||||||||||||||||||||
2071 | if (dayStr.endsWith(QLatin1Char('.'))
| 2-12 | ||||||||||||||||||||||||
2072 | dayStr = dayStr.left(dayStr.size() - 1); | - | ||||||||||||||||||||||||
2073 | day = dayStr.toInt(); | - | ||||||||||||||||||||||||
2074 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||
2075 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||
2076 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||
2077 | - | |||||||||||||||||||||||||
2078 | - | |||||||||||||||||||||||||
2079 | if (!month
| 0-40 | ||||||||||||||||||||||||
2080 | return executed 3 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 3 times by 1 test: return QDateTime(); Executed by:
| 3 | ||||||||||||||||||||||||
2081 | - | |||||||||||||||||||||||||
2082 | - | |||||||||||||||||||||||||
2083 | - | |||||||||||||||||||||||||
2084 | int year = 0; | - | ||||||||||||||||||||||||
2085 | int yearPart = 0; | - | ||||||||||||||||||||||||
2086 | int timePart = 0; | - | ||||||||||||||||||||||||
2087 | if (parts.at(3).contains(QLatin1Char(':'))
| 14-23 | ||||||||||||||||||||||||
2088 | yearPart = 4; | - | ||||||||||||||||||||||||
2089 | timePart = 3; | - | ||||||||||||||||||||||||
2090 | } executed 23 times by 3 tests: else if (parts.at(4).contains(QLatin1Char(':'))end of block Executed by:
| 1-23 | ||||||||||||||||||||||||
2091 | yearPart = 3; | - | ||||||||||||||||||||||||
2092 | timePart = 4; | - | ||||||||||||||||||||||||
2093 | } executed 13 times by 1 test: else {end of block Executed by:
| 13 | ||||||||||||||||||||||||
2094 | return executed 1 time by 1 test: QDateTime();return QDateTime(); Executed by:
executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||
2095 | } | - | ||||||||||||||||||||||||
2096 | - | |||||||||||||||||||||||||
2097 | year = parts.at(yearPart).toInt(&ok); | - | ||||||||||||||||||||||||
2098 | if (!ok
| 2-34 | ||||||||||||||||||||||||
2099 | return executed 2 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 2 times by 1 test: return QDateTime(); Executed by:
| 2 | ||||||||||||||||||||||||
2100 | - | |||||||||||||||||||||||||
2101 | QDate date(year, month, day); | - | ||||||||||||||||||||||||
2102 | if (!date.isValid()
| 2-32 | ||||||||||||||||||||||||
2103 | return executed 2 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 2 times by 1 test: return QDateTime(); Executed by:
| 2 | ||||||||||||||||||||||||
2104 | - | |||||||||||||||||||||||||
2105 | QVector<QStringRef> timeParts = parts.at(timePart).split(QLatin1Char(':')); | - | ||||||||||||||||||||||||
2106 | if (timeParts.count() < 2
| 0-32 | ||||||||||||||||||||||||
2107 | return executed 1 time by 1 test: QDateTime();return QDateTime(); Executed by:
executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||
2108 | - | |||||||||||||||||||||||||
2109 | int hour = timeParts.at(0).toInt(&ok); | - | ||||||||||||||||||||||||
2110 | if (!ok
| 1-30 | ||||||||||||||||||||||||
2111 | return executed 1 time by 1 test: QDateTime();return QDateTime(); Executed by:
executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||
2112 | - | |||||||||||||||||||||||||
2113 | int minute = timeParts.at(1).toInt(&ok); | - | ||||||||||||||||||||||||
2114 | if (!ok
| 1-29 | ||||||||||||||||||||||||
2115 | return executed 1 time by 1 test: QDateTime();return QDateTime(); Executed by:
executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||
2116 | - | |||||||||||||||||||||||||
2117 | int second = 0; | - | ||||||||||||||||||||||||
2118 | int millisecond = 0; | - | ||||||||||||||||||||||||
2119 | if (timeParts.count() > 2
| 1-28 | ||||||||||||||||||||||||
2120 | const QVector<QStringRef> secondParts = timeParts.at(2).split(QLatin1Char('.')); | - | ||||||||||||||||||||||||
2121 | if (secondParts.size() > 2
| 0-28 | ||||||||||||||||||||||||
2122 | return never executed: QDateTime();return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||
2123 | } | - | ||||||||||||||||||||||||
2124 | - | |||||||||||||||||||||||||
2125 | second = secondParts.first().toInt(&ok); | - | ||||||||||||||||||||||||
2126 | if (!ok
| 1-27 | ||||||||||||||||||||||||
2127 | return executed 1 time by 1 test: QDateTime();return QDateTime(); Executed by:
executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||
2128 | } | - | ||||||||||||||||||||||||
2129 | - | |||||||||||||||||||||||||
2130 | if (secondParts.size() > 1
| 1-26 | ||||||||||||||||||||||||
2131 | millisecond = secondParts.last().toInt(&ok); | - | ||||||||||||||||||||||||
2132 | if (!ok
| 0-1 | ||||||||||||||||||||||||
2133 | return never executed: QDateTime();return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||
2134 | } | - | ||||||||||||||||||||||||
2135 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||
2136 | } executed 27 times by 3 tests: end of block Executed by:
| 27 | ||||||||||||||||||||||||
2137 | - | |||||||||||||||||||||||||
2138 | QTime time(hour, minute, second, millisecond); | - | ||||||||||||||||||||||||
2139 | if (!time.isValid()
| 0-28 | ||||||||||||||||||||||||
2140 | return never executed: QDateTime();return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||
2141 | - | |||||||||||||||||||||||||
2142 | if (parts.count() == 5
| 13-15 | ||||||||||||||||||||||||
2143 | return executed 15 times by 3 tests: QDateTime(date, time, Qt::LocalTime);return QDateTime(date, time, Qt::LocalTime); Executed by:
executed 15 times by 3 tests: return QDateTime(date, time, Qt::LocalTime); Executed by:
| 15 | ||||||||||||||||||||||||
2144 | - | |||||||||||||||||||||||||
2145 | QStringRef tz = parts.at(5); | - | ||||||||||||||||||||||||
2146 | if (!tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive)
| 1-12 | ||||||||||||||||||||||||
2147 | return executed 1 time by 1 test: QDateTime();return QDateTime(); Executed by:
executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||
2148 | tz = tz.mid(3); | - | ||||||||||||||||||||||||
2149 | if (!tz.isEmpty()
| 3-9 | ||||||||||||||||||||||||
2150 | int offset = fromOffsetString(tz, &ok); | - | ||||||||||||||||||||||||
2151 | if (!ok
| 4-5 | ||||||||||||||||||||||||
2152 | return executed 4 times by 1 test: QDateTime();return QDateTime(); Executed by:
executed 4 times by 1 test: return QDateTime(); Executed by:
| 4 | ||||||||||||||||||||||||
2153 | return executed 5 times by 1 test: QDateTime(date, time, Qt::OffsetFromUTC, offset);return QDateTime(date, time, Qt::OffsetFromUTC, offset); Executed by:
executed 5 times by 1 test: return QDateTime(date, time, Qt::OffsetFromUTC, offset); Executed by:
| 5 | ||||||||||||||||||||||||
2154 | } else { | - | ||||||||||||||||||||||||
2155 | return executed 3 times by 1 test: QDateTime(date, time, Qt::UTC);return QDateTime(date, time, Qt::UTC); Executed by:
executed 3 times by 1 test: return QDateTime(date, time, Qt::UTC); Executed by:
| 3 | ||||||||||||||||||||||||
2156 | } | - | ||||||||||||||||||||||||
2157 | } | - | ||||||||||||||||||||||||
2158 | - | |||||||||||||||||||||||||
2159 | } | - | ||||||||||||||||||||||||
2160 | - | |||||||||||||||||||||||||
2161 | return never executed: QDateTime();return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||
2162 | } | - | ||||||||||||||||||||||||
2163 | QDateTime QDateTime::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||
2164 | { | - | ||||||||||||||||||||||||
2165 | - | |||||||||||||||||||||||||
2166 | QTime time; | - | ||||||||||||||||||||||||
2167 | QDate date; | - | ||||||||||||||||||||||||
2168 | - | |||||||||||||||||||||||||
2169 | QDateTimeParser dt(QVariant::DateTime, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||
2170 | if (dt.parseFormat(format)
| 0-49 | ||||||||||||||||||||||||
2171 | return executed 41 times by 4 tests: QDateTime(date, time);return QDateTime(date, time); Executed by:
executed 41 times by 4 tests: return QDateTime(date, time); Executed by:
| 41 | ||||||||||||||||||||||||
2172 | - | |||||||||||||||||||||||||
2173 | - | |||||||||||||||||||||||||
2174 | - | |||||||||||||||||||||||||
2175 | - | |||||||||||||||||||||||||
2176 | return executed 8 times by 1 test: QDateTime(QDate(), QTime(-1, -1, -1));();return QDateTime(); Executed by:
executed 8 times by 1 test: return QDateTime(); Executed by:
| 8 | ||||||||||||||||||||||||
2177 | } | - | ||||||||||||||||||||||||
2178 | QDataStream &operator<<(QDataStream &out, const QDate &date) | - | ||||||||||||||||||||||||
2179 | { | - | ||||||||||||||||||||||||
2180 | if (out.version() < QDataStream::Qt_5_0) | - | ||||||||||||||||||||||||
2181 | return out << quint32(date.jd); | - | ||||||||||||||||||||||||
2182 | else | - | ||||||||||||||||||||||||
2183 | return out << qint64(date.jd); | - | ||||||||||||||||||||||||
2184 | } | - | ||||||||||||||||||||||||
2185 | QDataStream &operator>>(QDataStream &in, QDate &date) | - | ||||||||||||||||||||||||
2186 | { | - | ||||||||||||||||||||||||
2187 | if (in.version() < QDataStream::Qt_5_0) { | - | ||||||||||||||||||||||||
2188 | quint32 jd; | - | ||||||||||||||||||||||||
2189 | in >> jd; | - | ||||||||||||||||||||||||
2190 | - | |||||||||||||||||||||||||
2191 | date.jd = (jd != 0 ? jd : QDate::nullJd()); | - | ||||||||||||||||||||||||
2192 | } else { | - | ||||||||||||||||||||||||
2193 | qint64 jd; | - | ||||||||||||||||||||||||
2194 | in >> jd; | - | ||||||||||||||||||||||||
2195 | date.jd = jd; | - | ||||||||||||||||||||||||
2196 | } | - | ||||||||||||||||||||||||
2197 | - | |||||||||||||||||||||||||
2198 | return in; | - | ||||||||||||||||||||||||
2199 | } | - | ||||||||||||||||||||||||
2200 | QDataStream &operator<<(QDataStream &out, const QTime &time) | - | ||||||||||||||||||||||||
2201 | { | - | ||||||||||||||||||||||||
2202 | if (out.version() >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
2203 | return out << quint32(time.mds); | - | ||||||||||||||||||||||||
2204 | } else { | - | ||||||||||||||||||||||||
2205 | - | |||||||||||||||||||||||||
2206 | return out << quint32(time.isNull() ? 0 : time.mds); | - | ||||||||||||||||||||||||
2207 | } | - | ||||||||||||||||||||||||
2208 | } | - | ||||||||||||||||||||||||
2209 | QDataStream &operator>>(QDataStream &in, QTime &time) | - | ||||||||||||||||||||||||
2210 | { | - | ||||||||||||||||||||||||
2211 | quint32 ds; | - | ||||||||||||||||||||||||
2212 | in >> ds; | - | ||||||||||||||||||||||||
2213 | if (in.version() >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
2214 | time.mds = int(ds); | - | ||||||||||||||||||||||||
2215 | } else { | - | ||||||||||||||||||||||||
2216 | - | |||||||||||||||||||||||||
2217 | time.mds = (ds == 0) ? QTime::NullTime : int(ds); | - | ||||||||||||||||||||||||
2218 | } | - | ||||||||||||||||||||||||
2219 | return in; | - | ||||||||||||||||||||||||
2220 | } | - | ||||||||||||||||||||||||
2221 | QDataStream &operator<<(QDataStream &out, const QDateTime &dateTime) | - | ||||||||||||||||||||||||
2222 | { | - | ||||||||||||||||||||||||
2223 | QPair<QDate, QTime> dateAndTime; | - | ||||||||||||||||||||||||
2224 | - | |||||||||||||||||||||||||
2225 | if (out.version() >= QDataStream::Qt_5_2) { | - | ||||||||||||||||||||||||
2226 | - | |||||||||||||||||||||||||
2227 | - | |||||||||||||||||||||||||
2228 | dateAndTime = dateTime.d->getDateTime(); | - | ||||||||||||||||||||||||
2229 | out << dateAndTime << qint8(dateTime.timeSpec()); | - | ||||||||||||||||||||||||
2230 | if (dateTime.timeSpec() == Qt::OffsetFromUTC) | - | ||||||||||||||||||||||||
2231 | out << qint32(dateTime.offsetFromUtc()); | - | ||||||||||||||||||||||||
2232 | - | |||||||||||||||||||||||||
2233 | else if (dateTime.timeSpec() == Qt::TimeZone) | - | ||||||||||||||||||||||||
2234 | out << dateTime.timeZone(); | - | ||||||||||||||||||||||||
2235 | - | |||||||||||||||||||||||||
2236 | - | |||||||||||||||||||||||||
2237 | } else if (out.version() == QDataStream::Qt_5_0) { | - | ||||||||||||||||||||||||
2238 | - | |||||||||||||||||||||||||
2239 | - | |||||||||||||||||||||||||
2240 | - | |||||||||||||||||||||||||
2241 | - | |||||||||||||||||||||||||
2242 | - | |||||||||||||||||||||||||
2243 | dateAndTime = (dateTime.isValid() ? dateTime.toUTC() : dateTime).d->getDateTime(); | - | ||||||||||||||||||||||||
2244 | out << dateAndTime << qint8(dateTime.timeSpec()); | - | ||||||||||||||||||||||||
2245 | - | |||||||||||||||||||||||||
2246 | } else if (out.version() >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
2247 | - | |||||||||||||||||||||||||
2248 | - | |||||||||||||||||||||||||
2249 | dateAndTime = dateTime.d->getDateTime(); | - | ||||||||||||||||||||||||
2250 | out << dateAndTime; | - | ||||||||||||||||||||||||
2251 | switch (dateTime.timeSpec()) { | - | ||||||||||||||||||||||||
2252 | case Qt::UTC: | - | ||||||||||||||||||||||||
2253 | out << (qint8)QDateTimePrivate::UTC; | - | ||||||||||||||||||||||||
2254 | break; | - | ||||||||||||||||||||||||
2255 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
2256 | out << (qint8)QDateTimePrivate::OffsetFromUTC; | - | ||||||||||||||||||||||||
2257 | break; | - | ||||||||||||||||||||||||
2258 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
2259 | out << (qint8)QDateTimePrivate::TimeZone; | - | ||||||||||||||||||||||||
2260 | break; | - | ||||||||||||||||||||||||
2261 | case Qt::LocalTime: | - | ||||||||||||||||||||||||
2262 | out << (qint8)QDateTimePrivate::LocalUnknown; | - | ||||||||||||||||||||||||
2263 | break; | - | ||||||||||||||||||||||||
2264 | } | - | ||||||||||||||||||||||||
2265 | - | |||||||||||||||||||||||||
2266 | } else { | - | ||||||||||||||||||||||||
2267 | - | |||||||||||||||||||||||||
2268 | - | |||||||||||||||||||||||||
2269 | dateAndTime = dateTime.d->getDateTime(); | - | ||||||||||||||||||||||||
2270 | out << dateAndTime; | - | ||||||||||||||||||||||||
2271 | - | |||||||||||||||||||||||||
2272 | } | - | ||||||||||||||||||||||||
2273 | - | |||||||||||||||||||||||||
2274 | return out; | - | ||||||||||||||||||||||||
2275 | } | - | ||||||||||||||||||||||||
2276 | QDataStream &operator>>(QDataStream &in, QDateTime &dateTime) | - | ||||||||||||||||||||||||
2277 | { | - | ||||||||||||||||||||||||
2278 | QDate dt; | - | ||||||||||||||||||||||||
2279 | QTime tm; | - | ||||||||||||||||||||||||
2280 | qint8 ts = 0; | - | ||||||||||||||||||||||||
2281 | Qt::TimeSpec spec = Qt::LocalTime; | - | ||||||||||||||||||||||||
2282 | qint32 offset = 0; | - | ||||||||||||||||||||||||
2283 | - | |||||||||||||||||||||||||
2284 | QTimeZone tz; | - | ||||||||||||||||||||||||
2285 | - | |||||||||||||||||||||||||
2286 | - | |||||||||||||||||||||||||
2287 | if (in.version() >= QDataStream::Qt_5_2) { | - | ||||||||||||||||||||||||
2288 | - | |||||||||||||||||||||||||
2289 | - | |||||||||||||||||||||||||
2290 | in >> dt >> tm >> ts; | - | ||||||||||||||||||||||||
2291 | spec = static_cast<Qt::TimeSpec>(ts); | - | ||||||||||||||||||||||||
2292 | if (spec == Qt::OffsetFromUTC) { | - | ||||||||||||||||||||||||
2293 | in >> offset; | - | ||||||||||||||||||||||||
2294 | dateTime = QDateTime(dt, tm, spec, offset); | - | ||||||||||||||||||||||||
2295 | - | |||||||||||||||||||||||||
2296 | } else if (spec == Qt::TimeZone) { | - | ||||||||||||||||||||||||
2297 | in >> tz; | - | ||||||||||||||||||||||||
2298 | dateTime = QDateTime(dt, tm, tz); | - | ||||||||||||||||||||||||
2299 | - | |||||||||||||||||||||||||
2300 | } else { | - | ||||||||||||||||||||||||
2301 | dateTime = QDateTime(dt, tm, spec); | - | ||||||||||||||||||||||||
2302 | } | - | ||||||||||||||||||||||||
2303 | - | |||||||||||||||||||||||||
2304 | } else if (in.version() == QDataStream::Qt_5_0) { | - | ||||||||||||||||||||||||
2305 | - | |||||||||||||||||||||||||
2306 | - | |||||||||||||||||||||||||
2307 | in >> dt >> tm >> ts; | - | ||||||||||||||||||||||||
2308 | spec = static_cast<Qt::TimeSpec>(ts); | - | ||||||||||||||||||||||||
2309 | dateTime = QDateTime(dt, tm, Qt::UTC); | - | ||||||||||||||||||||||||
2310 | dateTime = dateTime.toTimeSpec(spec); | - | ||||||||||||||||||||||||
2311 | - | |||||||||||||||||||||||||
2312 | } else if (in.version() >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
2313 | - | |||||||||||||||||||||||||
2314 | - | |||||||||||||||||||||||||
2315 | in >> dt >> tm >> ts; | - | ||||||||||||||||||||||||
2316 | switch ((QDateTimePrivate::Spec)ts) { | - | ||||||||||||||||||||||||
2317 | case QDateTimePrivate::UTC: | - | ||||||||||||||||||||||||
2318 | spec = Qt::UTC; | - | ||||||||||||||||||||||||
2319 | break; | - | ||||||||||||||||||||||||
2320 | case QDateTimePrivate::OffsetFromUTC: | - | ||||||||||||||||||||||||
2321 | spec = Qt::OffsetFromUTC; | - | ||||||||||||||||||||||||
2322 | break; | - | ||||||||||||||||||||||||
2323 | case QDateTimePrivate::TimeZone: | - | ||||||||||||||||||||||||
2324 | spec = Qt::TimeZone; | - | ||||||||||||||||||||||||
2325 | - | |||||||||||||||||||||||||
2326 | - | |||||||||||||||||||||||||
2327 | - | |||||||||||||||||||||||||
2328 | break; | - | ||||||||||||||||||||||||
2329 | case QDateTimePrivate::LocalUnknown: | - | ||||||||||||||||||||||||
2330 | case QDateTimePrivate::LocalStandard: | - | ||||||||||||||||||||||||
2331 | case QDateTimePrivate::LocalDST: | - | ||||||||||||||||||||||||
2332 | spec = Qt::LocalTime; | - | ||||||||||||||||||||||||
2333 | break; | - | ||||||||||||||||||||||||
2334 | } | - | ||||||||||||||||||||||||
2335 | dateTime = QDateTime(dt, tm, spec, offset); | - | ||||||||||||||||||||||||
2336 | - | |||||||||||||||||||||||||
2337 | } else { | - | ||||||||||||||||||||||||
2338 | - | |||||||||||||||||||||||||
2339 | - | |||||||||||||||||||||||||
2340 | in >> dt >> tm; | - | ||||||||||||||||||||||||
2341 | dateTime = QDateTime(dt, tm, spec, offset); | - | ||||||||||||||||||||||||
2342 | - | |||||||||||||||||||||||||
2343 | } | - | ||||||||||||||||||||||||
2344 | - | |||||||||||||||||||||||||
2345 | return in; | - | ||||||||||||||||||||||||
2346 | } | - | ||||||||||||||||||||||||
2347 | - | |||||||||||||||||||||||||
2348 | - | |||||||||||||||||||||||||
2349 | - | |||||||||||||||||||||||||
2350 | - | |||||||||||||||||||||||||
2351 | - | |||||||||||||||||||||||||
2352 | - | |||||||||||||||||||||||||
2353 | - | |||||||||||||||||||||||||
2354 | QDebug operator<<(QDebug dbg, const QDate &date) | - | ||||||||||||||||||||||||
2355 | { | - | ||||||||||||||||||||||||
2356 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
2357 | dbg.nospace() << "QDate(" << date.toString(Qt::ISODate) << ')'; | - | ||||||||||||||||||||||||
2358 | return dbg; | - | ||||||||||||||||||||||||
2359 | } | - | ||||||||||||||||||||||||
2360 | - | |||||||||||||||||||||||||
2361 | QDebug operator<<(QDebug dbg, const QTime &time) | - | ||||||||||||||||||||||||
2362 | { | - | ||||||||||||||||||||||||
2363 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
2364 | dbg.nospace() << "QTime(" << time.toString(([]() -> QString { enum { Size = sizeof(u"" "HH:mm:ss.zzz")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "HH:mm:ss.zzz" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) << ')'; | - | ||||||||||||||||||||||||
2365 | return dbg; | - | ||||||||||||||||||||||||
2366 | } | - | ||||||||||||||||||||||||
2367 | - | |||||||||||||||||||||||||
2368 | QDebug operator<<(QDebug dbg, const QDateTime &date) | - | ||||||||||||||||||||||||
2369 | { | - | ||||||||||||||||||||||||
2370 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
2371 | const Qt::TimeSpec ts = date.timeSpec(); | - | ||||||||||||||||||||||||
2372 | dbg.nospace() << "QDateTime("; | - | ||||||||||||||||||||||||
2373 | dbg.noquote() << date.toString(([]() -> QString { enum { Size = sizeof(u"" "yyyy-MM-dd HH:mm:ss.zzz t")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "yyyy-MM-dd HH:mm:ss.zzz t" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())) | - | ||||||||||||||||||||||||
2374 | << ' ' << ts; | - | ||||||||||||||||||||||||
2375 | switch (ts) { | - | ||||||||||||||||||||||||
2376 | case Qt::UTC: | - | ||||||||||||||||||||||||
2377 | break; | - | ||||||||||||||||||||||||
2378 | case Qt::OffsetFromUTC: | - | ||||||||||||||||||||||||
2379 | dbg << ' ' << date.offsetFromUtc() << 's'; | - | ||||||||||||||||||||||||
2380 | break; | - | ||||||||||||||||||||||||
2381 | case Qt::TimeZone: | - | ||||||||||||||||||||||||
2382 | - | |||||||||||||||||||||||||
2383 | dbg << ' ' << date.timeZone().id(); | - | ||||||||||||||||||||||||
2384 | - | |||||||||||||||||||||||||
2385 | break; | - | ||||||||||||||||||||||||
2386 | case Qt::LocalTime: | - | ||||||||||||||||||||||||
2387 | break; | - | ||||||||||||||||||||||||
2388 | } | - | ||||||||||||||||||||||||
2389 | return dbg << ')'; | - | ||||||||||||||||||||||||
2390 | } | - | ||||||||||||||||||||||||
2391 | uint qHash(const QDateTime &key, uint seed) | - | ||||||||||||||||||||||||
2392 | { | - | ||||||||||||||||||||||||
2393 | - | |||||||||||||||||||||||||
2394 | - | |||||||||||||||||||||||||
2395 | - | |||||||||||||||||||||||||
2396 | - | |||||||||||||||||||||||||
2397 | return qHash(key.toMSecsSinceEpoch(), seed); | - | ||||||||||||||||||||||||
2398 | } | - | ||||||||||||||||||||||||
2399 | - | |||||||||||||||||||||||||
2400 | - | |||||||||||||||||||||||||
2401 | - | |||||||||||||||||||||||||
2402 | - | |||||||||||||||||||||||||
2403 | - | |||||||||||||||||||||||||
2404 | - | |||||||||||||||||||||||||
2405 | - | |||||||||||||||||||||||||
2406 | uint qHash(const QDate &key, uint seed) noexcept | - | ||||||||||||||||||||||||
2407 | { | - | ||||||||||||||||||||||||
2408 | return executed 6 times by 1 test: qHash(key.toJulianDay(), seed);return qHash(key.toJulianDay(), seed); Executed by:
executed 6 times by 1 test: return qHash(key.toJulianDay(), seed); Executed by:
| 6 | ||||||||||||||||||||||||
2409 | } | - | ||||||||||||||||||||||||
2410 | - | |||||||||||||||||||||||||
2411 | - | |||||||||||||||||||||||||
2412 | - | |||||||||||||||||||||||||
2413 | - | |||||||||||||||||||||||||
2414 | - | |||||||||||||||||||||||||
2415 | - | |||||||||||||||||||||||||
2416 | - | |||||||||||||||||||||||||
2417 | uint qHash(const QTime &key, uint seed) noexcept | - | ||||||||||||||||||||||||
2418 | { | - | ||||||||||||||||||||||||
2419 | return executed 4 times by 1 test: qHash(key.msecsSinceStartOfDay(), seed);return qHash(key.msecsSinceStartOfDay(), seed); Executed by:
executed 4 times by 1 test: return qHash(key.msecsSinceStartOfDay(), seed); Executed by:
| 4 | ||||||||||||||||||||||||
2420 | } | - | ||||||||||||||||||||||||
2421 | - | |||||||||||||||||||||||||
2422 | - | |||||||||||||||||||||||||
Switch to Source code | Preprocessed file |