Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qdatetime.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||||||||
34 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||||||||
35 | #include "private/qdatetime_p.h" | - | ||||||||||||||||||||||||||||||
36 | #include "private/qdatetimeparser_p.h" | - | ||||||||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||||||||
38 | #include "qdatastream.h" | - | ||||||||||||||||||||||||||||||
39 | #include "qset.h" | - | ||||||||||||||||||||||||||||||
40 | #include "qlocale.h" | - | ||||||||||||||||||||||||||||||
41 | #include "qdatetime.h" | - | ||||||||||||||||||||||||||||||
42 | #include "qtimezoneprivate_p.h" | - | ||||||||||||||||||||||||||||||
43 | #include "qregexp.h" | - | ||||||||||||||||||||||||||||||
44 | #include "qdebug.h" | - | ||||||||||||||||||||||||||||||
45 | #ifndef Q_OS_WIN | - | ||||||||||||||||||||||||||||||
46 | #include <locale.h> | - | ||||||||||||||||||||||||||||||
47 | #endif | - | ||||||||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||||||||
49 | #include <cmath> | - | ||||||||||||||||||||||||||||||
50 | #include <time.h> | - | ||||||||||||||||||||||||||||||
51 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||||||||
52 | # include <qt_windows.h> | - | ||||||||||||||||||||||||||||||
53 | # ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||||||||
54 | # include "qfunctions_wince.h" | - | ||||||||||||||||||||||||||||||
55 | # endif | - | ||||||||||||||||||||||||||||||
56 | # ifdef Q_OS_WINRT | - | ||||||||||||||||||||||||||||||
57 | # include "qfunctions_winrt.h" | - | ||||||||||||||||||||||||||||||
58 | # endif | - | ||||||||||||||||||||||||||||||
59 | #endif | - | ||||||||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||||||||
61 | #if defined(Q_OS_MAC) | - | ||||||||||||||||||||||||||||||
62 | #include <private/qcore_mac_p.h> | - | ||||||||||||||||||||||||||||||
63 | #endif | - | ||||||||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||||||||
65 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||||||||
67 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
68 | Date/Time Constants | - | ||||||||||||||||||||||||||||||
69 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||||||||
71 | enum { | - | ||||||||||||||||||||||||||||||
72 | SECS_PER_DAY = 86400, | - | ||||||||||||||||||||||||||||||
73 | MSECS_PER_DAY = 86400000, | - | ||||||||||||||||||||||||||||||
74 | SECS_PER_HOUR = 3600, | - | ||||||||||||||||||||||||||||||
75 | MSECS_PER_HOUR = 3600000, | - | ||||||||||||||||||||||||||||||
76 | SECS_PER_MIN = 60, | - | ||||||||||||||||||||||||||||||
77 | MSECS_PER_MIN = 60000, | - | ||||||||||||||||||||||||||||||
78 | TIME_T_MAX = 2145916799, // int maximum 2037-12-31T23:59:59 UTC | - | ||||||||||||||||||||||||||||||
79 | JULIAN_DAY_FOR_EPOCH = 2440588 // result of julianDayFromDate(1970, 1, 1) | - | ||||||||||||||||||||||||||||||
80 | }; | - | ||||||||||||||||||||||||||||||
81 | - | |||||||||||||||||||||||||||||||
82 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
83 | QDate static helper functions | - | ||||||||||||||||||||||||||||||
84 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||||||||
86 | static inline QDate fixedDate(int y, int m, int d) | - | ||||||||||||||||||||||||||||||
87 | { | - | ||||||||||||||||||||||||||||||
88 | QDate result(y, m, 1); | - | ||||||||||||||||||||||||||||||
89 | result.setDate(y, m, qMin(d, result.daysInMonth())); | - | ||||||||||||||||||||||||||||||
90 | return result; executed 288 times by 4 tests: return result; Executed by:
| 288 | ||||||||||||||||||||||||||||||
91 | } | - | ||||||||||||||||||||||||||||||
92 | - | |||||||||||||||||||||||||||||||
93 | /* | - | ||||||||||||||||||||||||||||||
94 | Until C++11, rounding direction is implementation-defined. | - | ||||||||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||||||||
96 | For negative operands, implementations may chose to round down instead of | - | ||||||||||||||||||||||||||||||
97 | towards zero (truncation). We only actually care about the case a < 0, as all | - | ||||||||||||||||||||||||||||||
98 | uses of floordiv have b > 0. In this case, if rounding is down we have a % b | - | ||||||||||||||||||||||||||||||
99 | >= 0 and simple division works fine; but a % b = a - (a / b) * b always, so | - | ||||||||||||||||||||||||||||||
100 | rounding towards zero gives a % b <= 0; when < 0, we need to adjust. | - | ||||||||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||||||||
102 | Once we assume C++11, we can safely test a < 0 instead of a % b < 0. | - | ||||||||||||||||||||||||||||||
103 | */ | - | ||||||||||||||||||||||||||||||
104 | static inline qint64 floordiv(qint64 a, int b) | - | ||||||||||||||||||||||||||||||
105 | { | - | ||||||||||||||||||||||||||||||
106 | return (a - (a % b < 0 ? b - 1 : 0)) / b; executed 95030186 times by 102 tests: return (a - (a % b < 0 ? b - 1 : 0)) / b; Executed by:
| 1327688-95030186 | ||||||||||||||||||||||||||||||
107 | } | - | ||||||||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||||||||
109 | static inline int floordiv(int a, int b) | - | ||||||||||||||||||||||||||||||
110 | { | - | ||||||||||||||||||||||||||||||
111 | return (a - (a % b < 0 ? b - 1 : 0)) / b; executed 136433380 times by 102 tests: return (a - (a % b < 0 ? b - 1 : 0)) / b; Executed by:
| 0-136433380 | ||||||||||||||||||||||||||||||
112 | } | - | ||||||||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||||||||
114 | static inline qint64 julianDayFromDate(int year, int month, int day) | - | ||||||||||||||||||||||||||||||
115 | { | - | ||||||||||||||||||||||||||||||
116 | // Adjust for no year 0 | - | ||||||||||||||||||||||||||||||
117 | if (year < 0)
| 239374-21048343 | ||||||||||||||||||||||||||||||
118 | ++year; executed 239374 times by 2 tests: ++year; Executed by:
| 239374 | ||||||||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||||||||
120 | /* | - | ||||||||||||||||||||||||||||||
121 | * Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php | - | ||||||||||||||||||||||||||||||
122 | * This formula is correct for all julian days, when using mathematical integer | - | ||||||||||||||||||||||||||||||
123 | * division (round to negative infinity), not c++11 integer division (round to zero) | - | ||||||||||||||||||||||||||||||
124 | */ | - | ||||||||||||||||||||||||||||||
125 | int a = floordiv(14 - month, 12); | - | ||||||||||||||||||||||||||||||
126 | qint64 y = (qint64)year + 4800 - a; | - | ||||||||||||||||||||||||||||||
127 | int m = month + 12 * a - 3; | - | ||||||||||||||||||||||||||||||
128 | return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045; executed 21292299 times by 102 tests: return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045; Executed by:
| 21292299 | ||||||||||||||||||||||||||||||
129 | } | - | ||||||||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||||||||
131 | struct ParsedDate | - | ||||||||||||||||||||||||||||||
132 | { | - | ||||||||||||||||||||||||||||||
133 | int year, month, day; | - | ||||||||||||||||||||||||||||||
134 | }; | - | ||||||||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||||||||
136 | // prevent this function from being inlined into all 10 users | - | ||||||||||||||||||||||||||||||
137 | Q_NEVER_INLINE | - | ||||||||||||||||||||||||||||||
138 | static ParsedDate getDateFromJulianDay(qint64 julianDay) | - | ||||||||||||||||||||||||||||||
139 | { | - | ||||||||||||||||||||||||||||||
140 | /* | - | ||||||||||||||||||||||||||||||
141 | * Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php | - | ||||||||||||||||||||||||||||||
142 | * This formula is correct for all julian days, when using mathematical integer | - | ||||||||||||||||||||||||||||||
143 | * division (round to negative infinity), not c++11 integer division (round to zero) | - | ||||||||||||||||||||||||||||||
144 | */ | - | ||||||||||||||||||||||||||||||
145 | qint64 a = julianDay + 32044; | - | ||||||||||||||||||||||||||||||
146 | qint64 b = floordiv(4 * a + 3, 146097); | - | ||||||||||||||||||||||||||||||
147 | int c = a - floordiv(146097 * b, 4); | - | ||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||
149 | int d = floordiv(4 * c + 3, 1461); | - | ||||||||||||||||||||||||||||||
150 | int e = c - floordiv(1461 * d, 4); | - | ||||||||||||||||||||||||||||||
151 | int m = floordiv(5 * e + 2, 153); | - | ||||||||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||||||||
153 | int day = e - floordiv(153 * m + 2, 5) + 1; | - | ||||||||||||||||||||||||||||||
154 | int month = m + 3 - 12 * floordiv(m, 10); | - | ||||||||||||||||||||||||||||||
155 | int year = 100 * b + d - 4800 + floordiv(m, 10); | - | ||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||
157 | // Adjust for no year 0 | - | ||||||||||||||||||||||||||||||
158 | if (year <= 0)
| 715840-14937258 | ||||||||||||||||||||||||||||||
159 | --year ; executed 715840 times by 5 tests: --year ; Executed by:
| 715840 | ||||||||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||||||||
161 | const ParsedDate result = { year, month, day }; | - | ||||||||||||||||||||||||||||||
162 | return result; executed 15653098 times by 99 tests: return result; Executed by:
| 15653098 | ||||||||||||||||||||||||||||||
163 | } | - | ||||||||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||||||||
165 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
166 | Date/Time formatting helper functions | - | ||||||||||||||||||||||||||||||
167 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||||||||
169 | static const char monthDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | - | ||||||||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||||||||
171 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
172 | static const char qt_shortMonthNames[][4] = { | - | ||||||||||||||||||||||||||||||
173 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | - | ||||||||||||||||||||||||||||||
174 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | - | ||||||||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||||||||
176 | static int qt_monthNumberFromShortName(QStringRef shortName) | - | ||||||||||||||||||||||||||||||
177 | { | - | ||||||||||||||||||||||||||||||
178 | for (unsigned int i = 0; i < sizeof(qt_shortMonthNames) / sizeof(qt_shortMonthNames[0]); ++i) {
| 25-588 | ||||||||||||||||||||||||||||||
179 | if (shortName == QLatin1String(qt_shortMonthNames[i], 3))
| 90-498 | ||||||||||||||||||||||||||||||
180 | return i + 1; executed 90 times by 4 tests: return i + 1; Executed by:
| 90 | ||||||||||||||||||||||||||||||
181 | } executed 498 times by 4 tests: end of block Executed by:
| 498 | ||||||||||||||||||||||||||||||
182 | return -1; executed 25 times by 3 tests: return -1; Executed by:
| 25 | ||||||||||||||||||||||||||||||
183 | } | - | ||||||||||||||||||||||||||||||
184 | static int qt_monthNumberFromShortName(const QString &shortName) | - | ||||||||||||||||||||||||||||||
185 | { executed 48 times by 3 tests: return qt_monthNumberFromShortName(QStringRef(&shortName)); }return qt_monthNumberFromShortName(QStringRef(&shortName)); Executed by:
executed 48 times by 3 tests: return qt_monthNumberFromShortName(QStringRef(&shortName)); Executed by:
| 48 | ||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||
187 | static int fromShortMonthName(const QStringRef &monthName) | - | ||||||||||||||||||||||||||||||
188 | { | - | ||||||||||||||||||||||||||||||
189 | // Assume that English monthnames are the default | - | ||||||||||||||||||||||||||||||
190 | int month = qt_monthNumberFromShortName(monthName); | - | ||||||||||||||||||||||||||||||
191 | if (month != -1)
| 16-51 | ||||||||||||||||||||||||||||||
192 | return month; executed 51 times by 3 tests: return month; Executed by:
| 51 | ||||||||||||||||||||||||||||||
193 | // If English names can't be found, search the localized ones | - | ||||||||||||||||||||||||||||||
194 | for (int i = 1; i <= 12; ++i) {
| 16-192 | ||||||||||||||||||||||||||||||
195 | if (monthName == QDate::shortMonthName(i))
| 0-192 | ||||||||||||||||||||||||||||||
196 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||||||||
197 | } executed 192 times by 2 tests: end of block Executed by:
| 192 | ||||||||||||||||||||||||||||||
198 | return -1; executed 16 times by 2 tests: return -1; Executed by:
| 16 | ||||||||||||||||||||||||||||||
199 | } | - | ||||||||||||||||||||||||||||||
200 | #endif // QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||||||||
202 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
203 | struct ParsedRfcDateTime { | - | ||||||||||||||||||||||||||||||
204 | QDate date; | - | ||||||||||||||||||||||||||||||
205 | QTime time; | - | ||||||||||||||||||||||||||||||
206 | int utcOffset; | - | ||||||||||||||||||||||||||||||
207 | }; | - | ||||||||||||||||||||||||||||||
208 | - | |||||||||||||||||||||||||||||||
209 | static ParsedRfcDateTime rfcDateImpl(const QString &s) | - | ||||||||||||||||||||||||||||||
210 | { | - | ||||||||||||||||||||||||||||||
211 | ParsedRfcDateTime result; | - | ||||||||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||||||||
213 | // Matches "Wdy, DD Mon YYYY HH:mm:ss ±hhmm" (Wdy, being optional) | - | ||||||||||||||||||||||||||||||
214 | QRegExp rex(QStringLiteral("^(?:[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))?")); executed 71 times by 3 tests: return qstring_literal_temp; Executed by:
| 71 | ||||||||||||||||||||||||||||||
215 | if (s.indexOf(rex) == 0) {
| 33-38 | ||||||||||||||||||||||||||||||
216 | const QStringList cap = rex.capturedTexts(); | - | ||||||||||||||||||||||||||||||
217 | result.date = QDate(cap[3].toInt(), qt_monthNumberFromShortName(cap[2]), cap[1].toInt()); | - | ||||||||||||||||||||||||||||||
218 | if (!cap[4].isEmpty())
| 6-27 | ||||||||||||||||||||||||||||||
219 | result.time = QTime(cap[4].toInt(), cap[5].toInt(), cap[6].toInt()); executed 27 times by 3 tests: result.time = QTime(cap[4].toInt(), cap[5].toInt(), cap[6].toInt()); Executed by:
| 27 | ||||||||||||||||||||||||||||||
220 | const bool positiveOffset = (cap[7] == QLatin1String("+")); | - | ||||||||||||||||||||||||||||||
221 | const int hourOffset = cap[8].toInt(); | - | ||||||||||||||||||||||||||||||
222 | const int minOffset = cap[9].toInt(); | - | ||||||||||||||||||||||||||||||
223 | result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); | - | ||||||||||||||||||||||||||||||
224 | } else { executed 33 times by 3 tests: end of block Executed by:
| 33 | ||||||||||||||||||||||||||||||
225 | // Matches "Wdy Mon DD HH:mm:ss YYYY" | - | ||||||||||||||||||||||||||||||
226 | QRegExp rex(QStringLiteral("^[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))?")); executed 38 times by 3 tests: return qstring_literal_temp; Executed by:
| 38 | ||||||||||||||||||||||||||||||
227 | if (s.indexOf(rex) == 0) {
| 15-23 | ||||||||||||||||||||||||||||||
228 | const QStringList cap = rex.capturedTexts(); | - | ||||||||||||||||||||||||||||||
229 | result.date = QDate(cap[6].toInt(), qt_monthNumberFromShortName(cap[1]), cap[2].toInt()); | - | ||||||||||||||||||||||||||||||
230 | if (!cap[3].isEmpty())
| 3-12 | ||||||||||||||||||||||||||||||
231 | result.time = QTime(cap[3].toInt(), cap[4].toInt(), cap[5].toInt()); executed 12 times by 3 tests: result.time = QTime(cap[3].toInt(), cap[4].toInt(), cap[5].toInt()); Executed by:
| 12 | ||||||||||||||||||||||||||||||
232 | const bool positiveOffset = (cap[7] == QLatin1String("+")); | - | ||||||||||||||||||||||||||||||
233 | const int hourOffset = cap[8].toInt(); | - | ||||||||||||||||||||||||||||||
234 | const int minOffset = cap[9].toInt(); | - | ||||||||||||||||||||||||||||||
235 | result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); | - | ||||||||||||||||||||||||||||||
236 | } executed 15 times by 3 tests: end of block Executed by:
| 15 | ||||||||||||||||||||||||||||||
237 | } executed 38 times by 3 tests: end of block Executed by:
| 38 | ||||||||||||||||||||||||||||||
238 | - | |||||||||||||||||||||||||||||||
239 | return result; executed 71 times by 3 tests: return result; Executed by:
| 71 | ||||||||||||||||||||||||||||||
240 | } | - | ||||||||||||||||||||||||||||||
241 | #endif // QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||||||||
243 | // Return offset in [+-]HH:mm format | - | ||||||||||||||||||||||||||||||
244 | static QString toOffsetString(Qt::DateFormat format, int offset) | - | ||||||||||||||||||||||||||||||
245 | { | - | ||||||||||||||||||||||||||||||
246 | return QString::asprintf("%c%02d%s%02d", executed 96 times by 3 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60); Executed by:
| 96 | ||||||||||||||||||||||||||||||
247 | offset >= 0 ? '+' : '-', executed 96 times by 3 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60); Executed by:
| 96 | ||||||||||||||||||||||||||||||
248 | qAbs(offset) / SECS_PER_HOUR, executed 96 times by 3 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60); Executed by:
| 96 | ||||||||||||||||||||||||||||||
249 | // Qt::ISODate puts : between the hours and minutes, but Qt:TextDate does not: executed 96 times by 3 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60); Executed by:
| 96 | ||||||||||||||||||||||||||||||
250 | format == Qt::TextDate ? "" : ":", executed 96 times by 3 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60); Executed by:
| 96 | ||||||||||||||||||||||||||||||
251 | (qAbs(offset) / 60) % 60); executed 96 times by 3 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60); Executed by:
| 96 | ||||||||||||||||||||||||||||||
252 | } | - | ||||||||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||||||||
254 | // Parse offset in [+-]HH[[:]mm] format | - | ||||||||||||||||||||||||||||||
255 | static int fromOffsetString(const QStringRef &offsetString, bool *valid) | - | ||||||||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||||||||
257 | *valid = false; | - | ||||||||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||||||||
259 | const int size = offsetString.size(); | - | ||||||||||||||||||||||||||||||
260 | if (size < 2 || size > 6)
| 0-23 | ||||||||||||||||||||||||||||||
261 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
262 | - | |||||||||||||||||||||||||||||||
263 | // sign will be +1 for a positive and -1 for a negative offset | - | ||||||||||||||||||||||||||||||
264 | int sign; | - | ||||||||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||||||||
266 | // First char must be + or - | - | ||||||||||||||||||||||||||||||
267 | const QChar signChar = offsetString.at(0); | - | ||||||||||||||||||||||||||||||
268 | if (signChar == QLatin1Char('+'))
| 11-12 | ||||||||||||||||||||||||||||||
269 | sign = 1; executed 12 times by 2 tests: sign = 1; Executed by:
| 12 | ||||||||||||||||||||||||||||||
270 | else if (signChar == QLatin1Char('-'))
| 1-10 | ||||||||||||||||||||||||||||||
271 | sign = -1; executed 10 times by 1 test: sign = -1; Executed by:
| 10 | ||||||||||||||||||||||||||||||
272 | else | - | ||||||||||||||||||||||||||||||
273 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||||||||
275 | // Split the hour and minute parts | - | ||||||||||||||||||||||||||||||
276 | QVector<QStringRef> parts = offsetString.mid(1).split(QLatin1Char(':')); | - | ||||||||||||||||||||||||||||||
277 | if (parts.count() == 1) {
| 9-13 | ||||||||||||||||||||||||||||||
278 | // [+-]HHmm or [+-]HH format | - | ||||||||||||||||||||||||||||||
279 | parts.append(parts.first().mid(2)); | - | ||||||||||||||||||||||||||||||
280 | parts[0] = parts.first().left(2); | - | ||||||||||||||||||||||||||||||
281 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||||||||
282 | - | |||||||||||||||||||||||||||||||
283 | bool ok = false; | - | ||||||||||||||||||||||||||||||
284 | const int hour = parts.first().toInt(&ok); | - | ||||||||||||||||||||||||||||||
285 | if (!ok)
| 2-20 | ||||||||||||||||||||||||||||||
286 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||
287 | - | |||||||||||||||||||||||||||||||
288 | const int minute = (parts.at(1).isEmpty()) ? 0 : parts.at(1).toInt(&ok);
| 4-16 | ||||||||||||||||||||||||||||||
289 | if (!ok || minute < 0 || minute > 59)
| 0-19 | ||||||||||||||||||||||||||||||
290 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||
291 | - | |||||||||||||||||||||||||||||||
292 | *valid = true; | - | ||||||||||||||||||||||||||||||
293 | return sign * ((hour * 60) + minute) * 60; executed 19 times by 2 tests: return sign * ((hour * 60) + minute) * 60; Executed by:
| 19 | ||||||||||||||||||||||||||||||
294 | } | - | ||||||||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||||||||
296 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
297 | QDate member functions | - | ||||||||||||||||||||||||||||||
298 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||||||||
300 | /*! | - | ||||||||||||||||||||||||||||||
301 | \since 4.5 | - | ||||||||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||||||||
303 | \enum QDate::MonthNameType | - | ||||||||||||||||||||||||||||||
304 | - | |||||||||||||||||||||||||||||||
305 | This enum describes the types of the string representation used | - | ||||||||||||||||||||||||||||||
306 | for the month name. | - | ||||||||||||||||||||||||||||||
307 | - | |||||||||||||||||||||||||||||||
308 | \value DateFormat This type of name can be used for date-to-string formatting. | - | ||||||||||||||||||||||||||||||
309 | \value StandaloneFormat This type is used when you need to enumerate months or weekdays. | - | ||||||||||||||||||||||||||||||
310 | Usually standalone names are represented in singular forms with | - | ||||||||||||||||||||||||||||||
311 | capitalized first letter. | - | ||||||||||||||||||||||||||||||
312 | */ | - | ||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||
314 | /*! | - | ||||||||||||||||||||||||||||||
315 | \class QDate | - | ||||||||||||||||||||||||||||||
316 | \inmodule QtCore | - | ||||||||||||||||||||||||||||||
317 | \reentrant | - | ||||||||||||||||||||||||||||||
318 | \brief The QDate class provides date functions. | - | ||||||||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||||||||
320 | - | |||||||||||||||||||||||||||||||
321 | A QDate object contains a calendar date, i.e. year, month, and day | - | ||||||||||||||||||||||||||||||
322 | numbers, in the Gregorian calendar. It can read the current date | - | ||||||||||||||||||||||||||||||
323 | from the system clock. It provides functions for comparing dates, | - | ||||||||||||||||||||||||||||||
324 | and for manipulating dates. For example, it is possible to add | - | ||||||||||||||||||||||||||||||
325 | and subtract days, months, and years to dates. | - | ||||||||||||||||||||||||||||||
326 | - | |||||||||||||||||||||||||||||||
327 | A QDate object is typically created by giving the year, | - | ||||||||||||||||||||||||||||||
328 | month, and day numbers explicitly. Note that QDate interprets two | - | ||||||||||||||||||||||||||||||
329 | digit years as is, i.e., years 0 - 99. A QDate can also be | - | ||||||||||||||||||||||||||||||
330 | constructed with the static function currentDate(), which creates | - | ||||||||||||||||||||||||||||||
331 | a QDate object containing the system clock's date. An explicit | - | ||||||||||||||||||||||||||||||
332 | date can also be set using setDate(). The fromString() function | - | ||||||||||||||||||||||||||||||
333 | returns a QDate given a string and a date format which is used to | - | ||||||||||||||||||||||||||||||
334 | interpret the date within the string. | - | ||||||||||||||||||||||||||||||
335 | - | |||||||||||||||||||||||||||||||
336 | The year(), month(), and day() functions provide access to the | - | ||||||||||||||||||||||||||||||
337 | year, month, and day numbers. Also, dayOfWeek() and dayOfYear() | - | ||||||||||||||||||||||||||||||
338 | functions are provided. The same information is provided in | - | ||||||||||||||||||||||||||||||
339 | textual format by the toString(), shortDayName(), longDayName(), | - | ||||||||||||||||||||||||||||||
340 | shortMonthName(), and longMonthName() functions. | - | ||||||||||||||||||||||||||||||
341 | - | |||||||||||||||||||||||||||||||
342 | QDate provides a full set of operators to compare two QDate | - | ||||||||||||||||||||||||||||||
343 | objects where smaller means earlier, and larger means later. | - | ||||||||||||||||||||||||||||||
344 | - | |||||||||||||||||||||||||||||||
345 | You can increment (or decrement) a date by a given number of days | - | ||||||||||||||||||||||||||||||
346 | using addDays(). Similarly you can use addMonths() and addYears(). | - | ||||||||||||||||||||||||||||||
347 | The daysTo() function returns the number of days between two | - | ||||||||||||||||||||||||||||||
348 | dates. | - | ||||||||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||||||||
350 | The daysInMonth() and daysInYear() functions return how many days | - | ||||||||||||||||||||||||||||||
351 | there are in this date's month and year, respectively. The | - | ||||||||||||||||||||||||||||||
352 | isLeapYear() function indicates whether a date is in a leap year. | - | ||||||||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||||||||
354 | \section1 | - | ||||||||||||||||||||||||||||||
355 | - | |||||||||||||||||||||||||||||||
356 | \section2 No Year 0 | - | ||||||||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||||||||
358 | There is no year 0. Dates in that year are considered invalid. The | - | ||||||||||||||||||||||||||||||
359 | year -1 is the year "1 before Christ" or "1 before current era." | - | ||||||||||||||||||||||||||||||
360 | The day before 1 January 1 CE is 31 December 1 BCE. | - | ||||||||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||||||||
362 | \section2 Range of Valid Dates | - | ||||||||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||||||||
364 | Dates are stored internally as a Julian Day number, an integer count of | - | ||||||||||||||||||||||||||||||
365 | every day in a contiguous range, with 24 November 4714 BCE in the Gregorian | - | ||||||||||||||||||||||||||||||
366 | calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar). | - | ||||||||||||||||||||||||||||||
367 | As well as being an efficient and accurate way of storing an absolute date, | - | ||||||||||||||||||||||||||||||
368 | it is suitable for converting a Date into other calendar systems such as | - | ||||||||||||||||||||||||||||||
369 | Hebrew, Islamic or Chinese. The Julian Day number can be obtained using | - | ||||||||||||||||||||||||||||||
370 | QDate::toJulianDay() and can be set using QDate::fromJulianDay(). | - | ||||||||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||||||||
372 | The range of dates able to be stored by QDate as a Julian Day number is | - | ||||||||||||||||||||||||||||||
373 | for technical reasons limited to between -784350574879 and 784354017364, | - | ||||||||||||||||||||||||||||||
374 | which means from before 2 billion BCE to after 2 billion CE. | - | ||||||||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||||||||
376 | \sa QTime, QDateTime, QDateEdit, QDateTimeEdit, QCalendarWidget | - | ||||||||||||||||||||||||||||||
377 | */ | - | ||||||||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||||||||
379 | /*! | - | ||||||||||||||||||||||||||||||
380 | \fn QDate::QDate() | - | ||||||||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||||||||
382 | Constructs a null date. Null dates are invalid. | - | ||||||||||||||||||||||||||||||
383 | - | |||||||||||||||||||||||||||||||
384 | \sa isNull(), isValid() | - | ||||||||||||||||||||||||||||||
385 | */ | - | ||||||||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||||||||
387 | /*! | - | ||||||||||||||||||||||||||||||
388 | Constructs a date with year \a y, month \a m and day \a d. | - | ||||||||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||||||||
390 | If the specified date is invalid, the date is not set and | - | ||||||||||||||||||||||||||||||
391 | isValid() returns \c false. | - | ||||||||||||||||||||||||||||||
392 | - | |||||||||||||||||||||||||||||||
393 | \warning Years 1 to 99 are interpreted as is. Year 0 is invalid. | - | ||||||||||||||||||||||||||||||
394 | - | |||||||||||||||||||||||||||||||
395 | \sa isValid() | - | ||||||||||||||||||||||||||||||
396 | */ | - | ||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||
398 | QDate::QDate(int y, int m, int d) | - | ||||||||||||||||||||||||||||||
399 | { | - | ||||||||||||||||||||||||||||||
400 | setDate(y, m, d); | - | ||||||||||||||||||||||||||||||
401 | } executed 20734897 times by 102 tests: end of block Executed by:
| 20734897 | ||||||||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||||||||
404 | /*! | - | ||||||||||||||||||||||||||||||
405 | \fn bool QDate::isNull() const | - | ||||||||||||||||||||||||||||||
406 | - | |||||||||||||||||||||||||||||||
407 | Returns \c true if the date is null; otherwise returns \c false. A null | - | ||||||||||||||||||||||||||||||
408 | date is invalid. | - | ||||||||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||||||||
410 | \note The behavior of this function is equivalent to isValid(). | - | ||||||||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||||||||
412 | \sa isValid() | - | ||||||||||||||||||||||||||||||
413 | */ | - | ||||||||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||||||||
415 | - | |||||||||||||||||||||||||||||||
416 | /*! | - | ||||||||||||||||||||||||||||||
417 | \fn bool QDate::isValid() const | - | ||||||||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||||||||
419 | Returns \c true if this date is valid; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
420 | - | |||||||||||||||||||||||||||||||
421 | \sa isNull() | - | ||||||||||||||||||||||||||||||
422 | */ | - | ||||||||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||||||||
425 | /*! | - | ||||||||||||||||||||||||||||||
426 | Returns the year of this date. Negative numbers indicate years | - | ||||||||||||||||||||||||||||||
427 | before 1 CE, such that year -44 is 44 BCE. | - | ||||||||||||||||||||||||||||||
428 | - | |||||||||||||||||||||||||||||||
429 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||||||||
431 | \sa month(), day() | - | ||||||||||||||||||||||||||||||
432 | */ | - | ||||||||||||||||||||||||||||||
433 | - | |||||||||||||||||||||||||||||||
434 | int QDate::year() const | - | ||||||||||||||||||||||||||||||
435 | { | - | ||||||||||||||||||||||||||||||
436 | if (isNull())
| 24-621632 | ||||||||||||||||||||||||||||||
437 | return 0; executed 24 times by 2 tests: return 0; Executed by:
| 24 | ||||||||||||||||||||||||||||||
438 | - | |||||||||||||||||||||||||||||||
439 | return getDateFromJulianDay(jd).year; executed 621632 times by 41 tests: return getDateFromJulianDay(jd).year; Executed by:
| 621632 | ||||||||||||||||||||||||||||||
440 | } | - | ||||||||||||||||||||||||||||||
441 | - | |||||||||||||||||||||||||||||||
442 | /*! | - | ||||||||||||||||||||||||||||||
443 | Returns the number corresponding to the month of this date, using | - | ||||||||||||||||||||||||||||||
444 | the following convention: | - | ||||||||||||||||||||||||||||||
445 | - | |||||||||||||||||||||||||||||||
446 | \list | - | ||||||||||||||||||||||||||||||
447 | \li 1 = "January" | - | ||||||||||||||||||||||||||||||
448 | \li 2 = "February" | - | ||||||||||||||||||||||||||||||
449 | \li 3 = "March" | - | ||||||||||||||||||||||||||||||
450 | \li 4 = "April" | - | ||||||||||||||||||||||||||||||
451 | \li 5 = "May" | - | ||||||||||||||||||||||||||||||
452 | \li 6 = "June" | - | ||||||||||||||||||||||||||||||
453 | \li 7 = "July" | - | ||||||||||||||||||||||||||||||
454 | \li 8 = "August" | - | ||||||||||||||||||||||||||||||
455 | \li 9 = "September" | - | ||||||||||||||||||||||||||||||
456 | \li 10 = "October" | - | ||||||||||||||||||||||||||||||
457 | \li 11 = "November" | - | ||||||||||||||||||||||||||||||
458 | \li 12 = "December" | - | ||||||||||||||||||||||||||||||
459 | \endlist | - | ||||||||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||||||||
461 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
462 | - | |||||||||||||||||||||||||||||||
463 | \sa year(), day() | - | ||||||||||||||||||||||||||||||
464 | */ | - | ||||||||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||||||||
466 | int QDate::month() const | - | ||||||||||||||||||||||||||||||
467 | { | - | ||||||||||||||||||||||||||||||
468 | if (isNull())
| 24-611326 | ||||||||||||||||||||||||||||||
469 | return 0; executed 24 times by 2 tests: return 0; Executed by:
| 24 | ||||||||||||||||||||||||||||||
470 | - | |||||||||||||||||||||||||||||||
471 | return getDateFromJulianDay(jd).month; executed 611326 times by 40 tests: return getDateFromJulianDay(jd).month; Executed by:
| 611326 | ||||||||||||||||||||||||||||||
472 | } | - | ||||||||||||||||||||||||||||||
473 | - | |||||||||||||||||||||||||||||||
474 | /*! | - | ||||||||||||||||||||||||||||||
475 | Returns the day of the month (1 to 31) of this date. | - | ||||||||||||||||||||||||||||||
476 | - | |||||||||||||||||||||||||||||||
477 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
478 | - | |||||||||||||||||||||||||||||||
479 | \sa year(), month(), dayOfWeek() | - | ||||||||||||||||||||||||||||||
480 | */ | - | ||||||||||||||||||||||||||||||
481 | - | |||||||||||||||||||||||||||||||
482 | int QDate::day() const | - | ||||||||||||||||||||||||||||||
483 | { | - | ||||||||||||||||||||||||||||||
484 | if (isNull())
| 24-647178 | ||||||||||||||||||||||||||||||
485 | return 0; executed 24 times by 2 tests: return 0; Executed by:
| 24 | ||||||||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||||||||
487 | return getDateFromJulianDay(jd).day; executed 647178 times by 39 tests: return getDateFromJulianDay(jd).day; Executed by:
| 647178 | ||||||||||||||||||||||||||||||
488 | } | - | ||||||||||||||||||||||||||||||
489 | - | |||||||||||||||||||||||||||||||
490 | /*! | - | ||||||||||||||||||||||||||||||
491 | Returns the weekday (1 = Monday to 7 = Sunday) for this date. | - | ||||||||||||||||||||||||||||||
492 | - | |||||||||||||||||||||||||||||||
493 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
494 | - | |||||||||||||||||||||||||||||||
495 | \sa day(), dayOfYear(), Qt::DayOfWeek | - | ||||||||||||||||||||||||||||||
496 | */ | - | ||||||||||||||||||||||||||||||
497 | - | |||||||||||||||||||||||||||||||
498 | int QDate::dayOfWeek() const | - | ||||||||||||||||||||||||||||||
499 | { | - | ||||||||||||||||||||||||||||||
500 | if (isNull())
| 77-39474 | ||||||||||||||||||||||||||||||
501 | return 0; executed 77 times by 3 tests: return 0; Executed by:
| 77 | ||||||||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||||||||
503 | if (jd >= 0)
| 8-39466 | ||||||||||||||||||||||||||||||
504 | return (jd % 7) + 1; executed 39466 times by 17 tests: return (jd % 7) + 1; Executed by:
| 39466 | ||||||||||||||||||||||||||||||
505 | else | - | ||||||||||||||||||||||||||||||
506 | return ((jd + 1) % 7) + 7; executed 8 times by 1 test: return ((jd + 1) % 7) + 7; Executed by:
| 8 | ||||||||||||||||||||||||||||||
507 | } | - | ||||||||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||||||||
509 | /*! | - | ||||||||||||||||||||||||||||||
510 | Returns the day of the year (1 to 365 or 366 on leap years) for | - | ||||||||||||||||||||||||||||||
511 | this date. | - | ||||||||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||||||||
513 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||||||||
515 | \sa day(), dayOfWeek() | - | ||||||||||||||||||||||||||||||
516 | */ | - | ||||||||||||||||||||||||||||||
517 | - | |||||||||||||||||||||||||||||||
518 | int QDate::dayOfYear() const | - | ||||||||||||||||||||||||||||||
519 | { | - | ||||||||||||||||||||||||||||||
520 | if (isNull())
| 1-1907 | ||||||||||||||||||||||||||||||
521 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||||||||
523 | return jd - julianDayFromDate(year(), 1, 1) + 1; executed 1907 times by 3 tests: return jd - julianDayFromDate(year(), 1, 1) + 1; Executed by:
| 1907 | ||||||||||||||||||||||||||||||
524 | } | - | ||||||||||||||||||||||||||||||
525 | - | |||||||||||||||||||||||||||||||
526 | /*! | - | ||||||||||||||||||||||||||||||
527 | Returns the number of days in the month (28 to 31) for this date. | - | ||||||||||||||||||||||||||||||
528 | - | |||||||||||||||||||||||||||||||
529 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
530 | - | |||||||||||||||||||||||||||||||
531 | \sa day(), daysInYear() | - | ||||||||||||||||||||||||||||||
532 | */ | - | ||||||||||||||||||||||||||||||
533 | - | |||||||||||||||||||||||||||||||
534 | int QDate::daysInMonth() const | - | ||||||||||||||||||||||||||||||
535 | { | - | ||||||||||||||||||||||||||||||
536 | if (isNull())
| 41-4510 | ||||||||||||||||||||||||||||||
537 | return 0; executed 41 times by 2 tests: return 0; Executed by:
| 41 | ||||||||||||||||||||||||||||||
538 | - | |||||||||||||||||||||||||||||||
539 | const ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||||||||
540 | if (pd.month == 2 && isLeapYear(pd.year))
| 64-4287 | ||||||||||||||||||||||||||||||
541 | return 29; executed 159 times by 7 tests: return 29; Executed by:
| 159 | ||||||||||||||||||||||||||||||
542 | else | - | ||||||||||||||||||||||||||||||
543 | return monthDays[pd.month]; executed 4351 times by 8 tests: return monthDays[pd.month]; Executed by:
| 4351 | ||||||||||||||||||||||||||||||
544 | } | - | ||||||||||||||||||||||||||||||
545 | - | |||||||||||||||||||||||||||||||
546 | /*! | - | ||||||||||||||||||||||||||||||
547 | Returns the number of days in the year (365 or 366) for this date. | - | ||||||||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||||||||
549 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
550 | - | |||||||||||||||||||||||||||||||
551 | \sa day(), daysInMonth() | - | ||||||||||||||||||||||||||||||
552 | */ | - | ||||||||||||||||||||||||||||||
553 | - | |||||||||||||||||||||||||||||||
554 | int QDate::daysInYear() const | - | ||||||||||||||||||||||||||||||
555 | { | - | ||||||||||||||||||||||||||||||
556 | if (isNull())
| 1-4 | ||||||||||||||||||||||||||||||
557 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||
558 | - | |||||||||||||||||||||||||||||||
559 | return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365; executed 4 times by 1 test: return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365; Executed by:
| 2-4 | ||||||||||||||||||||||||||||||
560 | } | - | ||||||||||||||||||||||||||||||
561 | - | |||||||||||||||||||||||||||||||
562 | /*! | - | ||||||||||||||||||||||||||||||
563 | Returns the week number (1 to 53), and stores the year in | - | ||||||||||||||||||||||||||||||
564 | *\a{yearNumber} unless \a yearNumber is null (the default). | - | ||||||||||||||||||||||||||||||
565 | - | |||||||||||||||||||||||||||||||
566 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
567 | - | |||||||||||||||||||||||||||||||
568 | In accordance with ISO 8601, weeks start on Monday and the first | - | ||||||||||||||||||||||||||||||
569 | Thursday of a year is always in week 1 of that year. Most years | - | ||||||||||||||||||||||||||||||
570 | have 52 weeks, but some have 53. | - | ||||||||||||||||||||||||||||||
571 | - | |||||||||||||||||||||||||||||||
572 | *\a{yearNumber} is not always the same as year(). For example, 1 | - | ||||||||||||||||||||||||||||||
573 | January 2000 has week number 52 in the year 1999, and 31 December | - | ||||||||||||||||||||||||||||||
574 | 2002 has week number 1 in the year 2003. | - | ||||||||||||||||||||||||||||||
575 | - | |||||||||||||||||||||||||||||||
576 | \sa isValid() | - | ||||||||||||||||||||||||||||||
577 | */ | - | ||||||||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||||||||
579 | int QDate::weekNumber(int *yearNumber) const | - | ||||||||||||||||||||||||||||||
580 | { | - | ||||||||||||||||||||||||||||||
581 | if (!isValid())
| 3-1894 | ||||||||||||||||||||||||||||||
582 | return 0; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||||||||
584 | int year = QDate::year(); | - | ||||||||||||||||||||||||||||||
585 | int yday = dayOfYear(); | - | ||||||||||||||||||||||||||||||
586 | int wday = dayOfWeek(); | - | ||||||||||||||||||||||||||||||
587 | - | |||||||||||||||||||||||||||||||
588 | int week = (yday - wday + 10) / 7; | - | ||||||||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||||||||
590 | if (week == 0) {
| 172-1722 | ||||||||||||||||||||||||||||||
591 | // last week of previous year | - | ||||||||||||||||||||||||||||||
592 | --year; | - | ||||||||||||||||||||||||||||||
593 | week = (yday + 365 + (QDate::isLeapYear(year) ? 1 : 0) - wday + 10) / 7;
| 42-130 | ||||||||||||||||||||||||||||||
594 | Q_ASSERT(week == 52 || week == 53); | - | ||||||||||||||||||||||||||||||
595 | } else if (week == 53) { executed 172 times by 1 test: end of block Executed by:
| 172-1407 | ||||||||||||||||||||||||||||||
596 | // maybe first week of next year | - | ||||||||||||||||||||||||||||||
597 | int w = (yday - 365 - (QDate::isLeapYear(year) ? 1 : 0) - wday + 10) / 7;
| 96-219 | ||||||||||||||||||||||||||||||
598 | if (w > 0) {
| 142-173 | ||||||||||||||||||||||||||||||
599 | ++year; | - | ||||||||||||||||||||||||||||||
600 | week = w; | - | ||||||||||||||||||||||||||||||
601 | } executed 173 times by 2 tests: end of block Executed by:
| 173 | ||||||||||||||||||||||||||||||
602 | Q_ASSERT(week == 53 || week == 1); | - | ||||||||||||||||||||||||||||||
603 | } executed 315 times by 2 tests: end of block Executed by:
| 315 | ||||||||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||||||||
605 | if (yearNumber != 0)
| 294-1600 | ||||||||||||||||||||||||||||||
606 | *yearNumber = year; executed 1600 times by 1 test: *yearNumber = year; Executed by:
| 1600 | ||||||||||||||||||||||||||||||
607 | return week; executed 1894 times by 3 tests: return week; Executed by:
| 1894 | ||||||||||||||||||||||||||||||
608 | } | - | ||||||||||||||||||||||||||||||
609 | - | |||||||||||||||||||||||||||||||
610 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
611 | /*! | - | ||||||||||||||||||||||||||||||
612 | \since 4.5 | - | ||||||||||||||||||||||||||||||
613 | - | |||||||||||||||||||||||||||||||
614 | Returns the short name of the \a month for the representation specified | - | ||||||||||||||||||||||||||||||
615 | by \a type. | - | ||||||||||||||||||||||||||||||
616 | - | |||||||||||||||||||||||||||||||
617 | The months are enumerated using the following convention: | - | ||||||||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||||||||
619 | \list | - | ||||||||||||||||||||||||||||||
620 | \li 1 = "Jan" | - | ||||||||||||||||||||||||||||||
621 | \li 2 = "Feb" | - | ||||||||||||||||||||||||||||||
622 | \li 3 = "Mar" | - | ||||||||||||||||||||||||||||||
623 | \li 4 = "Apr" | - | ||||||||||||||||||||||||||||||
624 | \li 5 = "May" | - | ||||||||||||||||||||||||||||||
625 | \li 6 = "Jun" | - | ||||||||||||||||||||||||||||||
626 | \li 7 = "Jul" | - | ||||||||||||||||||||||||||||||
627 | \li 8 = "Aug" | - | ||||||||||||||||||||||||||||||
628 | \li 9 = "Sep" | - | ||||||||||||||||||||||||||||||
629 | \li 10 = "Oct" | - | ||||||||||||||||||||||||||||||
630 | \li 11 = "Nov" | - | ||||||||||||||||||||||||||||||
631 | \li 12 = "Dec" | - | ||||||||||||||||||||||||||||||
632 | \endlist | - | ||||||||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||||||||
634 | The month names will be localized according to the system's | - | ||||||||||||||||||||||||||||||
635 | locale settings, i.e. using QLocale::system(). | - | ||||||||||||||||||||||||||||||
636 | - | |||||||||||||||||||||||||||||||
637 | Returns an empty string if the date is invalid. | - | ||||||||||||||||||||||||||||||
638 | - | |||||||||||||||||||||||||||||||
639 | \sa toString(), longMonthName(), shortDayName(), longDayName() | - | ||||||||||||||||||||||||||||||
640 | */ | - | ||||||||||||||||||||||||||||||
641 | - | |||||||||||||||||||||||||||||||
642 | QString QDate::shortMonthName(int month, QDate::MonthNameType type) | - | ||||||||||||||||||||||||||||||
643 | { | - | ||||||||||||||||||||||||||||||
644 | if (month >= 1 || month <= 12) {
| 0-658 | ||||||||||||||||||||||||||||||
645 | switch (type) { | - | ||||||||||||||||||||||||||||||
646 | case QDate::DateFormat: executed 646 times by 4 tests: case QDate::DateFormat: Executed by:
| 646 | ||||||||||||||||||||||||||||||
647 | return QLocale::system().monthName(month, QLocale::ShortFormat); executed 646 times by 4 tests: return QLocale::system().monthName(month, QLocale::ShortFormat); Executed by:
| 646 | ||||||||||||||||||||||||||||||
648 | case QDate::StandaloneFormat: executed 14 times by 1 test: case QDate::StandaloneFormat: Executed by:
| 14 | ||||||||||||||||||||||||||||||
649 | return QLocale::system().standaloneMonthName(month, QLocale::ShortFormat); executed 14 times by 1 test: return QLocale::system().standaloneMonthName(month, QLocale::ShortFormat); Executed by:
| 14 | ||||||||||||||||||||||||||||||
650 | } | - | ||||||||||||||||||||||||||||||
651 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
652 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
653 | } | - | ||||||||||||||||||||||||||||||
654 | - | |||||||||||||||||||||||||||||||
655 | /*! | - | ||||||||||||||||||||||||||||||
656 | \since 4.5 | - | ||||||||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||||||||
658 | Returns the long name of the \a month for the representation specified | - | ||||||||||||||||||||||||||||||
659 | by \a type. | - | ||||||||||||||||||||||||||||||
660 | - | |||||||||||||||||||||||||||||||
661 | The months are enumerated using the following convention: | - | ||||||||||||||||||||||||||||||
662 | - | |||||||||||||||||||||||||||||||
663 | \list | - | ||||||||||||||||||||||||||||||
664 | \li 1 = "January" | - | ||||||||||||||||||||||||||||||
665 | \li 2 = "February" | - | ||||||||||||||||||||||||||||||
666 | \li 3 = "March" | - | ||||||||||||||||||||||||||||||
667 | \li 4 = "April" | - | ||||||||||||||||||||||||||||||
668 | \li 5 = "May" | - | ||||||||||||||||||||||||||||||
669 | \li 6 = "June" | - | ||||||||||||||||||||||||||||||
670 | \li 7 = "July" | - | ||||||||||||||||||||||||||||||
671 | \li 8 = "August" | - | ||||||||||||||||||||||||||||||
672 | \li 9 = "September" | - | ||||||||||||||||||||||||||||||
673 | \li 10 = "October" | - | ||||||||||||||||||||||||||||||
674 | \li 11 = "November" | - | ||||||||||||||||||||||||||||||
675 | \li 12 = "December" | - | ||||||||||||||||||||||||||||||
676 | \endlist | - | ||||||||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||||||||
678 | The month names will be localized according to the system's | - | ||||||||||||||||||||||||||||||
679 | locale settings, i.e. using QLocale::system(). | - | ||||||||||||||||||||||||||||||
680 | - | |||||||||||||||||||||||||||||||
681 | Returns an empty string if the date is invalid. | - | ||||||||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||||||||
683 | \sa toString(), shortMonthName(), shortDayName(), longDayName() | - | ||||||||||||||||||||||||||||||
684 | */ | - | ||||||||||||||||||||||||||||||
685 | - | |||||||||||||||||||||||||||||||
686 | QString QDate::longMonthName(int month, MonthNameType type) | - | ||||||||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||||||||
688 | if (month >= 1 && month <= 12) {
| 2-38 | ||||||||||||||||||||||||||||||
689 | switch (type) { | - | ||||||||||||||||||||||||||||||
690 | case QDate::DateFormat: executed 24 times by 3 tests: case QDate::DateFormat: Executed by:
| 24 | ||||||||||||||||||||||||||||||
691 | return QLocale::system().monthName(month, QLocale::LongFormat); executed 24 times by 3 tests: return QLocale::system().monthName(month, QLocale::LongFormat); Executed by:
| 24 | ||||||||||||||||||||||||||||||
692 | case QDate::StandaloneFormat: executed 12 times by 1 test: case QDate::StandaloneFormat: Executed by:
| 12 | ||||||||||||||||||||||||||||||
693 | return QLocale::system().standaloneMonthName(month, QLocale::LongFormat); executed 12 times by 1 test: return QLocale::system().standaloneMonthName(month, QLocale::LongFormat); Executed by:
| 12 | ||||||||||||||||||||||||||||||
694 | } | - | ||||||||||||||||||||||||||||||
695 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
696 | return QString(); executed 4 times by 1 test: return QString(); Executed by:
| 4 | ||||||||||||||||||||||||||||||
697 | } | - | ||||||||||||||||||||||||||||||
698 | - | |||||||||||||||||||||||||||||||
699 | /*! | - | ||||||||||||||||||||||||||||||
700 | \since 4.5 | - | ||||||||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||||||||
702 | Returns the short name of the \a weekday for the representation specified | - | ||||||||||||||||||||||||||||||
703 | by \a type. | - | ||||||||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||||||||
705 | The days are enumerated using the following convention: | - | ||||||||||||||||||||||||||||||
706 | - | |||||||||||||||||||||||||||||||
707 | \list | - | ||||||||||||||||||||||||||||||
708 | \li 1 = "Mon" | - | ||||||||||||||||||||||||||||||
709 | \li 2 = "Tue" | - | ||||||||||||||||||||||||||||||
710 | \li 3 = "Wed" | - | ||||||||||||||||||||||||||||||
711 | \li 4 = "Thu" | - | ||||||||||||||||||||||||||||||
712 | \li 5 = "Fri" | - | ||||||||||||||||||||||||||||||
713 | \li 6 = "Sat" | - | ||||||||||||||||||||||||||||||
714 | \li 7 = "Sun" | - | ||||||||||||||||||||||||||||||
715 | \endlist | - | ||||||||||||||||||||||||||||||
716 | - | |||||||||||||||||||||||||||||||
717 | The day names will be localized according to the system's | - | ||||||||||||||||||||||||||||||
718 | locale settings, i.e. using QLocale::system(). | - | ||||||||||||||||||||||||||||||
719 | - | |||||||||||||||||||||||||||||||
720 | Returns an empty string if the date is invalid. | - | ||||||||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||||||||
722 | \sa toString(), shortMonthName(), longMonthName(), longDayName() | - | ||||||||||||||||||||||||||||||
723 | */ | - | ||||||||||||||||||||||||||||||
724 | - | |||||||||||||||||||||||||||||||
725 | QString QDate::shortDayName(int weekday, MonthNameType type) | - | ||||||||||||||||||||||||||||||
726 | { | - | ||||||||||||||||||||||||||||||
727 | if (weekday >= 1 && weekday <= 7) {
| 2-456 | ||||||||||||||||||||||||||||||
728 | switch (type) { | - | ||||||||||||||||||||||||||||||
729 | case QDate::DateFormat: executed 447 times by 4 tests: case QDate::DateFormat: Executed by:
| 447 | ||||||||||||||||||||||||||||||
730 | return QLocale::system().dayName(weekday, QLocale::ShortFormat); executed 447 times by 4 tests: return QLocale::system().dayName(weekday, QLocale::ShortFormat); Executed by:
| 447 | ||||||||||||||||||||||||||||||
731 | case QDate::StandaloneFormat: executed 7 times by 1 test: case QDate::StandaloneFormat: Executed by:
| 7 | ||||||||||||||||||||||||||||||
732 | return QLocale::system().standaloneDayName(weekday, QLocale::ShortFormat); executed 7 times by 1 test: return QLocale::system().standaloneDayName(weekday, QLocale::ShortFormat); Executed by:
| 7 | ||||||||||||||||||||||||||||||
733 | } | - | ||||||||||||||||||||||||||||||
734 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
735 | return QString(); executed 4 times by 1 test: return QString(); Executed by:
| 4 | ||||||||||||||||||||||||||||||
736 | } | - | ||||||||||||||||||||||||||||||
737 | - | |||||||||||||||||||||||||||||||
738 | /*! | - | ||||||||||||||||||||||||||||||
739 | \since 4.5 | - | ||||||||||||||||||||||||||||||
740 | - | |||||||||||||||||||||||||||||||
741 | Returns the long name of the \a weekday for the representation specified | - | ||||||||||||||||||||||||||||||
742 | by \a type. | - | ||||||||||||||||||||||||||||||
743 | - | |||||||||||||||||||||||||||||||
744 | The days are enumerated using the following convention: | - | ||||||||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||||||||
746 | \list | - | ||||||||||||||||||||||||||||||
747 | \li 1 = "Monday" | - | ||||||||||||||||||||||||||||||
748 | \li 2 = "Tuesday" | - | ||||||||||||||||||||||||||||||
749 | \li 3 = "Wednesday" | - | ||||||||||||||||||||||||||||||
750 | \li 4 = "Thursday" | - | ||||||||||||||||||||||||||||||
751 | \li 5 = "Friday" | - | ||||||||||||||||||||||||||||||
752 | \li 6 = "Saturday" | - | ||||||||||||||||||||||||||||||
753 | \li 7 = "Sunday" | - | ||||||||||||||||||||||||||||||
754 | \endlist | - | ||||||||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||||||||
756 | The day names will be localized according to the system's | - | ||||||||||||||||||||||||||||||
757 | locale settings, i.e. using QLocale::system(). | - | ||||||||||||||||||||||||||||||
758 | - | |||||||||||||||||||||||||||||||
759 | Returns an empty string if the date is invalid. | - | ||||||||||||||||||||||||||||||
760 | - | |||||||||||||||||||||||||||||||
761 | \sa toString(), shortDayName(), shortMonthName(), longMonthName() | - | ||||||||||||||||||||||||||||||
762 | */ | - | ||||||||||||||||||||||||||||||
763 | - | |||||||||||||||||||||||||||||||
764 | QString QDate::longDayName(int weekday, MonthNameType type) | - | ||||||||||||||||||||||||||||||
765 | { | - | ||||||||||||||||||||||||||||||
766 | if (weekday >= 1 && weekday <= 7) {
| 2-23 | ||||||||||||||||||||||||||||||
767 | switch (type) { | - | ||||||||||||||||||||||||||||||
768 | case QDate::DateFormat: executed 14 times by 1 test: case QDate::DateFormat: Executed by:
| 14 | ||||||||||||||||||||||||||||||
769 | return QLocale::system().dayName(weekday, QLocale::LongFormat); executed 14 times by 1 test: return QLocale::system().dayName(weekday, QLocale::LongFormat); Executed by:
| 14 | ||||||||||||||||||||||||||||||
770 | case QDate::StandaloneFormat: executed 7 times by 1 test: case QDate::StandaloneFormat: Executed by:
| 7 | ||||||||||||||||||||||||||||||
771 | return QLocale::system().standaloneDayName(weekday, QLocale::LongFormat); executed 7 times by 1 test: return QLocale::system().standaloneDayName(weekday, QLocale::LongFormat); Executed by:
| 7 | ||||||||||||||||||||||||||||||
772 | } | - | ||||||||||||||||||||||||||||||
773 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
774 | return QString(); executed 4 times by 1 test: return QString(); Executed by:
| 4 | ||||||||||||||||||||||||||||||
775 | } | - | ||||||||||||||||||||||||||||||
776 | #endif //QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||||||||
778 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
779 | - | |||||||||||||||||||||||||||||||
780 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
781 | static QString toStringTextDate(QDate date) | - | ||||||||||||||||||||||||||||||
782 | { | - | ||||||||||||||||||||||||||||||
783 | const ParsedDate pd = getDateFromJulianDay(date.toJulianDay()); | - | ||||||||||||||||||||||||||||||
784 | static const QLatin1Char sp(' '); | - | ||||||||||||||||||||||||||||||
785 | return date.shortDayName(date.dayOfWeek()) + sp executed 2 times by 1 test: return date.shortDayName(date.dayOfWeek()) + sp + date.shortMonthName(pd.month) + sp + QString::number(pd.day) + sp + QString::number(pd.year); Executed by:
| 2 | ||||||||||||||||||||||||||||||
786 | + date.shortMonthName(pd.month) + sp executed 2 times by 1 test: return date.shortDayName(date.dayOfWeek()) + sp + date.shortMonthName(pd.month) + sp + QString::number(pd.day) + sp + QString::number(pd.year); Executed by:
| 2 | ||||||||||||||||||||||||||||||
787 | + QString::number(pd.day) + sp executed 2 times by 1 test: return date.shortDayName(date.dayOfWeek()) + sp + date.shortMonthName(pd.month) + sp + QString::number(pd.day) + sp + QString::number(pd.year); Executed by:
| 2 | ||||||||||||||||||||||||||||||
788 | + QString::number(pd.year); executed 2 times by 1 test: return date.shortDayName(date.dayOfWeek()) + sp + date.shortMonthName(pd.month) + sp + QString::number(pd.day) + sp + QString::number(pd.year); Executed by:
| 2 | ||||||||||||||||||||||||||||||
789 | } | - | ||||||||||||||||||||||||||||||
790 | #endif // QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
791 | - | |||||||||||||||||||||||||||||||
792 | static QString toStringIsoDate(qint64 jd) | - | ||||||||||||||||||||||||||||||
793 | { | - | ||||||||||||||||||||||||||||||
794 | const ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||||||||
795 | if (pd.year >= 0 && pd.year <= 9999)
| 0-36 | ||||||||||||||||||||||||||||||
796 | return QString::asprintf("%04d-%02d-%02d", pd.year, pd.month, pd.day); executed 36 times by 5 tests: return QString::asprintf("%04d-%02d-%02d", pd.year, pd.month, pd.day); Executed by:
| 36 | ||||||||||||||||||||||||||||||
797 | else | - | ||||||||||||||||||||||||||||||
798 | return QString(); executed 3 times by 2 tests: return QString(); Executed by:
| 3 | ||||||||||||||||||||||||||||||
799 | } | - | ||||||||||||||||||||||||||||||
800 | - | |||||||||||||||||||||||||||||||
801 | /*! | - | ||||||||||||||||||||||||||||||
802 | \fn QString QDate::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||||||||
803 | - | |||||||||||||||||||||||||||||||
804 | \overload | - | ||||||||||||||||||||||||||||||
805 | - | |||||||||||||||||||||||||||||||
806 | Returns the date as a string. The \a format parameter determines | - | ||||||||||||||||||||||||||||||
807 | the format of the string. | - | ||||||||||||||||||||||||||||||
808 | - | |||||||||||||||||||||||||||||||
809 | If the \a format is Qt::TextDate, the string is formatted in | - | ||||||||||||||||||||||||||||||
810 | the default way. QDate::shortDayName() and QDate::shortMonthName() | - | ||||||||||||||||||||||||||||||
811 | are used to generate the string, so the day and month names will | - | ||||||||||||||||||||||||||||||
812 | be localized names using the system locale, i.e. QLocale::system(). An | - | ||||||||||||||||||||||||||||||
813 | example of this formatting is "Sat May 20 1995". | - | ||||||||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||||||||
815 | If the \a format is Qt::ISODate, the string format corresponds | - | ||||||||||||||||||||||||||||||
816 | to the ISO 8601 extended specification for representations of | - | ||||||||||||||||||||||||||||||
817 | dates and times, taking the form YYYY-MM-DD, where YYYY is the | - | ||||||||||||||||||||||||||||||
818 | year, MM is the month of the year (between 01 and 12), and DD is | - | ||||||||||||||||||||||||||||||
819 | the day of the month between 01 and 31. | - | ||||||||||||||||||||||||||||||
820 | - | |||||||||||||||||||||||||||||||
821 | If the \a format is Qt::SystemLocaleShortDate or | - | ||||||||||||||||||||||||||||||
822 | Qt::SystemLocaleLongDate, the string format depends on the locale | - | ||||||||||||||||||||||||||||||
823 | settings of the system. Identical to calling | - | ||||||||||||||||||||||||||||||
824 | QLocale::system().toString(date, QLocale::ShortFormat) or | - | ||||||||||||||||||||||||||||||
825 | QLocale::system().toString(date, QLocale::LongFormat). | - | ||||||||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||||||||
827 | If the \a format is Qt::DefaultLocaleShortDate or | - | ||||||||||||||||||||||||||||||
828 | Qt::DefaultLocaleLongDate, the string format depends on the | - | ||||||||||||||||||||||||||||||
829 | default application locale. This is the locale set with | - | ||||||||||||||||||||||||||||||
830 | QLocale::setDefault(), or the system locale if no default locale | - | ||||||||||||||||||||||||||||||
831 | has been set. Identical to calling | - | ||||||||||||||||||||||||||||||
832 | \l {QLocale::toString()}{QLocale().toString(date, QLocale::ShortFormat) } or | - | ||||||||||||||||||||||||||||||
833 | \l {QLocale::toString()}{QLocale().toString(date, QLocale::LongFormat)}. | - | ||||||||||||||||||||||||||||||
834 | - | |||||||||||||||||||||||||||||||
835 | If the \a format is Qt::RFC2822Date, the string is formatted in | - | ||||||||||||||||||||||||||||||
836 | an \l{RFC 2822} compatible way. An example of this formatting is | - | ||||||||||||||||||||||||||||||
837 | "20 May 1995". | - | ||||||||||||||||||||||||||||||
838 | - | |||||||||||||||||||||||||||||||
839 | If the date is invalid, an empty string will be returned. | - | ||||||||||||||||||||||||||||||
840 | - | |||||||||||||||||||||||||||||||
841 | \warning The Qt::ISODate format is only valid for years in the | - | ||||||||||||||||||||||||||||||
842 | range 0 to 9999. This restriction may apply to locale-aware | - | ||||||||||||||||||||||||||||||
843 | formats as well, depending on the locale settings. | - | ||||||||||||||||||||||||||||||
844 | - | |||||||||||||||||||||||||||||||
845 | \sa fromString(), shortDayName(), shortMonthName(), QLocale::toString() | - | ||||||||||||||||||||||||||||||
846 | */ | - | ||||||||||||||||||||||||||||||
847 | QString QDate::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||||||||
848 | { | - | ||||||||||||||||||||||||||||||
849 | if (!isValid())
| 2-98 | ||||||||||||||||||||||||||||||
850 | return QString(); executed 2 times by 2 tests: return QString(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
851 | - | |||||||||||||||||||||||||||||||
852 | switch (format) { | - | ||||||||||||||||||||||||||||||
853 | case Qt::SystemLocaleDate: never executed: case Qt::SystemLocaleDate: | 0 | ||||||||||||||||||||||||||||||
854 | case Qt::SystemLocaleShortDate: executed 14 times by 1 test: case Qt::SystemLocaleShortDate: Executed by:
| 14 | ||||||||||||||||||||||||||||||
855 | return QLocale::system().toString(*this, QLocale::ShortFormat); executed 14 times by 1 test: return QLocale::system().toString(*this, QLocale::ShortFormat); Executed by:
| 14 | ||||||||||||||||||||||||||||||
856 | case Qt::SystemLocaleLongDate: executed 14 times by 1 test: case Qt::SystemLocaleLongDate: Executed by:
| 14 | ||||||||||||||||||||||||||||||
857 | return QLocale::system().toString(*this, QLocale::LongFormat); executed 14 times by 1 test: return QLocale::system().toString(*this, QLocale::LongFormat); Executed by:
| 14 | ||||||||||||||||||||||||||||||
858 | case Qt::LocaleDate: never executed: case Qt::LocaleDate: | 0 | ||||||||||||||||||||||||||||||
859 | case Qt::DefaultLocaleShortDate: executed 14 times by 1 test: case Qt::DefaultLocaleShortDate: Executed by:
| 14 | ||||||||||||||||||||||||||||||
860 | return QLocale().toString(*this, QLocale::ShortFormat); executed 14 times by 1 test: return QLocale().toString(*this, QLocale::ShortFormat); Executed by:
| 14 | ||||||||||||||||||||||||||||||
861 | case Qt::DefaultLocaleLongDate: executed 14 times by 1 test: case Qt::DefaultLocaleLongDate: Executed by:
| 14 | ||||||||||||||||||||||||||||||
862 | return QLocale().toString(*this, QLocale::LongFormat); executed 14 times by 1 test: return QLocale().toString(*this, QLocale::LongFormat); Executed by:
| 14 | ||||||||||||||||||||||||||||||
863 | case Qt::RFC2822Date: executed 1 time by 1 test: case Qt::RFC2822Date: Executed by:
| 1 | ||||||||||||||||||||||||||||||
864 | return QLocale::c().toString(*this, QStringLiteral("dd MMM yyyy")); executed 1 time by 1 test: 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; }())); Executed by:
executed 1 time by 1 test: return qstring_literal_temp; Executed by:
| 1 | ||||||||||||||||||||||||||||||
865 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
866 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
867 | case Qt::TextDate: executed 2 times by 1 test: case Qt::TextDate: Executed by:
| 2 | ||||||||||||||||||||||||||||||
868 | return toStringTextDate(*this); executed 2 times by 1 test: return toStringTextDate(*this); Executed by:
| 2 | ||||||||||||||||||||||||||||||
869 | #endif | - | ||||||||||||||||||||||||||||||
870 | case Qt::ISODate: executed 39 times by 5 tests: case Qt::ISODate: Executed by:
| 39 | ||||||||||||||||||||||||||||||
871 | return toStringIsoDate(jd); executed 39 times by 5 tests: return toStringIsoDate(jd); Executed by:
| 39 | ||||||||||||||||||||||||||||||
872 | } | - | ||||||||||||||||||||||||||||||
873 | } | - | ||||||||||||||||||||||||||||||
874 | - | |||||||||||||||||||||||||||||||
875 | /*! | - | ||||||||||||||||||||||||||||||
876 | Returns the date as a string. The \a format parameter determines | - | ||||||||||||||||||||||||||||||
877 | the format of the result string. | - | ||||||||||||||||||||||||||||||
878 | - | |||||||||||||||||||||||||||||||
879 | These expressions may be used: | - | ||||||||||||||||||||||||||||||
880 | - | |||||||||||||||||||||||||||||||
881 | \table | - | ||||||||||||||||||||||||||||||
882 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
883 | \row \li d \li the day as number without a leading zero (1 to 31) | - | ||||||||||||||||||||||||||||||
884 | \row \li dd \li the day as number with a leading zero (01 to 31) | - | ||||||||||||||||||||||||||||||
885 | \row \li ddd | - | ||||||||||||||||||||||||||||||
886 | \li the abbreviated localized day name (e.g. 'Mon' to 'Sun'). | - | ||||||||||||||||||||||||||||||
887 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
888 | \row \li dddd | - | ||||||||||||||||||||||||||||||
889 | \li the long localized day name (e.g. 'Monday' to 'Sunday'). | - | ||||||||||||||||||||||||||||||
890 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
891 | \row \li M \li the month as number without a leading zero (1 to 12) | - | ||||||||||||||||||||||||||||||
892 | \row \li MM \li the month as number with a leading zero (01 to 12) | - | ||||||||||||||||||||||||||||||
893 | \row \li MMM | - | ||||||||||||||||||||||||||||||
894 | \li the abbreviated localized month name (e.g. 'Jan' to 'Dec'). | - | ||||||||||||||||||||||||||||||
895 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
896 | \row \li MMMM | - | ||||||||||||||||||||||||||||||
897 | \li the long localized month name (e.g. 'January' to 'December'). | - | ||||||||||||||||||||||||||||||
898 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
899 | \row \li yy \li the year as two digit number (00 to 99) | - | ||||||||||||||||||||||||||||||
900 | \row \li yyyy \li the year as four digit number. If the year is negative, | - | ||||||||||||||||||||||||||||||
901 | a minus sign is prepended in addition. | - | ||||||||||||||||||||||||||||||
902 | \endtable | - | ||||||||||||||||||||||||||||||
903 | - | |||||||||||||||||||||||||||||||
904 | All other input characters will be ignored. Any sequence of characters that | - | ||||||||||||||||||||||||||||||
905 | are enclosed in single quotes will be treated as text and not be used as an | - | ||||||||||||||||||||||||||||||
906 | expression. Two consecutive single quotes ("''") are replaced by a singlequote | - | ||||||||||||||||||||||||||||||
907 | in the output. Formats without separators (e.g. "ddMM") are currently not supported. | - | ||||||||||||||||||||||||||||||
908 | - | |||||||||||||||||||||||||||||||
909 | Example format strings (assuming that the QDate is the 20 July | - | ||||||||||||||||||||||||||||||
910 | 1969): | - | ||||||||||||||||||||||||||||||
911 | - | |||||||||||||||||||||||||||||||
912 | \table | - | ||||||||||||||||||||||||||||||
913 | \header \li Format \li Result | - | ||||||||||||||||||||||||||||||
914 | \row \li dd.MM.yyyy \li 20.07.1969 | - | ||||||||||||||||||||||||||||||
915 | \row \li ddd MMMM d yy \li Sun July 20 69 | - | ||||||||||||||||||||||||||||||
916 | \row \li 'The day is' dddd \li The day is Sunday | - | ||||||||||||||||||||||||||||||
917 | \endtable | - | ||||||||||||||||||||||||||||||
918 | - | |||||||||||||||||||||||||||||||
919 | If the datetime is invalid, an empty string will be returned. | - | ||||||||||||||||||||||||||||||
920 | - | |||||||||||||||||||||||||||||||
921 | \sa fromString(), QDateTime::toString(), QTime::toString(), QLocale::toString() | - | ||||||||||||||||||||||||||||||
922 | - | |||||||||||||||||||||||||||||||
923 | */ | - | ||||||||||||||||||||||||||||||
924 | QString QDate::toString(const QString& format) const | - | ||||||||||||||||||||||||||||||
925 | { | - | ||||||||||||||||||||||||||||||
926 | return QLocale::system().toString(*this, format); executed 13785 times by 7 tests: return QLocale::system().toString(*this, format); Executed by:
| 13785 | ||||||||||||||||||||||||||||||
927 | } | - | ||||||||||||||||||||||||||||||
928 | #endif //QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
929 | - | |||||||||||||||||||||||||||||||
930 | /*! | - | ||||||||||||||||||||||||||||||
931 | \fn bool QDate::setYMD(int y, int m, int d) | - | ||||||||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||||||||
933 | \deprecated in 5.0, use setDate() instead. | - | ||||||||||||||||||||||||||||||
934 | - | |||||||||||||||||||||||||||||||
935 | Sets the date's year \a y, month \a m, and day \a d. | - | ||||||||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||||||||
937 | If \a y is in the range 0 to 99, it is interpreted as 1900 to | - | ||||||||||||||||||||||||||||||
938 | 1999. | - | ||||||||||||||||||||||||||||||
939 | Returns \c false if the date is invalid. | - | ||||||||||||||||||||||||||||||
940 | - | |||||||||||||||||||||||||||||||
941 | Use setDate() instead. | - | ||||||||||||||||||||||||||||||
942 | */ | - | ||||||||||||||||||||||||||||||
943 | - | |||||||||||||||||||||||||||||||
944 | /*! | - | ||||||||||||||||||||||||||||||
945 | \since 4.2 | - | ||||||||||||||||||||||||||||||
946 | - | |||||||||||||||||||||||||||||||
947 | Sets the date's \a year, \a month, and \a day. Returns \c true if | - | ||||||||||||||||||||||||||||||
948 | the date is valid; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
949 | - | |||||||||||||||||||||||||||||||
950 | If the specified date is invalid, the QDate object is set to be | - | ||||||||||||||||||||||||||||||
951 | invalid. | - | ||||||||||||||||||||||||||||||
952 | - | |||||||||||||||||||||||||||||||
953 | \sa isValid() | - | ||||||||||||||||||||||||||||||
954 | */ | - | ||||||||||||||||||||||||||||||
955 | bool QDate::setDate(int year, int month, int day) | - | ||||||||||||||||||||||||||||||
956 | { | - | ||||||||||||||||||||||||||||||
957 | if (isValid(year, month, day))
| 11380-21296277 | ||||||||||||||||||||||||||||||
958 | jd = julianDayFromDate(year, month, day); executed 21294616 times by 102 tests: jd = julianDayFromDate(year, month, day); Executed by:
| 21294616 | ||||||||||||||||||||||||||||||
959 | else | - | ||||||||||||||||||||||||||||||
960 | jd = nullJd(); executed 11380 times by 6 tests: jd = nullJd(); Executed by:
| 11380 | ||||||||||||||||||||||||||||||
961 | - | |||||||||||||||||||||||||||||||
962 | return isValid(); executed 21291822 times by 102 tests: return isValid(); Executed by:
| 21291822 | ||||||||||||||||||||||||||||||
963 | } | - | ||||||||||||||||||||||||||||||
964 | - | |||||||||||||||||||||||||||||||
965 | /*! | - | ||||||||||||||||||||||||||||||
966 | \since 4.5 | - | ||||||||||||||||||||||||||||||
967 | - | |||||||||||||||||||||||||||||||
968 | Extracts the date's year, month, and day, and assigns them to | - | ||||||||||||||||||||||||||||||
969 | *\a year, *\a month, and *\a day. The pointers may be null. | - | ||||||||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||||||||
971 | Returns 0 if the date is invalid. | - | ||||||||||||||||||||||||||||||
972 | - | |||||||||||||||||||||||||||||||
973 | \sa year(), month(), day(), isValid() | - | ||||||||||||||||||||||||||||||
974 | */ | - | ||||||||||||||||||||||||||||||
975 | void QDate::getDate(int *year, int *month, int *day) | - | ||||||||||||||||||||||||||||||
976 | { | - | ||||||||||||||||||||||||||||||
977 | ParsedDate pd = { 0, 0, 0 }; | - | ||||||||||||||||||||||||||||||
978 | if (isValid())
| 3-13766956 | ||||||||||||||||||||||||||||||
979 | pd = getDateFromJulianDay(jd); executed 13762626 times by 97 tests: pd = getDateFromJulianDay(jd); Executed by:
| 13762626 | ||||||||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||||||||
981 | if (year)
| 3-13767590 | ||||||||||||||||||||||||||||||
982 | *year = pd.year; executed 13758246 times by 97 tests: *year = pd.year; Executed by:
| 13758246 | ||||||||||||||||||||||||||||||
983 | if (month)
| 3-13768119 | ||||||||||||||||||||||||||||||
984 | *month = pd.month; executed 13768119 times by 97 tests: *month = pd.month; Executed by:
| 13768119 | ||||||||||||||||||||||||||||||
985 | if (day)
| 3-13767049 | ||||||||||||||||||||||||||||||
986 | *day = pd.day; executed 13768119 times by 97 tests: *day = pd.day; Executed by:
| 13768119 | ||||||||||||||||||||||||||||||
987 | } executed 13764451 times by 97 tests: end of block Executed by:
| 13764451 | ||||||||||||||||||||||||||||||
988 | - | |||||||||||||||||||||||||||||||
989 | /*! | - | ||||||||||||||||||||||||||||||
990 | Returns a QDate object containing a date \a ndays later than the | - | ||||||||||||||||||||||||||||||
991 | date of this object (or earlier if \a ndays is negative). | - | ||||||||||||||||||||||||||||||
992 | - | |||||||||||||||||||||||||||||||
993 | Returns a null date if the current date is invalid or the new date is | - | ||||||||||||||||||||||||||||||
994 | out of range. | - | ||||||||||||||||||||||||||||||
995 | - | |||||||||||||||||||||||||||||||
996 | \sa addMonths(), addYears(), daysTo() | - | ||||||||||||||||||||||||||||||
997 | */ | - | ||||||||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||||||||
999 | QDate QDate::addDays(qint64 ndays) const | - | ||||||||||||||||||||||||||||||
1000 | { | - | ||||||||||||||||||||||||||||||
1001 | if (isNull())
| 1-630950 | ||||||||||||||||||||||||||||||
1002 | return QDate(); executed 1 time by 1 test: return QDate(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1003 | - | |||||||||||||||||||||||||||||||
1004 | // Due to limits on minJd() and maxJd() we know that any overflow | - | ||||||||||||||||||||||||||||||
1005 | // will be invalid and caught by fromJulianDay(). | - | ||||||||||||||||||||||||||||||
1006 | return fromJulianDay(jd + ndays); executed 630950 times by 14 tests: return fromJulianDay(jd + ndays); Executed by:
| 630950 | ||||||||||||||||||||||||||||||
1007 | } | - | ||||||||||||||||||||||||||||||
1008 | - | |||||||||||||||||||||||||||||||
1009 | /*! | - | ||||||||||||||||||||||||||||||
1010 | Returns a QDate object containing a date \a nmonths later than the | - | ||||||||||||||||||||||||||||||
1011 | date of this object (or earlier if \a nmonths is negative). | - | ||||||||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||||||||
1013 | \note If the ending day/month combination does not exist in the | - | ||||||||||||||||||||||||||||||
1014 | resulting month/year, this function will return a date that is the | - | ||||||||||||||||||||||||||||||
1015 | latest valid date. | - | ||||||||||||||||||||||||||||||
1016 | - | |||||||||||||||||||||||||||||||
1017 | \sa addDays(), addYears() | - | ||||||||||||||||||||||||||||||
1018 | */ | - | ||||||||||||||||||||||||||||||
1019 | - | |||||||||||||||||||||||||||||||
1020 | QDate QDate::addMonths(int nmonths) const | - | ||||||||||||||||||||||||||||||
1021 | { | - | ||||||||||||||||||||||||||||||
1022 | if (!isValid())
| 1-172 | ||||||||||||||||||||||||||||||
1023 | return QDate(); executed 1 time by 1 test: return QDate(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1024 | if (!nmonths)
| 4-168 | ||||||||||||||||||||||||||||||
1025 | return *this; executed 4 times by 1 test: return *this; Executed by:
| 4 | ||||||||||||||||||||||||||||||
1026 | - | |||||||||||||||||||||||||||||||
1027 | int old_y, y, m, d; | - | ||||||||||||||||||||||||||||||
1028 | { | - | ||||||||||||||||||||||||||||||
1029 | const ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||||||||
1030 | y = pd.year; | - | ||||||||||||||||||||||||||||||
1031 | m = pd.month; | - | ||||||||||||||||||||||||||||||
1032 | d = pd.day; | - | ||||||||||||||||||||||||||||||
1033 | } | - | ||||||||||||||||||||||||||||||
1034 | old_y = y; | - | ||||||||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||||||||
1036 | bool increasing = nmonths > 0; | - | ||||||||||||||||||||||||||||||
1037 | - | |||||||||||||||||||||||||||||||
1038 | while (nmonths != 0) {
| 168-188 | ||||||||||||||||||||||||||||||
1039 | if (nmonths < 0 && nmonths + 12 <= 0) {
| 15-97 | ||||||||||||||||||||||||||||||
1040 | y--; | - | ||||||||||||||||||||||||||||||
1041 | nmonths+=12; | - | ||||||||||||||||||||||||||||||
1042 | } else if (nmonths < 0) { executed 15 times by 2 tests: end of block Executed by:
| 15-91 | ||||||||||||||||||||||||||||||
1043 | m+= nmonths; | - | ||||||||||||||||||||||||||||||
1044 | nmonths = 0; | - | ||||||||||||||||||||||||||||||
1045 | if (m <= 0) {
| 33-49 | ||||||||||||||||||||||||||||||
1046 | --y; | - | ||||||||||||||||||||||||||||||
1047 | m += 12; | - | ||||||||||||||||||||||||||||||
1048 | } executed 49 times by 3 tests: end of block Executed by:
| 49 | ||||||||||||||||||||||||||||||
1049 | } else if (nmonths - 12 >= 0) { executed 82 times by 3 tests: end of block Executed by:
| 16-82 | ||||||||||||||||||||||||||||||
1050 | y++; | - | ||||||||||||||||||||||||||||||
1051 | nmonths -= 12; | - | ||||||||||||||||||||||||||||||
1052 | } else if (m == 12) { executed 16 times by 2 tests: end of block Executed by:
| 2-73 | ||||||||||||||||||||||||||||||
1053 | y++; | - | ||||||||||||||||||||||||||||||
1054 | m = 0; | - | ||||||||||||||||||||||||||||||
1055 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
1056 | m += nmonths; | - | ||||||||||||||||||||||||||||||
1057 | nmonths = 0; | - | ||||||||||||||||||||||||||||||
1058 | if (m > 12) {
| 1-72 | ||||||||||||||||||||||||||||||
1059 | ++y; | - | ||||||||||||||||||||||||||||||
1060 | m -= 12; | - | ||||||||||||||||||||||||||||||
1061 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||
1062 | } executed 73 times by 4 tests: end of block Executed by:
| 73 | ||||||||||||||||||||||||||||||
1063 | } | - | ||||||||||||||||||||||||||||||
1064 | - | |||||||||||||||||||||||||||||||
1065 | // was there a sign change? | - | ||||||||||||||||||||||||||||||
1066 | if ((old_y > 0 && y <= 0) ||
| 2-165 | ||||||||||||||||||||||||||||||
1067 | (old_y < 0 && y >= 0))
| 1-163 | ||||||||||||||||||||||||||||||
1068 | // yes, adjust the date by +1 or -1 years | - | ||||||||||||||||||||||||||||||
1069 | y += increasing ? +1 : -1; executed 4 times by 1 test: y += increasing ? +1 : -1; Executed by:
| 2-4 | ||||||||||||||||||||||||||||||
1070 | - | |||||||||||||||||||||||||||||||
1071 | return fixedDate(y, m, d); executed 168 times by 4 tests: return fixedDate(y, m, d); Executed by:
| 168 | ||||||||||||||||||||||||||||||
1072 | } | - | ||||||||||||||||||||||||||||||
1073 | - | |||||||||||||||||||||||||||||||
1074 | /*! | - | ||||||||||||||||||||||||||||||
1075 | Returns a QDate object containing a date \a nyears later than the | - | ||||||||||||||||||||||||||||||
1076 | date of this object (or earlier if \a nyears is negative). | - | ||||||||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||||||||
1078 | \note If the ending day/month combination does not exist in the | - | ||||||||||||||||||||||||||||||
1079 | resulting year (i.e., if the date was Feb 29 and the final year is | - | ||||||||||||||||||||||||||||||
1080 | not a leap year), this function will return a date that is the | - | ||||||||||||||||||||||||||||||
1081 | latest valid date (that is, Feb 28). | - | ||||||||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||||||||
1083 | \sa addDays(), addMonths() | - | ||||||||||||||||||||||||||||||
1084 | */ | - | ||||||||||||||||||||||||||||||
1085 | - | |||||||||||||||||||||||||||||||
1086 | QDate QDate::addYears(int nyears) const | - | ||||||||||||||||||||||||||||||
1087 | { | - | ||||||||||||||||||||||||||||||
1088 | if (!isValid())
| 1-120 | ||||||||||||||||||||||||||||||
1089 | return QDate(); executed 1 time by 1 test: return QDate(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1090 | - | |||||||||||||||||||||||||||||||
1091 | ParsedDate pd = getDateFromJulianDay(jd); | - | ||||||||||||||||||||||||||||||
1092 | - | |||||||||||||||||||||||||||||||
1093 | int old_y = pd.year; | - | ||||||||||||||||||||||||||||||
1094 | pd.year += nyears; | - | ||||||||||||||||||||||||||||||
1095 | - | |||||||||||||||||||||||||||||||
1096 | // was there a sign change? | - | ||||||||||||||||||||||||||||||
1097 | if ((old_y > 0 && pd.year <= 0) ||
| 8-99 | ||||||||||||||||||||||||||||||
1098 | (old_y < 0 && pd.year >= 0))
| 8-91 | ||||||||||||||||||||||||||||||
1099 | // yes, adjust the date by +1 or -1 years | - | ||||||||||||||||||||||||||||||
1100 | pd.year += nyears > 0 ? +1 : -1; executed 16 times by 2 tests: pd.year += nyears > 0 ? +1 : -1; Executed by:
| 8-16 | ||||||||||||||||||||||||||||||
1101 | - | |||||||||||||||||||||||||||||||
1102 | return fixedDate(pd.year, pd.month, pd.day); executed 120 times by 4 tests: return fixedDate(pd.year, pd.month, pd.day); Executed by:
| 120 | ||||||||||||||||||||||||||||||
1103 | } | - | ||||||||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||||||||
1105 | /*! | - | ||||||||||||||||||||||||||||||
1106 | Returns the number of days from this date to \a d (which is | - | ||||||||||||||||||||||||||||||
1107 | negative if \a d is earlier than this date). | - | ||||||||||||||||||||||||||||||
1108 | - | |||||||||||||||||||||||||||||||
1109 | Returns 0 if either date is invalid. | - | ||||||||||||||||||||||||||||||
1110 | - | |||||||||||||||||||||||||||||||
1111 | Example: | - | ||||||||||||||||||||||||||||||
1112 | \snippet code/src_corelib_tools_qdatetime.cpp 0 | - | ||||||||||||||||||||||||||||||
1113 | - | |||||||||||||||||||||||||||||||
1114 | \sa addDays() | - | ||||||||||||||||||||||||||||||
1115 | */ | - | ||||||||||||||||||||||||||||||
1116 | - | |||||||||||||||||||||||||||||||
1117 | qint64 QDate::daysTo(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1118 | { | - | ||||||||||||||||||||||||||||||
1119 | if (isNull() || d.isNull())
| 1-18656 | ||||||||||||||||||||||||||||||
1120 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||||||||||||||||||||
1121 | - | |||||||||||||||||||||||||||||||
1122 | // Due to limits on minJd() and maxJd() we know this will never overflow | - | ||||||||||||||||||||||||||||||
1123 | return d.jd - jd; executed 18655 times by 14 tests: return d.jd - jd; Executed by:
| 18655 | ||||||||||||||||||||||||||||||
1124 | } | - | ||||||||||||||||||||||||||||||
1125 | - | |||||||||||||||||||||||||||||||
1126 | - | |||||||||||||||||||||||||||||||
1127 | /*! | - | ||||||||||||||||||||||||||||||
1128 | \fn bool QDate::operator==(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1129 | - | |||||||||||||||||||||||||||||||
1130 | Returns \c true if this date is equal to \a d; otherwise returns | - | ||||||||||||||||||||||||||||||
1131 | false. | - | ||||||||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||||||||
1133 | */ | - | ||||||||||||||||||||||||||||||
1134 | - | |||||||||||||||||||||||||||||||
1135 | /*! | - | ||||||||||||||||||||||||||||||
1136 | \fn bool QDate::operator!=(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1137 | - | |||||||||||||||||||||||||||||||
1138 | Returns \c true if this date is different from \a d; otherwise | - | ||||||||||||||||||||||||||||||
1139 | returns \c false. | - | ||||||||||||||||||||||||||||||
1140 | */ | - | ||||||||||||||||||||||||||||||
1141 | - | |||||||||||||||||||||||||||||||
1142 | /*! | - | ||||||||||||||||||||||||||||||
1143 | \fn bool QDate::operator<(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1144 | - | |||||||||||||||||||||||||||||||
1145 | Returns \c true if this date is earlier than \a d; otherwise returns | - | ||||||||||||||||||||||||||||||
1146 | false. | - | ||||||||||||||||||||||||||||||
1147 | */ | - | ||||||||||||||||||||||||||||||
1148 | - | |||||||||||||||||||||||||||||||
1149 | /*! | - | ||||||||||||||||||||||||||||||
1150 | \fn bool QDate::operator<=(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1151 | - | |||||||||||||||||||||||||||||||
1152 | Returns \c true if this date is earlier than or equal to \a d; | - | ||||||||||||||||||||||||||||||
1153 | otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1154 | */ | - | ||||||||||||||||||||||||||||||
1155 | - | |||||||||||||||||||||||||||||||
1156 | /*! | - | ||||||||||||||||||||||||||||||
1157 | \fn bool QDate::operator>(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1158 | - | |||||||||||||||||||||||||||||||
1159 | Returns \c true if this date is later than \a d; otherwise returns | - | ||||||||||||||||||||||||||||||
1160 | false. | - | ||||||||||||||||||||||||||||||
1161 | */ | - | ||||||||||||||||||||||||||||||
1162 | - | |||||||||||||||||||||||||||||||
1163 | /*! | - | ||||||||||||||||||||||||||||||
1164 | \fn bool QDate::operator>=(const QDate &d) const | - | ||||||||||||||||||||||||||||||
1165 | - | |||||||||||||||||||||||||||||||
1166 | Returns \c true if this date is later than or equal to \a d; | - | ||||||||||||||||||||||||||||||
1167 | otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1168 | */ | - | ||||||||||||||||||||||||||||||
1169 | - | |||||||||||||||||||||||||||||||
1170 | /*! | - | ||||||||||||||||||||||||||||||
1171 | \fn QDate::currentDate() | - | ||||||||||||||||||||||||||||||
1172 | Returns the current date, as reported by the system clock. | - | ||||||||||||||||||||||||||||||
1173 | - | |||||||||||||||||||||||||||||||
1174 | \sa QTime::currentTime(), QDateTime::currentDateTime() | - | ||||||||||||||||||||||||||||||
1175 | */ | - | ||||||||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||||||||
1177 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
1178 | /*! | - | ||||||||||||||||||||||||||||||
1179 | \fn QDate QDate::fromString(const QString &string, Qt::DateFormat format) | - | ||||||||||||||||||||||||||||||
1180 | - | |||||||||||||||||||||||||||||||
1181 | Returns the QDate represented by the \a string, using the | - | ||||||||||||||||||||||||||||||
1182 | \a format given, or an invalid date if the string cannot be | - | ||||||||||||||||||||||||||||||
1183 | parsed. | - | ||||||||||||||||||||||||||||||
1184 | - | |||||||||||||||||||||||||||||||
1185 | Note for Qt::TextDate: It is recommended that you use the | - | ||||||||||||||||||||||||||||||
1186 | English short month names (e.g. "Jan"). Although localized month | - | ||||||||||||||||||||||||||||||
1187 | names can also be used, they depend on the user's locale settings. | - | ||||||||||||||||||||||||||||||
1188 | - | |||||||||||||||||||||||||||||||
1189 | \sa toString(), QLocale::toDate() | - | ||||||||||||||||||||||||||||||
1190 | */ | - | ||||||||||||||||||||||||||||||
1191 | QDate QDate::fromString(const QString& string, Qt::DateFormat format) | - | ||||||||||||||||||||||||||||||
1192 | { | - | ||||||||||||||||||||||||||||||
1193 | if (string.isEmpty())
| 2-114 | ||||||||||||||||||||||||||||||
1194 | return QDate(); executed 2 times by 1 test: return QDate(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1195 | - | |||||||||||||||||||||||||||||||
1196 | switch (format) { | - | ||||||||||||||||||||||||||||||
1197 | case Qt::SystemLocaleDate: never executed: case Qt::SystemLocaleDate: | 0 | ||||||||||||||||||||||||||||||
1198 | case Qt::SystemLocaleShortDate: never executed: case Qt::SystemLocaleShortDate: | 0 | ||||||||||||||||||||||||||||||
1199 | return QLocale::system().toDate(string, QLocale::ShortFormat); never executed: return QLocale::system().toDate(string, QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||||||||
1200 | case Qt::SystemLocaleLongDate: never executed: case Qt::SystemLocaleLongDate: | 0 | ||||||||||||||||||||||||||||||
1201 | return QLocale::system().toDate(string, QLocale::LongFormat); never executed: return QLocale::system().toDate(string, QLocale::LongFormat); | 0 | ||||||||||||||||||||||||||||||
1202 | case Qt::LocaleDate: never executed: case Qt::LocaleDate: | 0 | ||||||||||||||||||||||||||||||
1203 | case Qt::DefaultLocaleShortDate: never executed: case Qt::DefaultLocaleShortDate: | 0 | ||||||||||||||||||||||||||||||
1204 | return QLocale().toDate(string, QLocale::ShortFormat); never executed: return QLocale().toDate(string, QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||||||||
1205 | case Qt::DefaultLocaleLongDate: never executed: case Qt::DefaultLocaleLongDate: | 0 | ||||||||||||||||||||||||||||||
1206 | return QLocale().toDate(string, QLocale::LongFormat); never executed: return QLocale().toDate(string, QLocale::LongFormat); | 0 | ||||||||||||||||||||||||||||||
1207 | case Qt::RFC2822Date: executed 21 times by 1 test: case Qt::RFC2822Date: Executed by:
| 21 | ||||||||||||||||||||||||||||||
1208 | return rfcDateImpl(string).date; executed 21 times by 1 test: return rfcDateImpl(string).date; Executed by:
| 21 | ||||||||||||||||||||||||||||||
1209 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
1210 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
1211 | case Qt::TextDate: { executed 14 times by 1 test: case Qt::TextDate: Executed by:
| 14 | ||||||||||||||||||||||||||||||
1212 | QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||||||||
1213 | - | |||||||||||||||||||||||||||||||
1214 | if (parts.count() != 4)
| 1-13 | ||||||||||||||||||||||||||||||
1215 | return QDate(); executed 1 time by 1 test: return QDate(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1216 | - | |||||||||||||||||||||||||||||||
1217 | QStringRef monthName = parts.at(1); | - | ||||||||||||||||||||||||||||||
1218 | const int month = fromShortMonthName(monthName); | - | ||||||||||||||||||||||||||||||
1219 | if (month == -1) {
| 1-12 | ||||||||||||||||||||||||||||||
1220 | // Month name matches neither English nor other localised name. | - | ||||||||||||||||||||||||||||||
1221 | return QDate(); executed 1 time by 1 test: return QDate(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1222 | } | - | ||||||||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||||||||
1224 | bool ok = false; | - | ||||||||||||||||||||||||||||||
1225 | int year = parts.at(3).toInt(&ok); | - | ||||||||||||||||||||||||||||||
1226 | if (!ok)
| 1-11 | ||||||||||||||||||||||||||||||
1227 | return QDate(); executed 1 time by 1 test: return QDate(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1228 | - | |||||||||||||||||||||||||||||||
1229 | return QDate(year, month, parts.at(2).toInt()); executed 11 times by 1 test: return QDate(year, month, parts.at(2).toInt()); Executed by:
| 11 | ||||||||||||||||||||||||||||||
1230 | } | - | ||||||||||||||||||||||||||||||
1231 | #endif // QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
1232 | case Qt::ISODate: { executed 79 times by 5 tests: case Qt::ISODate: Executed by:
| 79 | ||||||||||||||||||||||||||||||
1233 | // Semi-strict parsing, must be long enough and have non-numeric separators | - | ||||||||||||||||||||||||||||||
1234 | if (string.size() < 10 || string.at(4).isDigit() || string.at(7).isDigit()
| 0-78 | ||||||||||||||||||||||||||||||
1235 | || (string.size() > 10 && string.at(10).isDigit())) {
| 1-69 | ||||||||||||||||||||||||||||||
1236 | return QDate(); executed 8 times by 3 tests: return QDate(); Executed by:
| 8 | ||||||||||||||||||||||||||||||
1237 | } | - | ||||||||||||||||||||||||||||||
1238 | const int year = string.midRef(0, 4).toInt(); | - | ||||||||||||||||||||||||||||||
1239 | if (year <= 0 || year > 9999)
| 0-67 | ||||||||||||||||||||||||||||||
1240 | return QDate(); executed 4 times by 2 tests: return QDate(); Executed by:
| 4 | ||||||||||||||||||||||||||||||
1241 | return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt()); executed 67 times by 5 tests: return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt()); Executed by:
| 67 | ||||||||||||||||||||||||||||||
1242 | } | - | ||||||||||||||||||||||||||||||
1243 | } | - | ||||||||||||||||||||||||||||||
1244 | return QDate(); never executed: return QDate(); | 0 | ||||||||||||||||||||||||||||||
1245 | } | - | ||||||||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||||||||
1247 | /*! | - | ||||||||||||||||||||||||||||||
1248 | \fn QDate::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||||||||
1249 | - | |||||||||||||||||||||||||||||||
1250 | Returns the QDate represented by the \a string, using the \a | - | ||||||||||||||||||||||||||||||
1251 | format given, or an invalid date if the string cannot be parsed. | - | ||||||||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||||||||
1253 | These expressions may be used for the format: | - | ||||||||||||||||||||||||||||||
1254 | - | |||||||||||||||||||||||||||||||
1255 | \table | - | ||||||||||||||||||||||||||||||
1256 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
1257 | \row \li d \li The day as a number without a leading zero (1 to 31) | - | ||||||||||||||||||||||||||||||
1258 | \row \li dd \li The day as a number with a leading zero (01 to 31) | - | ||||||||||||||||||||||||||||||
1259 | \row \li ddd | - | ||||||||||||||||||||||||||||||
1260 | \li The abbreviated localized day name (e.g. 'Mon' to 'Sun'). | - | ||||||||||||||||||||||||||||||
1261 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
1262 | \row \li dddd | - | ||||||||||||||||||||||||||||||
1263 | \li The long localized day name (e.g. 'Monday' to 'Sunday'). | - | ||||||||||||||||||||||||||||||
1264 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
1265 | \row \li M \li The month as a number without a leading zero (1 to 12) | - | ||||||||||||||||||||||||||||||
1266 | \row \li MM \li The month as a number with a leading zero (01 to 12) | - | ||||||||||||||||||||||||||||||
1267 | \row \li MMM | - | ||||||||||||||||||||||||||||||
1268 | \li The abbreviated localized month name (e.g. 'Jan' to 'Dec'). | - | ||||||||||||||||||||||||||||||
1269 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
1270 | \row \li MMMM | - | ||||||||||||||||||||||||||||||
1271 | \li The long localized month name (e.g. 'January' to 'December'). | - | ||||||||||||||||||||||||||||||
1272 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
1273 | \row \li yy \li The year as two digit number (00 to 99) | - | ||||||||||||||||||||||||||||||
1274 | \row \li yyyy \li The year as four digit number. If the year is negative, | - | ||||||||||||||||||||||||||||||
1275 | a minus sign is prepended in addition. | - | ||||||||||||||||||||||||||||||
1276 | \endtable | - | ||||||||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||||||||
1278 | All other input characters will be treated as text. Any sequence | - | ||||||||||||||||||||||||||||||
1279 | of characters that are enclosed in single quotes will also be | - | ||||||||||||||||||||||||||||||
1280 | treated as text and will not be used as an expression. For example: | - | ||||||||||||||||||||||||||||||
1281 | - | |||||||||||||||||||||||||||||||
1282 | \snippet code/src_corelib_tools_qdatetime.cpp 1 | - | ||||||||||||||||||||||||||||||
1283 | - | |||||||||||||||||||||||||||||||
1284 | If the format is not satisfied, an invalid QDate is returned. The | - | ||||||||||||||||||||||||||||||
1285 | expressions that don't expect leading zeroes (d, M) will be | - | ||||||||||||||||||||||||||||||
1286 | greedy. This means that they will use two digits even if this | - | ||||||||||||||||||||||||||||||
1287 | will put them outside the accepted range of values and leaves too | - | ||||||||||||||||||||||||||||||
1288 | few digits for other sections. For example, the following format | - | ||||||||||||||||||||||||||||||
1289 | string could have meant January 30 but the M will grab two | - | ||||||||||||||||||||||||||||||
1290 | digits, resulting in an invalid date: | - | ||||||||||||||||||||||||||||||
1291 | - | |||||||||||||||||||||||||||||||
1292 | \snippet code/src_corelib_tools_qdatetime.cpp 2 | - | ||||||||||||||||||||||||||||||
1293 | - | |||||||||||||||||||||||||||||||
1294 | For any field that is not represented in the format the following | - | ||||||||||||||||||||||||||||||
1295 | defaults are used: | - | ||||||||||||||||||||||||||||||
1296 | - | |||||||||||||||||||||||||||||||
1297 | \table | - | ||||||||||||||||||||||||||||||
1298 | \header \li Field \li Default value | - | ||||||||||||||||||||||||||||||
1299 | \row \li Year \li 1900 | - | ||||||||||||||||||||||||||||||
1300 | \row \li Month \li 1 | - | ||||||||||||||||||||||||||||||
1301 | \row \li Day \li 1 | - | ||||||||||||||||||||||||||||||
1302 | \endtable | - | ||||||||||||||||||||||||||||||
1303 | - | |||||||||||||||||||||||||||||||
1304 | The following examples demonstrate the default values: | - | ||||||||||||||||||||||||||||||
1305 | - | |||||||||||||||||||||||||||||||
1306 | \snippet code/src_corelib_tools_qdatetime.cpp 3 | - | ||||||||||||||||||||||||||||||
1307 | - | |||||||||||||||||||||||||||||||
1308 | \sa toString(), QDateTime::fromString(), QTime::fromString(), | - | ||||||||||||||||||||||||||||||
1309 | QLocale::toDate() | - | ||||||||||||||||||||||||||||||
1310 | */ | - | ||||||||||||||||||||||||||||||
1311 | - | |||||||||||||||||||||||||||||||
1312 | QDate QDate::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||||||||
1313 | { | - | ||||||||||||||||||||||||||||||
1314 | QDate date; | - | ||||||||||||||||||||||||||||||
1315 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
1316 | QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||||||||
1317 | if (dt.parseFormat(format))
| 0-44 | ||||||||||||||||||||||||||||||
1318 | dt.fromString(string, &date, 0); executed 44 times by 1 test: dt.fromString(string, &date, 0); Executed by:
| 44 | ||||||||||||||||||||||||||||||
1319 | #else | - | ||||||||||||||||||||||||||||||
1320 | Q_UNUSED(string); | - | ||||||||||||||||||||||||||||||
1321 | Q_UNUSED(format); | - | ||||||||||||||||||||||||||||||
1322 | #endif | - | ||||||||||||||||||||||||||||||
1323 | return date; executed 44 times by 1 test: return date; Executed by:
| 44 | ||||||||||||||||||||||||||||||
1324 | } | - | ||||||||||||||||||||||||||||||
1325 | #endif // QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
1326 | - | |||||||||||||||||||||||||||||||
1327 | /*! | - | ||||||||||||||||||||||||||||||
1328 | \overload | - | ||||||||||||||||||||||||||||||
1329 | - | |||||||||||||||||||||||||||||||
1330 | Returns \c true if the specified date (\a year, \a month, and \a | - | ||||||||||||||||||||||||||||||
1331 | day) is valid; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1332 | - | |||||||||||||||||||||||||||||||
1333 | Example: | - | ||||||||||||||||||||||||||||||
1334 | \snippet code/src_corelib_tools_qdatetime.cpp 4 | - | ||||||||||||||||||||||||||||||
1335 | - | |||||||||||||||||||||||||||||||
1336 | \sa isNull(), setDate() | - | ||||||||||||||||||||||||||||||
1337 | */ | - | ||||||||||||||||||||||||||||||
1338 | - | |||||||||||||||||||||||||||||||
1339 | bool QDate::isValid(int year, int month, int day) | - | ||||||||||||||||||||||||||||||
1340 | { | - | ||||||||||||||||||||||||||||||
1341 | // there is no year 0 in the Gregorian calendar | - | ||||||||||||||||||||||||||||||
1342 | if (year == 0)
| 143-21284773 | ||||||||||||||||||||||||||||||
1343 | return false; executed 143 times by 4 tests: return false; Executed by:
| 143 | ||||||||||||||||||||||||||||||
1344 | - | |||||||||||||||||||||||||||||||
1345 | return (day > 0 && month > 0 && month <= 12) && executed 21313708 times by 102 tests: return (day > 0 && month > 0 && month <= 12) && (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year))); Executed by:
| 4-21316474 | ||||||||||||||||||||||||||||||
1346 | (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year))); executed 21313708 times by 102 tests: return (day > 0 && month > 0 && month <= 12) && (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year))); Executed by:
| 0-21313708 | ||||||||||||||||||||||||||||||
1347 | } | - | ||||||||||||||||||||||||||||||
1348 | - | |||||||||||||||||||||||||||||||
1349 | /*! | - | ||||||||||||||||||||||||||||||
1350 | \fn bool QDate::isLeapYear(int year) | - | ||||||||||||||||||||||||||||||
1351 | - | |||||||||||||||||||||||||||||||
1352 | Returns \c true if the specified \a year is a leap year; otherwise | - | ||||||||||||||||||||||||||||||
1353 | returns \c false. | - | ||||||||||||||||||||||||||||||
1354 | */ | - | ||||||||||||||||||||||||||||||
1355 | - | |||||||||||||||||||||||||||||||
1356 | bool QDate::isLeapYear(int y) | - | ||||||||||||||||||||||||||||||
1357 | { | - | ||||||||||||||||||||||||||||||
1358 | // No year 0 in Gregorian calendar, so -1, -5, -9 etc are leap years | - | ||||||||||||||||||||||||||||||
1359 | if ( y < 1)
| 9596-27921 | ||||||||||||||||||||||||||||||
1360 | ++y; executed 9596 times by 1 test: ++y; Executed by:
| 9596 | ||||||||||||||||||||||||||||||
1361 | - | |||||||||||||||||||||||||||||||
1362 | return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; executed 37517 times by 9 tests: return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; Executed by:
| 493-37517 | ||||||||||||||||||||||||||||||
1363 | } | - | ||||||||||||||||||||||||||||||
1364 | - | |||||||||||||||||||||||||||||||
1365 | /*! \fn static QDate QDate::fromJulianDay(qint64 jd) | - | ||||||||||||||||||||||||||||||
1366 | - | |||||||||||||||||||||||||||||||
1367 | Converts the Julian day \a jd to a QDate. | - | ||||||||||||||||||||||||||||||
1368 | - | |||||||||||||||||||||||||||||||
1369 | \sa toJulianDay() | - | ||||||||||||||||||||||||||||||
1370 | */ | - | ||||||||||||||||||||||||||||||
1371 | - | |||||||||||||||||||||||||||||||
1372 | /*! \fn int QDate::toJulianDay() const | - | ||||||||||||||||||||||||||||||
1373 | - | |||||||||||||||||||||||||||||||
1374 | Converts the date to a Julian day. | - | ||||||||||||||||||||||||||||||
1375 | - | |||||||||||||||||||||||||||||||
1376 | \sa fromJulianDay() | - | ||||||||||||||||||||||||||||||
1377 | */ | - | ||||||||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||||||||
1379 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
1380 | QTime member functions | - | ||||||||||||||||||||||||||||||
1381 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
1382 | - | |||||||||||||||||||||||||||||||
1383 | /*! | - | ||||||||||||||||||||||||||||||
1384 | \class QTime | - | ||||||||||||||||||||||||||||||
1385 | \inmodule QtCore | - | ||||||||||||||||||||||||||||||
1386 | \reentrant | - | ||||||||||||||||||||||||||||||
1387 | - | |||||||||||||||||||||||||||||||
1388 | \brief The QTime class provides clock time functions. | - | ||||||||||||||||||||||||||||||
1389 | - | |||||||||||||||||||||||||||||||
1390 | - | |||||||||||||||||||||||||||||||
1391 | A QTime object contains a clock time, i.e. the number of hours, | - | ||||||||||||||||||||||||||||||
1392 | minutes, seconds, and milliseconds since midnight. It can read the | - | ||||||||||||||||||||||||||||||
1393 | current time from the system clock and measure a span of elapsed | - | ||||||||||||||||||||||||||||||
1394 | time. It provides functions for comparing times and for | - | ||||||||||||||||||||||||||||||
1395 | manipulating a time by adding a number of milliseconds. | - | ||||||||||||||||||||||||||||||
1396 | - | |||||||||||||||||||||||||||||||
1397 | QTime uses the 24-hour clock format; it has no concept of AM/PM. | - | ||||||||||||||||||||||||||||||
1398 | Unlike QDateTime, QTime knows nothing about time zones or | - | ||||||||||||||||||||||||||||||
1399 | daylight-saving time (DST). | - | ||||||||||||||||||||||||||||||
1400 | - | |||||||||||||||||||||||||||||||
1401 | A QTime object is typically created either by giving the number | - | ||||||||||||||||||||||||||||||
1402 | of hours, minutes, seconds, and milliseconds explicitly, or by | - | ||||||||||||||||||||||||||||||
1403 | using the static function currentTime(), which creates a QTime | - | ||||||||||||||||||||||||||||||
1404 | object that contains the system's local time. Note that the | - | ||||||||||||||||||||||||||||||
1405 | accuracy depends on the accuracy of the underlying operating | - | ||||||||||||||||||||||||||||||
1406 | system; not all systems provide 1-millisecond accuracy. | - | ||||||||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||||||||
1408 | The hour(), minute(), second(), and msec() functions provide | - | ||||||||||||||||||||||||||||||
1409 | access to the number of hours, minutes, seconds, and milliseconds | - | ||||||||||||||||||||||||||||||
1410 | of the time. The same information is provided in textual format by | - | ||||||||||||||||||||||||||||||
1411 | the toString() function. | - | ||||||||||||||||||||||||||||||
1412 | - | |||||||||||||||||||||||||||||||
1413 | QTime provides a full set of operators to compare two QTime | - | ||||||||||||||||||||||||||||||
1414 | objects. QTime A is considered smaller than QTime B if A is | - | ||||||||||||||||||||||||||||||
1415 | earlier than B. | - | ||||||||||||||||||||||||||||||
1416 | - | |||||||||||||||||||||||||||||||
1417 | The addSecs() and addMSecs() functions provide the time a given | - | ||||||||||||||||||||||||||||||
1418 | number of seconds or milliseconds later than a given time. | - | ||||||||||||||||||||||||||||||
1419 | Correspondingly, the number of seconds or milliseconds | - | ||||||||||||||||||||||||||||||
1420 | between two times can be found using secsTo() or msecsTo(). | - | ||||||||||||||||||||||||||||||
1421 | - | |||||||||||||||||||||||||||||||
1422 | QTime can be used to measure a span of elapsed time using the | - | ||||||||||||||||||||||||||||||
1423 | start(), restart(), and elapsed() functions. | - | ||||||||||||||||||||||||||||||
1424 | - | |||||||||||||||||||||||||||||||
1425 | \sa QDate, QDateTime | - | ||||||||||||||||||||||||||||||
1426 | */ | - | ||||||||||||||||||||||||||||||
1427 | - | |||||||||||||||||||||||||||||||
1428 | /*! | - | ||||||||||||||||||||||||||||||
1429 | \fn QTime::QTime() | - | ||||||||||||||||||||||||||||||
1430 | - | |||||||||||||||||||||||||||||||
1431 | Constructs a null time object. A null time can be a QTime(0, 0, 0, 0) | - | ||||||||||||||||||||||||||||||
1432 | (i.e., midnight) object, except that isNull() returns \c true and isValid() | - | ||||||||||||||||||||||||||||||
1433 | returns \c false. | - | ||||||||||||||||||||||||||||||
1434 | - | |||||||||||||||||||||||||||||||
1435 | \sa isNull(), isValid() | - | ||||||||||||||||||||||||||||||
1436 | */ | - | ||||||||||||||||||||||||||||||
1437 | - | |||||||||||||||||||||||||||||||
1438 | /*! | - | ||||||||||||||||||||||||||||||
1439 | Constructs a time with hour \a h, minute \a m, seconds \a s and | - | ||||||||||||||||||||||||||||||
1440 | milliseconds \a ms. | - | ||||||||||||||||||||||||||||||
1441 | - | |||||||||||||||||||||||||||||||
1442 | \a h must be in the range 0 to 23, \a m and \a s must be in the | - | ||||||||||||||||||||||||||||||
1443 | range 0 to 59, and \a ms must be in the range 0 to 999. | - | ||||||||||||||||||||||||||||||
1444 | - | |||||||||||||||||||||||||||||||
1445 | \sa isValid() | - | ||||||||||||||||||||||||||||||
1446 | */ | - | ||||||||||||||||||||||||||||||
1447 | - | |||||||||||||||||||||||||||||||
1448 | QTime::QTime(int h, int m, int s, int ms) | - | ||||||||||||||||||||||||||||||
1449 | { | - | ||||||||||||||||||||||||||||||
1450 | setHMS(h, m, s, ms); | - | ||||||||||||||||||||||||||||||
1451 | } executed 20675576 times by 103 tests: end of block Executed by:
| 20675576 | ||||||||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||||||||
1453 | - | |||||||||||||||||||||||||||||||
1454 | /*! | - | ||||||||||||||||||||||||||||||
1455 | \fn bool QTime::isNull() const | - | ||||||||||||||||||||||||||||||
1456 | - | |||||||||||||||||||||||||||||||
1457 | Returns \c true if the time is null (i.e., the QTime object was | - | ||||||||||||||||||||||||||||||
1458 | constructed using the default constructor); otherwise returns | - | ||||||||||||||||||||||||||||||
1459 | false. A null time is also an invalid time. | - | ||||||||||||||||||||||||||||||
1460 | - | |||||||||||||||||||||||||||||||
1461 | \sa isValid() | - | ||||||||||||||||||||||||||||||
1462 | */ | - | ||||||||||||||||||||||||||||||
1463 | - | |||||||||||||||||||||||||||||||
1464 | /*! | - | ||||||||||||||||||||||||||||||
1465 | Returns \c true if the time is valid; otherwise returns \c false. For example, | - | ||||||||||||||||||||||||||||||
1466 | the time 23:30:55.746 is valid, but 24:12:30 is invalid. | - | ||||||||||||||||||||||||||||||
1467 | - | |||||||||||||||||||||||||||||||
1468 | \sa isNull() | - | ||||||||||||||||||||||||||||||
1469 | */ | - | ||||||||||||||||||||||||||||||
1470 | - | |||||||||||||||||||||||||||||||
1471 | bool QTime::isValid() const | - | ||||||||||||||||||||||||||||||
1472 | { | - | ||||||||||||||||||||||||||||||
1473 | return mds > NullTime && mds < MSECS_PER_DAY; executed 82666006 times by 105 tests: return mds > NullTime && mds < MSECS_PER_DAY; Executed by:
| 101-82722004 | ||||||||||||||||||||||||||||||
1474 | } | - | ||||||||||||||||||||||||||||||
1475 | - | |||||||||||||||||||||||||||||||
1476 | - | |||||||||||||||||||||||||||||||
1477 | /*! | - | ||||||||||||||||||||||||||||||
1478 | Returns the hour part (0 to 23) of the time. | - | ||||||||||||||||||||||||||||||
1479 | - | |||||||||||||||||||||||||||||||
1480 | Returns -1 if the time is invalid. | - | ||||||||||||||||||||||||||||||
1481 | - | |||||||||||||||||||||||||||||||
1482 | \sa minute(), second(), msec() | - | ||||||||||||||||||||||||||||||
1483 | */ | - | ||||||||||||||||||||||||||||||
1484 | - | |||||||||||||||||||||||||||||||
1485 | int QTime::hour() const | - | ||||||||||||||||||||||||||||||
1486 | { | - | ||||||||||||||||||||||||||||||
1487 | if (!isValid())
| 4-13783783 | ||||||||||||||||||||||||||||||
1488 | return -1; executed 4 times by 1 test: return -1; Executed by:
| 4 | ||||||||||||||||||||||||||||||
1489 | - | |||||||||||||||||||||||||||||||
1490 | return ds() / MSECS_PER_HOUR; executed 13783783 times by 99 tests: return ds() / MSECS_PER_HOUR; Executed by:
| 13783783 | ||||||||||||||||||||||||||||||
1491 | } | - | ||||||||||||||||||||||||||||||
1492 | - | |||||||||||||||||||||||||||||||
1493 | /*! | - | ||||||||||||||||||||||||||||||
1494 | Returns the minute part (0 to 59) of the time. | - | ||||||||||||||||||||||||||||||
1495 | - | |||||||||||||||||||||||||||||||
1496 | Returns -1 if the time is invalid. | - | ||||||||||||||||||||||||||||||
1497 | - | |||||||||||||||||||||||||||||||
1498 | \sa hour(), second(), msec() | - | ||||||||||||||||||||||||||||||
1499 | */ | - | ||||||||||||||||||||||||||||||
1500 | - | |||||||||||||||||||||||||||||||
1501 | int QTime::minute() const | - | ||||||||||||||||||||||||||||||
1502 | { | - | ||||||||||||||||||||||||||||||
1503 | if (!isValid())
| 4-13779516 | ||||||||||||||||||||||||||||||
1504 | return -1; executed 4 times by 1 test: return -1; Executed by:
| 4 | ||||||||||||||||||||||||||||||
1505 | - | |||||||||||||||||||||||||||||||
1506 | return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN; executed 13770858 times by 99 tests: return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN; Executed by:
| 13770858 | ||||||||||||||||||||||||||||||
1507 | } | - | ||||||||||||||||||||||||||||||
1508 | - | |||||||||||||||||||||||||||||||
1509 | /*! | - | ||||||||||||||||||||||||||||||
1510 | Returns the second part (0 to 59) of the time. | - | ||||||||||||||||||||||||||||||
1511 | - | |||||||||||||||||||||||||||||||
1512 | Returns -1 if the time is invalid. | - | ||||||||||||||||||||||||||||||
1513 | - | |||||||||||||||||||||||||||||||
1514 | \sa hour(), minute(), msec() | - | ||||||||||||||||||||||||||||||
1515 | */ | - | ||||||||||||||||||||||||||||||
1516 | - | |||||||||||||||||||||||||||||||
1517 | int QTime::second() const | - | ||||||||||||||||||||||||||||||
1518 | { | - | ||||||||||||||||||||||||||||||
1519 | if (!isValid())
| 4-13772434 | ||||||||||||||||||||||||||||||
1520 | return -1; executed 4 times by 1 test: return -1; Executed by:
| 4 | ||||||||||||||||||||||||||||||
1521 | - | |||||||||||||||||||||||||||||||
1522 | return (ds() / 1000)%SECS_PER_MIN; executed 13771188 times by 99 tests: return (ds() / 1000)%SECS_PER_MIN; Executed by:
| 13771188 | ||||||||||||||||||||||||||||||
1523 | } | - | ||||||||||||||||||||||||||||||
1524 | - | |||||||||||||||||||||||||||||||
1525 | /*! | - | ||||||||||||||||||||||||||||||
1526 | Returns the millisecond part (0 to 999) of the time. | - | ||||||||||||||||||||||||||||||
1527 | - | |||||||||||||||||||||||||||||||
1528 | Returns -1 if the time is invalid. | - | ||||||||||||||||||||||||||||||
1529 | - | |||||||||||||||||||||||||||||||
1530 | \sa hour(), minute(), second() | - | ||||||||||||||||||||||||||||||
1531 | */ | - | ||||||||||||||||||||||||||||||
1532 | - | |||||||||||||||||||||||||||||||
1533 | int QTime::msec() const | - | ||||||||||||||||||||||||||||||
1534 | { | - | ||||||||||||||||||||||||||||||
1535 | if (!isValid())
| 3-13772830 | ||||||||||||||||||||||||||||||
1536 | return -1; executed 3 times by 1 test: return -1; Executed by:
| 3 | ||||||||||||||||||||||||||||||
1537 | - | |||||||||||||||||||||||||||||||
1538 | return ds() % 1000; executed 13773882 times by 99 tests: return ds() % 1000; Executed by:
| 13773882 | ||||||||||||||||||||||||||||||
1539 | } | - | ||||||||||||||||||||||||||||||
1540 | - | |||||||||||||||||||||||||||||||
1541 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
1542 | /*! | - | ||||||||||||||||||||||||||||||
1543 | \overload | - | ||||||||||||||||||||||||||||||
1544 | - | |||||||||||||||||||||||||||||||
1545 | Returns the time as a string. The \a format parameter determines | - | ||||||||||||||||||||||||||||||
1546 | the format of the string. | - | ||||||||||||||||||||||||||||||
1547 | - | |||||||||||||||||||||||||||||||
1548 | If \a format is Qt::TextDate, the string format is HH:mm:ss; | - | ||||||||||||||||||||||||||||||
1549 | e.g. 1 second before midnight would be "23:59:59". | - | ||||||||||||||||||||||||||||||
1550 | - | |||||||||||||||||||||||||||||||
1551 | If \a format is Qt::ISODate, the string format corresponds to the | - | ||||||||||||||||||||||||||||||
1552 | ISO 8601 extended specification for representations of dates, | - | ||||||||||||||||||||||||||||||
1553 | which is also HH:mm:ss. | - | ||||||||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||||||||
1555 | If the \a format is Qt::SystemLocaleShortDate or | - | ||||||||||||||||||||||||||||||
1556 | Qt::SystemLocaleLongDate, the string format depends on the locale | - | ||||||||||||||||||||||||||||||
1557 | settings of the system. Identical to calling | - | ||||||||||||||||||||||||||||||
1558 | QLocale::system().toString(time, QLocale::ShortFormat) or | - | ||||||||||||||||||||||||||||||
1559 | QLocale::system().toString(time, QLocale::LongFormat). | - | ||||||||||||||||||||||||||||||
1560 | - | |||||||||||||||||||||||||||||||
1561 | If the \a format is Qt::DefaultLocaleShortDate or | - | ||||||||||||||||||||||||||||||
1562 | Qt::DefaultLocaleLongDate, the string format depends on the | - | ||||||||||||||||||||||||||||||
1563 | default application locale. This is the locale set with | - | ||||||||||||||||||||||||||||||
1564 | QLocale::setDefault(), or the system locale if no default locale | - | ||||||||||||||||||||||||||||||
1565 | has been set. Identical to calling | - | ||||||||||||||||||||||||||||||
1566 | - | |||||||||||||||||||||||||||||||
1567 | \l {QLocale::toString()}{QLocale().toString(time, QLocale::ShortFormat)} or | - | ||||||||||||||||||||||||||||||
1568 | \l {QLocale::toString()}{QLocale().toString(time, QLocale::LongFormat)}. | - | ||||||||||||||||||||||||||||||
1569 | - | |||||||||||||||||||||||||||||||
1570 | If the \a format is Qt::RFC2822Date, the string is formatted in | - | ||||||||||||||||||||||||||||||
1571 | an \l{RFC 2822} compatible way. An example of this formatting is | - | ||||||||||||||||||||||||||||||
1572 | "23:59:20". | - | ||||||||||||||||||||||||||||||
1573 | - | |||||||||||||||||||||||||||||||
1574 | If the time is invalid, an empty string will be returned. | - | ||||||||||||||||||||||||||||||
1575 | - | |||||||||||||||||||||||||||||||
1576 | \sa fromString(), QDate::toString(), QDateTime::toString(), QLocale::toString() | - | ||||||||||||||||||||||||||||||
1577 | */ | - | ||||||||||||||||||||||||||||||
1578 | - | |||||||||||||||||||||||||||||||
1579 | QString QTime::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||||||||
1580 | { | - | ||||||||||||||||||||||||||||||
1581 | if (!isValid())
| 0-486 | ||||||||||||||||||||||||||||||
1582 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
1583 | - | |||||||||||||||||||||||||||||||
1584 | switch (format) { | - | ||||||||||||||||||||||||||||||
1585 | case Qt::SystemLocaleDate: never executed: case Qt::SystemLocaleDate: | 0 | ||||||||||||||||||||||||||||||
1586 | case Qt::SystemLocaleShortDate: executed 2 times by 1 test: case Qt::SystemLocaleShortDate: Executed by:
| 2 | ||||||||||||||||||||||||||||||
1587 | return QLocale::system().toString(*this, QLocale::ShortFormat); executed 2 times by 1 test: return QLocale::system().toString(*this, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1588 | case Qt::SystemLocaleLongDate: executed 2 times by 1 test: case Qt::SystemLocaleLongDate: Executed by:
| 2 | ||||||||||||||||||||||||||||||
1589 | return QLocale::system().toString(*this, QLocale::LongFormat); executed 2 times by 1 test: return QLocale::system().toString(*this, QLocale::LongFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1590 | case Qt::LocaleDate: never executed: case Qt::LocaleDate: | 0 | ||||||||||||||||||||||||||||||
1591 | case Qt::DefaultLocaleShortDate: executed 2 times by 1 test: case Qt::DefaultLocaleShortDate: Executed by:
| 2 | ||||||||||||||||||||||||||||||
1592 | return QLocale().toString(*this, QLocale::ShortFormat); executed 2 times by 1 test: return QLocale().toString(*this, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1593 | case Qt::DefaultLocaleLongDate: executed 2 times by 1 test: case Qt::DefaultLocaleLongDate: Executed by:
| 2 | ||||||||||||||||||||||||||||||
1594 | return QLocale().toString(*this, QLocale::LongFormat); executed 2 times by 1 test: return QLocale().toString(*this, QLocale::LongFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1595 | case Qt::RFC2822Date: executed 1 time by 1 test: case Qt::RFC2822Date: Executed by:
| 1 | ||||||||||||||||||||||||||||||
1596 | case Qt::ISODate: executed 32 times by 5 tests: case Qt::ISODate: Executed by:
| 32 | ||||||||||||||||||||||||||||||
1597 | case Qt::TextDate: executed 445 times by 5 tests: case Qt::TextDate: Executed by:
| 445 | ||||||||||||||||||||||||||||||
1598 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
1599 | return QString::asprintf("%02d:%02d:%02d", hour(), minute(), second()); executed 478 times by 8 tests: return QString::asprintf("%02d:%02d:%02d", hour(), minute(), second()); Executed by:
| 478 | ||||||||||||||||||||||||||||||
1600 | } | - | ||||||||||||||||||||||||||||||
1601 | } | - | ||||||||||||||||||||||||||||||
1602 | - | |||||||||||||||||||||||||||||||
1603 | /*! | - | ||||||||||||||||||||||||||||||
1604 | Returns the time as a string. The \a format parameter determines | - | ||||||||||||||||||||||||||||||
1605 | the format of the result string. | - | ||||||||||||||||||||||||||||||
1606 | - | |||||||||||||||||||||||||||||||
1607 | These expressions may be used: | - | ||||||||||||||||||||||||||||||
1608 | - | |||||||||||||||||||||||||||||||
1609 | \table | - | ||||||||||||||||||||||||||||||
1610 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
1611 | \row \li h | - | ||||||||||||||||||||||||||||||
1612 | \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
1613 | \row \li hh | - | ||||||||||||||||||||||||||||||
1614 | \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
1615 | \row \li H | - | ||||||||||||||||||||||||||||||
1616 | \li the hour without a leading zero (0 to 23, even with AM/PM display) | - | ||||||||||||||||||||||||||||||
1617 | \row \li HH | - | ||||||||||||||||||||||||||||||
1618 | \li the hour with a leading zero (00 to 23, even with AM/PM display) | - | ||||||||||||||||||||||||||||||
1619 | \row \li m \li the minute without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
1620 | \row \li mm \li the minute with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
1621 | \row \li s \li the second without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
1622 | \row \li ss \li the second with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
1623 | \row \li z \li the milliseconds without leading zeroes (0 to 999) | - | ||||||||||||||||||||||||||||||
1624 | \row \li zzz \li the milliseconds with leading zeroes (000 to 999) | - | ||||||||||||||||||||||||||||||
1625 | \row \li AP or A | - | ||||||||||||||||||||||||||||||
1626 | \li use AM/PM display. \e A/AP will be replaced by either | - | ||||||||||||||||||||||||||||||
1627 | QLocale::amText() or QLocale::pmText(). | - | ||||||||||||||||||||||||||||||
1628 | \row \li ap or a | - | ||||||||||||||||||||||||||||||
1629 | \li use am/pm display. \e a/ap will be replaced by a lower-case version of | - | ||||||||||||||||||||||||||||||
1630 | QLocale::amText() or QLocale::pmText(). | - | ||||||||||||||||||||||||||||||
1631 | \row \li t \li the timezone (for example "CEST") | - | ||||||||||||||||||||||||||||||
1632 | \endtable | - | ||||||||||||||||||||||||||||||
1633 | - | |||||||||||||||||||||||||||||||
1634 | All other input characters will be ignored. Any sequence of characters that | - | ||||||||||||||||||||||||||||||
1635 | are enclosed in single quotes will be treated as text and not be used as an | - | ||||||||||||||||||||||||||||||
1636 | expression. Two consecutive single quotes ("''") are replaced by a singlequote | - | ||||||||||||||||||||||||||||||
1637 | in the output. Formats without separators (e.g. "HHmm") are currently not supported. | - | ||||||||||||||||||||||||||||||
1638 | - | |||||||||||||||||||||||||||||||
1639 | Example format strings (assuming that the QTime is 14:13:09.042 and the system | - | ||||||||||||||||||||||||||||||
1640 | locale is \c{en_US}) | - | ||||||||||||||||||||||||||||||
1641 | - | |||||||||||||||||||||||||||||||
1642 | \table | - | ||||||||||||||||||||||||||||||
1643 | \header \li Format \li Result | - | ||||||||||||||||||||||||||||||
1644 | \row \li hh:mm:ss.zzz \li 14:13:09.042 | - | ||||||||||||||||||||||||||||||
1645 | \row \li h:m:s ap \li 2:13:9 pm | - | ||||||||||||||||||||||||||||||
1646 | \row \li H:m:s a \li 14:13:9 pm | - | ||||||||||||||||||||||||||||||
1647 | \endtable | - | ||||||||||||||||||||||||||||||
1648 | - | |||||||||||||||||||||||||||||||
1649 | If the time is invalid, an empty string will be returned. | - | ||||||||||||||||||||||||||||||
1650 | If \a format is empty, the default format "hh:mm:ss" is used. | - | ||||||||||||||||||||||||||||||
1651 | - | |||||||||||||||||||||||||||||||
1652 | \sa fromString(), QDate::toString(), QDateTime::toString(), QLocale::toString() | - | ||||||||||||||||||||||||||||||
1653 | */ | - | ||||||||||||||||||||||||||||||
1654 | QString QTime::toString(const QString& format) const | - | ||||||||||||||||||||||||||||||
1655 | { | - | ||||||||||||||||||||||||||||||
1656 | return QLocale::system().toString(*this, format); executed 14062 times by 6 tests: return QLocale::system().toString(*this, format); Executed by:
| 14062 | ||||||||||||||||||||||||||||||
1657 | } | - | ||||||||||||||||||||||||||||||
1658 | #endif //QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
1659 | /*! | - | ||||||||||||||||||||||||||||||
1660 | Sets the time to hour \a h, minute \a m, seconds \a s and | - | ||||||||||||||||||||||||||||||
1661 | milliseconds \a ms. | - | ||||||||||||||||||||||||||||||
1662 | - | |||||||||||||||||||||||||||||||
1663 | \a h must be in the range 0 to 23, \a m and \a s must be in the | - | ||||||||||||||||||||||||||||||
1664 | range 0 to 59, and \a ms must be in the range 0 to 999. | - | ||||||||||||||||||||||||||||||
1665 | Returns \c true if the set time is valid; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1666 | - | |||||||||||||||||||||||||||||||
1667 | \sa isValid() | - | ||||||||||||||||||||||||||||||
1668 | */ | - | ||||||||||||||||||||||||||||||
1669 | - | |||||||||||||||||||||||||||||||
1670 | bool QTime::setHMS(int h, int m, int s, int ms) | - | ||||||||||||||||||||||||||||||
1671 | { | - | ||||||||||||||||||||||||||||||
1672 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
1673 | startTick = NullTime; | - | ||||||||||||||||||||||||||||||
1674 | #endif | - | ||||||||||||||||||||||||||||||
1675 | if (!isValid(h,m,s,ms)) {
| 246-20673661 | ||||||||||||||||||||||||||||||
1676 | mds = NullTime; // make this invalid | - | ||||||||||||||||||||||||||||||
1677 | return false; executed 246 times by 5 tests: return false; Executed by:
| 246 | ||||||||||||||||||||||||||||||
1678 | } | - | ||||||||||||||||||||||||||||||
1679 | mds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms; | - | ||||||||||||||||||||||||||||||
1680 | return true; executed 20672515 times by 103 tests: return true; Executed by:
| 20672515 | ||||||||||||||||||||||||||||||
1681 | } | - | ||||||||||||||||||||||||||||||
1682 | - | |||||||||||||||||||||||||||||||
1683 | /*! | - | ||||||||||||||||||||||||||||||
1684 | Returns a QTime object containing a time \a s seconds later | - | ||||||||||||||||||||||||||||||
1685 | than the time of this object (or earlier if \a s is negative). | - | ||||||||||||||||||||||||||||||
1686 | - | |||||||||||||||||||||||||||||||
1687 | Note that the time will wrap if it passes midnight. | - | ||||||||||||||||||||||||||||||
1688 | - | |||||||||||||||||||||||||||||||
1689 | Returns a null time if this time is invalid. | - | ||||||||||||||||||||||||||||||
1690 | - | |||||||||||||||||||||||||||||||
1691 | Example: | - | ||||||||||||||||||||||||||||||
1692 | - | |||||||||||||||||||||||||||||||
1693 | \snippet code/src_corelib_tools_qdatetime.cpp 5 | - | ||||||||||||||||||||||||||||||
1694 | - | |||||||||||||||||||||||||||||||
1695 | \sa addMSecs(), secsTo(), QDateTime::addSecs() | - | ||||||||||||||||||||||||||||||
1696 | */ | - | ||||||||||||||||||||||||||||||
1697 | - | |||||||||||||||||||||||||||||||
1698 | QTime QTime::addSecs(int s) const | - | ||||||||||||||||||||||||||||||
1699 | { | - | ||||||||||||||||||||||||||||||
1700 | s %= SECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
1701 | return addMSecs(s * 1000); executed 8 times by 3 tests: return addMSecs(s * 1000); Executed by:
| 8 | ||||||||||||||||||||||||||||||
1702 | } | - | ||||||||||||||||||||||||||||||
1703 | - | |||||||||||||||||||||||||||||||
1704 | /*! | - | ||||||||||||||||||||||||||||||
1705 | Returns the number of seconds from this time to \a t. | - | ||||||||||||||||||||||||||||||
1706 | If \a t is earlier than this time, the number of seconds returned | - | ||||||||||||||||||||||||||||||
1707 | is negative. | - | ||||||||||||||||||||||||||||||
1708 | - | |||||||||||||||||||||||||||||||
1709 | Because QTime measures time within a day and there are 86400 | - | ||||||||||||||||||||||||||||||
1710 | seconds in a day, the result is always between -86400 and 86400. | - | ||||||||||||||||||||||||||||||
1711 | - | |||||||||||||||||||||||||||||||
1712 | secsTo() does not take into account any milliseconds. | - | ||||||||||||||||||||||||||||||
1713 | - | |||||||||||||||||||||||||||||||
1714 | Returns 0 if either time is invalid. | - | ||||||||||||||||||||||||||||||
1715 | - | |||||||||||||||||||||||||||||||
1716 | \sa addSecs(), QDateTime::secsTo() | - | ||||||||||||||||||||||||||||||
1717 | */ | - | ||||||||||||||||||||||||||||||
1718 | - | |||||||||||||||||||||||||||||||
1719 | int QTime::secsTo(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1720 | { | - | ||||||||||||||||||||||||||||||
1721 | if (!isValid() || !t.isValid())
| 1-9 | ||||||||||||||||||||||||||||||
1722 | return 0; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||||||||||||||||||||
1723 | - | |||||||||||||||||||||||||||||||
1724 | // Truncate milliseconds as we do not want to consider them. | - | ||||||||||||||||||||||||||||||
1725 | int ourSeconds = ds() / 1000; | - | ||||||||||||||||||||||||||||||
1726 | int theirSeconds = t.ds() / 1000; | - | ||||||||||||||||||||||||||||||
1727 | return theirSeconds - ourSeconds; executed 8 times by 1 test: return theirSeconds - ourSeconds; Executed by:
| 8 | ||||||||||||||||||||||||||||||
1728 | } | - | ||||||||||||||||||||||||||||||
1729 | - | |||||||||||||||||||||||||||||||
1730 | /*! | - | ||||||||||||||||||||||||||||||
1731 | Returns a QTime object containing a time \a ms milliseconds later | - | ||||||||||||||||||||||||||||||
1732 | than the time of this object (or earlier if \a ms is negative). | - | ||||||||||||||||||||||||||||||
1733 | - | |||||||||||||||||||||||||||||||
1734 | Note that the time will wrap if it passes midnight. See addSecs() | - | ||||||||||||||||||||||||||||||
1735 | for an example. | - | ||||||||||||||||||||||||||||||
1736 | - | |||||||||||||||||||||||||||||||
1737 | Returns a null time if this time is invalid. | - | ||||||||||||||||||||||||||||||
1738 | - | |||||||||||||||||||||||||||||||
1739 | \sa addSecs(), msecsTo(), QDateTime::addMSecs() | - | ||||||||||||||||||||||||||||||
1740 | */ | - | ||||||||||||||||||||||||||||||
1741 | - | |||||||||||||||||||||||||||||||
1742 | QTime QTime::addMSecs(int ms) const | - | ||||||||||||||||||||||||||||||
1743 | { | - | ||||||||||||||||||||||||||||||
1744 | QTime t; | - | ||||||||||||||||||||||||||||||
1745 | if (isValid()) {
| 1-214 | ||||||||||||||||||||||||||||||
1746 | if (ms < 0) {
| 40-174 | ||||||||||||||||||||||||||||||
1747 | // %,/ not well-defined for -ve, so always work with +ve. | - | ||||||||||||||||||||||||||||||
1748 | int negdays = (MSECS_PER_DAY - ms) / MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
1749 | t.mds = (ds() + ms + negdays * MSECS_PER_DAY) % MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
1750 | } else { executed 40 times by 3 tests: end of block Executed by:
| 40 | ||||||||||||||||||||||||||||||
1751 | t.mds = (ds() + ms) % MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
1752 | } executed 174 times by 4 tests: end of block Executed by:
| 174 | ||||||||||||||||||||||||||||||
1753 | } | - | ||||||||||||||||||||||||||||||
1754 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
1755 | if (startTick > NullTime) | - | ||||||||||||||||||||||||||||||
1756 | t.startTick = (startTick + ms) % MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
1757 | #endif | - | ||||||||||||||||||||||||||||||
1758 | return t; executed 215 times by 4 tests: return t; Executed by:
| 215 | ||||||||||||||||||||||||||||||
1759 | } | - | ||||||||||||||||||||||||||||||
1760 | - | |||||||||||||||||||||||||||||||
1761 | /*! | - | ||||||||||||||||||||||||||||||
1762 | Returns the number of milliseconds from this time to \a t. | - | ||||||||||||||||||||||||||||||
1763 | If \a t is earlier than this time, the number of milliseconds returned | - | ||||||||||||||||||||||||||||||
1764 | is negative. | - | ||||||||||||||||||||||||||||||
1765 | - | |||||||||||||||||||||||||||||||
1766 | Because QTime measures time within a day and there are 86400 | - | ||||||||||||||||||||||||||||||
1767 | seconds in a day, the result is always between -86400000 and | - | ||||||||||||||||||||||||||||||
1768 | 86400000 ms. | - | ||||||||||||||||||||||||||||||
1769 | - | |||||||||||||||||||||||||||||||
1770 | Returns 0 if either time is invalid. | - | ||||||||||||||||||||||||||||||
1771 | - | |||||||||||||||||||||||||||||||
1772 | \sa secsTo(), addMSecs(), QDateTime::msecsTo() | - | ||||||||||||||||||||||||||||||
1773 | */ | - | ||||||||||||||||||||||||||||||
1774 | - | |||||||||||||||||||||||||||||||
1775 | int QTime::msecsTo(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1776 | { | - | ||||||||||||||||||||||||||||||
1777 | if (!isValid() || !t.isValid())
| 1-6848969 | ||||||||||||||||||||||||||||||
1778 | return 0; executed 6 times by 3 tests: return 0; Executed by:
| 6 | ||||||||||||||||||||||||||||||
1779 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
1780 | // GetLocalTime() for Windows CE has no milliseconds resolution | - | ||||||||||||||||||||||||||||||
1781 | if (t.startTick > NullTime && startTick > NullTime) | - | ||||||||||||||||||||||||||||||
1782 | return t.startTick - startTick; | - | ||||||||||||||||||||||||||||||
1783 | else | - | ||||||||||||||||||||||||||||||
1784 | #endif | - | ||||||||||||||||||||||||||||||
1785 | return t.ds() - ds(); executed 6850955 times by 33 tests: return t.ds() - ds(); Executed by:
| 6850955 | ||||||||||||||||||||||||||||||
1786 | } | - | ||||||||||||||||||||||||||||||
1787 | - | |||||||||||||||||||||||||||||||
1788 | - | |||||||||||||||||||||||||||||||
1789 | /*! | - | ||||||||||||||||||||||||||||||
1790 | \fn bool QTime::operator==(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1791 | - | |||||||||||||||||||||||||||||||
1792 | Returns \c true if this time is equal to \a t; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1793 | */ | - | ||||||||||||||||||||||||||||||
1794 | - | |||||||||||||||||||||||||||||||
1795 | /*! | - | ||||||||||||||||||||||||||||||
1796 | \fn bool QTime::operator!=(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1797 | - | |||||||||||||||||||||||||||||||
1798 | Returns \c true if this time is different from \a t; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1799 | */ | - | ||||||||||||||||||||||||||||||
1800 | - | |||||||||||||||||||||||||||||||
1801 | /*! | - | ||||||||||||||||||||||||||||||
1802 | \fn bool QTime::operator<(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1803 | - | |||||||||||||||||||||||||||||||
1804 | Returns \c true if this time is earlier than \a t; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1805 | */ | - | ||||||||||||||||||||||||||||||
1806 | - | |||||||||||||||||||||||||||||||
1807 | /*! | - | ||||||||||||||||||||||||||||||
1808 | \fn bool QTime::operator<=(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1809 | - | |||||||||||||||||||||||||||||||
1810 | Returns \c true if this time is earlier than or equal to \a t; | - | ||||||||||||||||||||||||||||||
1811 | otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1812 | */ | - | ||||||||||||||||||||||||||||||
1813 | - | |||||||||||||||||||||||||||||||
1814 | /*! | - | ||||||||||||||||||||||||||||||
1815 | \fn bool QTime::operator>(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1816 | - | |||||||||||||||||||||||||||||||
1817 | Returns \c true if this time is later than \a t; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1818 | */ | - | ||||||||||||||||||||||||||||||
1819 | - | |||||||||||||||||||||||||||||||
1820 | /*! | - | ||||||||||||||||||||||||||||||
1821 | \fn bool QTime::operator>=(const QTime &t) const | - | ||||||||||||||||||||||||||||||
1822 | - | |||||||||||||||||||||||||||||||
1823 | Returns \c true if this time is later than or equal to \a t; | - | ||||||||||||||||||||||||||||||
1824 | otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
1825 | */ | - | ||||||||||||||||||||||||||||||
1826 | - | |||||||||||||||||||||||||||||||
1827 | /*! | - | ||||||||||||||||||||||||||||||
1828 | \fn QTime QTime::fromMSecsSinceStartOfDay(int msecs) | - | ||||||||||||||||||||||||||||||
1829 | - | |||||||||||||||||||||||||||||||
1830 | Returns a new QTime instance with the time set to the number of \a msecs | - | ||||||||||||||||||||||||||||||
1831 | since the start of the day, i.e. since 00:00:00. | - | ||||||||||||||||||||||||||||||
1832 | - | |||||||||||||||||||||||||||||||
1833 | If \a msecs falls outside the valid range an invalid QTime will be returned. | - | ||||||||||||||||||||||||||||||
1834 | - | |||||||||||||||||||||||||||||||
1835 | \sa msecsSinceStartOfDay() | - | ||||||||||||||||||||||||||||||
1836 | */ | - | ||||||||||||||||||||||||||||||
1837 | - | |||||||||||||||||||||||||||||||
1838 | /*! | - | ||||||||||||||||||||||||||||||
1839 | \fn int QTime::msecsSinceStartOfDay() const | - | ||||||||||||||||||||||||||||||
1840 | - | |||||||||||||||||||||||||||||||
1841 | Returns the number of msecs since the start of the day, i.e. since 00:00:00. | - | ||||||||||||||||||||||||||||||
1842 | - | |||||||||||||||||||||||||||||||
1843 | \sa fromMSecsSinceStartOfDay() | - | ||||||||||||||||||||||||||||||
1844 | */ | - | ||||||||||||||||||||||||||||||
1845 | - | |||||||||||||||||||||||||||||||
1846 | /*! | - | ||||||||||||||||||||||||||||||
1847 | \fn QTime::currentTime() | - | ||||||||||||||||||||||||||||||
1848 | - | |||||||||||||||||||||||||||||||
1849 | Returns the current time as reported by the system clock. | - | ||||||||||||||||||||||||||||||
1850 | - | |||||||||||||||||||||||||||||||
1851 | Note that the accuracy depends on the accuracy of the underlying | - | ||||||||||||||||||||||||||||||
1852 | operating system; not all systems provide 1-millisecond accuracy. | - | ||||||||||||||||||||||||||||||
1853 | */ | - | ||||||||||||||||||||||||||||||
1854 | - | |||||||||||||||||||||||||||||||
1855 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
1856 | - | |||||||||||||||||||||||||||||||
1857 | static QTime fromIsoTimeString(const QStringRef &string, Qt::DateFormat format, bool *isMidnight24) | - | ||||||||||||||||||||||||||||||
1858 | { | - | ||||||||||||||||||||||||||||||
1859 | if (isMidnight24)
| 30-57 | ||||||||||||||||||||||||||||||
1860 | *isMidnight24 = false; executed 57 times by 4 tests: *isMidnight24 = false; Executed by:
| 57 | ||||||||||||||||||||||||||||||
1861 | - | |||||||||||||||||||||||||||||||
1862 | const int size = string.size(); | - | ||||||||||||||||||||||||||||||
1863 | if (size < 5)
| 1-86 | ||||||||||||||||||||||||||||||
1864 | return QTime(); executed 1 time by 1 test: return QTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1865 | - | |||||||||||||||||||||||||||||||
1866 | bool ok = false; | - | ||||||||||||||||||||||||||||||
1867 | int hour = string.mid(0, 2).toInt(&ok); | - | ||||||||||||||||||||||||||||||
1868 | if (!ok)
| 1-85 | ||||||||||||||||||||||||||||||
1869 | return QTime(); executed 1 time by 1 test: return QTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1870 | const int minute = string.mid(3, 2).toInt(&ok); | - | ||||||||||||||||||||||||||||||
1871 | if (!ok)
| 2-83 | ||||||||||||||||||||||||||||||
1872 | return QTime(); executed 2 times by 1 test: return QTime(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1873 | int second = 0; | - | ||||||||||||||||||||||||||||||
1874 | int msec = 0; | - | ||||||||||||||||||||||||||||||
1875 | - | |||||||||||||||||||||||||||||||
1876 | if (size == 5) {
| 6-77 | ||||||||||||||||||||||||||||||
1877 | // HH:mm format | - | ||||||||||||||||||||||||||||||
1878 | second = 0; | - | ||||||||||||||||||||||||||||||
1879 | msec = 0; | - | ||||||||||||||||||||||||||||||
1880 | } else if (string.at(5) == QLatin1Char(',') || string.at(5) == QLatin1Char('.')) { executed 6 times by 1 test: end of block Executed by:
| 4-72 | ||||||||||||||||||||||||||||||
1881 | if (format == Qt::TextDate)
| 1-8 | ||||||||||||||||||||||||||||||
1882 | return QTime(); executed 1 time by 1 test: return QTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1883 | // ISODate HH:mm.ssssss format | - | ||||||||||||||||||||||||||||||
1884 | // We only want 5 digits worth of fraction of minute. This follows the existing | - | ||||||||||||||||||||||||||||||
1885 | // behavior that determines how milliseconds are read; 4 millisecond digits are | - | ||||||||||||||||||||||||||||||
1886 | // read and then rounded to 3. If we read at most 5 digits for fraction of minute, | - | ||||||||||||||||||||||||||||||
1887 | // the maximum amount of millisecond digits it will expand to once converted to | - | ||||||||||||||||||||||||||||||
1888 | // seconds is 4. E.g. 12:34,99999 will expand to 12:34:59.9994. The milliseconds | - | ||||||||||||||||||||||||||||||
1889 | // will then be rounded up AND clamped to 999. | - | ||||||||||||||||||||||||||||||
1890 | - | |||||||||||||||||||||||||||||||
1891 | const QStringRef minuteFractionStr = string.mid(6, 5); | - | ||||||||||||||||||||||||||||||
1892 | const long minuteFractionInt = minuteFractionStr.toLong(&ok); | - | ||||||||||||||||||||||||||||||
1893 | if (!ok)
| 1-7 | ||||||||||||||||||||||||||||||
1894 | return QTime(); executed 1 time by 1 test: return QTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
1895 | const float minuteFraction = double(minuteFractionInt) / (std::pow(double(10), minuteFractionStr.count())); | - | ||||||||||||||||||||||||||||||
1896 | - | |||||||||||||||||||||||||||||||
1897 | const float secondWithMs = minuteFraction * 60; | - | ||||||||||||||||||||||||||||||
1898 | const float secondNoMs = std::floor(secondWithMs); | - | ||||||||||||||||||||||||||||||
1899 | const float secondFraction = secondWithMs - secondNoMs; | - | ||||||||||||||||||||||||||||||
1900 | second = secondNoMs; | - | ||||||||||||||||||||||||||||||
1901 | msec = qMin(qRound(secondFraction * 1000.0), 999); | - | ||||||||||||||||||||||||||||||
1902 | } else { executed 7 times by 2 tests: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||
1903 | // HH:mm:ss or HH:mm:ss.zzz | - | ||||||||||||||||||||||||||||||
1904 | second = string.mid(6, 2).toInt(&ok); | - | ||||||||||||||||||||||||||||||
1905 | if (!ok)
| 2-66 | ||||||||||||||||||||||||||||||
1906 | return QTime(); executed 2 times by 1 test: return QTime(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1907 | if (size > 8 && (string.at(8) == QLatin1Char(',') || string.at(8) == QLatin1Char('.'))) {
| 3-34 | ||||||||||||||||||||||||||||||
1908 | const QStringRef msecStr(string.mid(9, 4)); | - | ||||||||||||||||||||||||||||||
1909 | int msecInt = msecStr.isEmpty() ? 0 : msecStr.toInt(&ok);
| 1-28 | ||||||||||||||||||||||||||||||
1910 | if (!ok)
| 0-29 | ||||||||||||||||||||||||||||||
1911 | return QTime(); never executed: return QTime(); | 0 | ||||||||||||||||||||||||||||||
1912 | const double secondFraction(msecInt / (std::pow(double(10), msecStr.count()))); | - | ||||||||||||||||||||||||||||||
1913 | msec = qMin(qRound(secondFraction * 1000.0), 999); | - | ||||||||||||||||||||||||||||||
1914 | } executed 29 times by 3 tests: end of block Executed by:
| 29 | ||||||||||||||||||||||||||||||
1915 | } executed 66 times by 5 tests: end of block Executed by:
| 66 | ||||||||||||||||||||||||||||||
1916 | - | |||||||||||||||||||||||||||||||
1917 | if (format == Qt::ISODate && hour == 24 && minute == 0 && second == 0 && msec == 0) {
| 0-72 | ||||||||||||||||||||||||||||||
1918 | if (isMidnight24)
| 2-5 | ||||||||||||||||||||||||||||||
1919 | *isMidnight24 = true; executed 5 times by 1 test: *isMidnight24 = true; Executed by:
| 5 | ||||||||||||||||||||||||||||||
1920 | hour = 0; | - | ||||||||||||||||||||||||||||||
1921 | } executed 7 times by 2 tests: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||
1922 | - | |||||||||||||||||||||||||||||||
1923 | return QTime(hour, minute, second, msec); executed 79 times by 5 tests: return QTime(hour, minute, second, msec); Executed by:
| 79 | ||||||||||||||||||||||||||||||
1924 | } | - | ||||||||||||||||||||||||||||||
1925 | - | |||||||||||||||||||||||||||||||
1926 | /*! | - | ||||||||||||||||||||||||||||||
1927 | \fn QTime QTime::fromString(const QString &string, Qt::DateFormat format) | - | ||||||||||||||||||||||||||||||
1928 | - | |||||||||||||||||||||||||||||||
1929 | Returns the time represented in the \a string as a QTime using the | - | ||||||||||||||||||||||||||||||
1930 | \a format given, or an invalid time if this is not possible. | - | ||||||||||||||||||||||||||||||
1931 | - | |||||||||||||||||||||||||||||||
1932 | Note that fromString() uses a "C" locale encoded string to convert | - | ||||||||||||||||||||||||||||||
1933 | milliseconds to a float value. If the default locale is not "C", | - | ||||||||||||||||||||||||||||||
1934 | this may result in two conversion attempts (if the conversion | - | ||||||||||||||||||||||||||||||
1935 | fails for the default locale). This should be considered an | - | ||||||||||||||||||||||||||||||
1936 | implementation detail. | - | ||||||||||||||||||||||||||||||
1937 | - | |||||||||||||||||||||||||||||||
1938 | \sa toString(), QLocale::toTime() | - | ||||||||||||||||||||||||||||||
1939 | */ | - | ||||||||||||||||||||||||||||||
1940 | QTime QTime::fromString(const QString& string, Qt::DateFormat format) | - | ||||||||||||||||||||||||||||||
1941 | { | - | ||||||||||||||||||||||||||||||
1942 | if (string.isEmpty())
| 2-50 | ||||||||||||||||||||||||||||||
1943 | return QTime(); executed 2 times by 1 test: return QTime(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
1944 | - | |||||||||||||||||||||||||||||||
1945 | switch (format) { | - | ||||||||||||||||||||||||||||||
1946 | case Qt::SystemLocaleDate: never executed: case Qt::SystemLocaleDate: | 0 | ||||||||||||||||||||||||||||||
1947 | case Qt::SystemLocaleShortDate: never executed: case Qt::SystemLocaleShortDate: | 0 | ||||||||||||||||||||||||||||||
1948 | return QLocale::system().toTime(string, QLocale::ShortFormat); never executed: return QLocale::system().toTime(string, QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||||||||
1949 | case Qt::SystemLocaleLongDate: never executed: case Qt::SystemLocaleLongDate: | 0 | ||||||||||||||||||||||||||||||
1950 | return QLocale::system().toTime(string, QLocale::LongFormat); never executed: return QLocale::system().toTime(string, QLocale::LongFormat); | 0 | ||||||||||||||||||||||||||||||
1951 | case Qt::LocaleDate: never executed: case Qt::LocaleDate: | 0 | ||||||||||||||||||||||||||||||
1952 | case Qt::DefaultLocaleShortDate: never executed: case Qt::DefaultLocaleShortDate: | 0 | ||||||||||||||||||||||||||||||
1953 | return QLocale().toTime(string, QLocale::ShortFormat); never executed: return QLocale().toTime(string, QLocale::ShortFormat); | 0 | ||||||||||||||||||||||||||||||
1954 | case Qt::DefaultLocaleLongDate: never executed: case Qt::DefaultLocaleLongDate: | 0 | ||||||||||||||||||||||||||||||
1955 | return QLocale().toTime(string, QLocale::LongFormat); never executed: return QLocale().toTime(string, QLocale::LongFormat); | 0 | ||||||||||||||||||||||||||||||
1956 | case Qt::RFC2822Date: executed 20 times by 1 test: case Qt::RFC2822Date: Executed by:
| 20 | ||||||||||||||||||||||||||||||
1957 | return rfcDateImpl(string).time; executed 20 times by 1 test: return rfcDateImpl(string).time; Executed by:
| 20 | ||||||||||||||||||||||||||||||
1958 | case Qt::ISODate: executed 20 times by 2 tests: case Qt::ISODate: Executed by:
| 20 | ||||||||||||||||||||||||||||||
1959 | case Qt::TextDate: executed 10 times by 1 test: case Qt::TextDate: Executed by:
| 10 | ||||||||||||||||||||||||||||||
1960 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
1961 | return fromIsoTimeString(&string, format, 0); executed 30 times by 2 tests: return fromIsoTimeString(&string, format, 0); Executed by:
| 30 | ||||||||||||||||||||||||||||||
1962 | } | - | ||||||||||||||||||||||||||||||
1963 | } | - | ||||||||||||||||||||||||||||||
1964 | - | |||||||||||||||||||||||||||||||
1965 | /*! | - | ||||||||||||||||||||||||||||||
1966 | \fn QTime::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||||||||
1967 | - | |||||||||||||||||||||||||||||||
1968 | Returns the QTime represented by the \a string, using the \a | - | ||||||||||||||||||||||||||||||
1969 | format given, or an invalid time if the string cannot be parsed. | - | ||||||||||||||||||||||||||||||
1970 | - | |||||||||||||||||||||||||||||||
1971 | These expressions may be used for the format: | - | ||||||||||||||||||||||||||||||
1972 | - | |||||||||||||||||||||||||||||||
1973 | \table | - | ||||||||||||||||||||||||||||||
1974 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
1975 | \row \li h | - | ||||||||||||||||||||||||||||||
1976 | \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
1977 | \row \li hh | - | ||||||||||||||||||||||||||||||
1978 | \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
1979 | \row \li m \li the minute without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
1980 | \row \li mm \li the minute with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
1981 | \row \li s \li the second without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
1982 | \row \li ss \li the second with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
1983 | \row \li z \li the milliseconds without leading zeroes (0 to 999) | - | ||||||||||||||||||||||||||||||
1984 | \row \li zzz \li the milliseconds with leading zeroes (000 to 999) | - | ||||||||||||||||||||||||||||||
1985 | \row \li AP | - | ||||||||||||||||||||||||||||||
1986 | \li interpret as an AM/PM time. \e AP must be either "AM" or "PM". | - | ||||||||||||||||||||||||||||||
1987 | \row \li ap | - | ||||||||||||||||||||||||||||||
1988 | \li Interpret as an AM/PM time. \e ap must be either "am" or "pm". | - | ||||||||||||||||||||||||||||||
1989 | \endtable | - | ||||||||||||||||||||||||||||||
1990 | - | |||||||||||||||||||||||||||||||
1991 | All other input characters will be treated as text. Any sequence | - | ||||||||||||||||||||||||||||||
1992 | of characters that are enclosed in single quotes will also be | - | ||||||||||||||||||||||||||||||
1993 | treated as text and not be used as an expression. | - | ||||||||||||||||||||||||||||||
1994 | - | |||||||||||||||||||||||||||||||
1995 | \snippet code/src_corelib_tools_qdatetime.cpp 6 | - | ||||||||||||||||||||||||||||||
1996 | - | |||||||||||||||||||||||||||||||
1997 | If the format is not satisfied, an invalid QTime is returned. | - | ||||||||||||||||||||||||||||||
1998 | Expressions that do not expect leading zeroes to be given (h, m, s | - | ||||||||||||||||||||||||||||||
1999 | and z) are greedy. This means that they will use two digits even if | - | ||||||||||||||||||||||||||||||
2000 | this puts them outside the range of accepted values and leaves too | - | ||||||||||||||||||||||||||||||
2001 | few digits for other sections. For example, the following string | - | ||||||||||||||||||||||||||||||
2002 | could have meant 00:07:10, but the m will grab two digits, resulting | - | ||||||||||||||||||||||||||||||
2003 | in an invalid time: | - | ||||||||||||||||||||||||||||||
2004 | - | |||||||||||||||||||||||||||||||
2005 | \snippet code/src_corelib_tools_qdatetime.cpp 7 | - | ||||||||||||||||||||||||||||||
2006 | - | |||||||||||||||||||||||||||||||
2007 | Any field that is not represented in the format will be set to zero. | - | ||||||||||||||||||||||||||||||
2008 | For example: | - | ||||||||||||||||||||||||||||||
2009 | - | |||||||||||||||||||||||||||||||
2010 | \snippet code/src_corelib_tools_qdatetime.cpp 8 | - | ||||||||||||||||||||||||||||||
2011 | - | |||||||||||||||||||||||||||||||
2012 | \sa toString(), QDateTime::fromString(), QDate::fromString(), | - | ||||||||||||||||||||||||||||||
2013 | QLocale::toTime() | - | ||||||||||||||||||||||||||||||
2014 | */ | - | ||||||||||||||||||||||||||||||
2015 | - | |||||||||||||||||||||||||||||||
2016 | QTime QTime::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||||||||
2017 | { | - | ||||||||||||||||||||||||||||||
2018 | QTime time; | - | ||||||||||||||||||||||||||||||
2019 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2020 | QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||||||||
2021 | if (dt.parseFormat(format))
| 0-12 | ||||||||||||||||||||||||||||||
2022 | dt.fromString(string, 0, &time); executed 12 times by 1 test: dt.fromString(string, 0, &time); Executed by:
| 12 | ||||||||||||||||||||||||||||||
2023 | #else | - | ||||||||||||||||||||||||||||||
2024 | Q_UNUSED(string); | - | ||||||||||||||||||||||||||||||
2025 | Q_UNUSED(format); | - | ||||||||||||||||||||||||||||||
2026 | #endif | - | ||||||||||||||||||||||||||||||
2027 | return time; executed 12 times by 1 test: return time; Executed by:
| 12 | ||||||||||||||||||||||||||||||
2028 | } | - | ||||||||||||||||||||||||||||||
2029 | - | |||||||||||||||||||||||||||||||
2030 | #endif // QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
2031 | - | |||||||||||||||||||||||||||||||
2032 | - | |||||||||||||||||||||||||||||||
2033 | /*! | - | ||||||||||||||||||||||||||||||
2034 | \overload | - | ||||||||||||||||||||||||||||||
2035 | - | |||||||||||||||||||||||||||||||
2036 | Returns \c true if the specified time is valid; otherwise returns | - | ||||||||||||||||||||||||||||||
2037 | false. | - | ||||||||||||||||||||||||||||||
2038 | - | |||||||||||||||||||||||||||||||
2039 | The time is valid if \a h is in the range 0 to 23, \a m and | - | ||||||||||||||||||||||||||||||
2040 | \a s are in the range 0 to 59, and \a ms is in the range 0 to 999. | - | ||||||||||||||||||||||||||||||
2041 | - | |||||||||||||||||||||||||||||||
2042 | Example: | - | ||||||||||||||||||||||||||||||
2043 | - | |||||||||||||||||||||||||||||||
2044 | \snippet code/src_corelib_tools_qdatetime.cpp 9 | - | ||||||||||||||||||||||||||||||
2045 | */ | - | ||||||||||||||||||||||||||||||
2046 | - | |||||||||||||||||||||||||||||||
2047 | bool QTime::isValid(int h, int m, int s, int ms) | - | ||||||||||||||||||||||||||||||
2048 | { | - | ||||||||||||||||||||||||||||||
2049 | return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; executed 20663406 times by 103 tests: return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; Executed by:
| 1-20679629 | ||||||||||||||||||||||||||||||
2050 | } | - | ||||||||||||||||||||||||||||||
2051 | - | |||||||||||||||||||||||||||||||
2052 | - | |||||||||||||||||||||||||||||||
2053 | /*! | - | ||||||||||||||||||||||||||||||
2054 | Sets this time to the current time. This is practical for timing: | - | ||||||||||||||||||||||||||||||
2055 | - | |||||||||||||||||||||||||||||||
2056 | \snippet code/src_corelib_tools_qdatetime.cpp 10 | - | ||||||||||||||||||||||||||||||
2057 | - | |||||||||||||||||||||||||||||||
2058 | \sa restart(), elapsed(), currentTime() | - | ||||||||||||||||||||||||||||||
2059 | */ | - | ||||||||||||||||||||||||||||||
2060 | - | |||||||||||||||||||||||||||||||
2061 | void QTime::start() | - | ||||||||||||||||||||||||||||||
2062 | { | - | ||||||||||||||||||||||||||||||
2063 | *this = currentTime(); | - | ||||||||||||||||||||||||||||||
2064 | } executed 677 times by 28 tests: end of block Executed by:
| 677 | ||||||||||||||||||||||||||||||
2065 | - | |||||||||||||||||||||||||||||||
2066 | /*! | - | ||||||||||||||||||||||||||||||
2067 | Sets this time to the current time and returns the number of | - | ||||||||||||||||||||||||||||||
2068 | milliseconds that have elapsed since the last time start() or | - | ||||||||||||||||||||||||||||||
2069 | restart() was called. | - | ||||||||||||||||||||||||||||||
2070 | - | |||||||||||||||||||||||||||||||
2071 | This function is guaranteed to be atomic and is thus very handy | - | ||||||||||||||||||||||||||||||
2072 | for repeated measurements. Call start() to start the first | - | ||||||||||||||||||||||||||||||
2073 | measurement, and restart() for each later measurement. | - | ||||||||||||||||||||||||||||||
2074 | - | |||||||||||||||||||||||||||||||
2075 | Note that the counter wraps to zero 24 hours after the last call | - | ||||||||||||||||||||||||||||||
2076 | to start() or restart(). | - | ||||||||||||||||||||||||||||||
2077 | - | |||||||||||||||||||||||||||||||
2078 | \warning If the system's clock setting has been changed since the | - | ||||||||||||||||||||||||||||||
2079 | last time start() or restart() was called, the result is | - | ||||||||||||||||||||||||||||||
2080 | undefined. This can happen when daylight-saving time is turned on | - | ||||||||||||||||||||||||||||||
2081 | or off. | - | ||||||||||||||||||||||||||||||
2082 | - | |||||||||||||||||||||||||||||||
2083 | \sa start(), elapsed(), currentTime() | - | ||||||||||||||||||||||||||||||
2084 | */ | - | ||||||||||||||||||||||||||||||
2085 | - | |||||||||||||||||||||||||||||||
2086 | int QTime::restart() | - | ||||||||||||||||||||||||||||||
2087 | { | - | ||||||||||||||||||||||||||||||
2088 | QTime t = currentTime(); | - | ||||||||||||||||||||||||||||||
2089 | int n = msecsTo(t); | - | ||||||||||||||||||||||||||||||
2090 | if (n < 0) // passed midnight
| 0-211 | ||||||||||||||||||||||||||||||
2091 | n += 86400*1000; never executed: n += 86400*1000; | 0 | ||||||||||||||||||||||||||||||
2092 | *this = t; | - | ||||||||||||||||||||||||||||||
2093 | return n; executed 211 times by 3 tests: return n; Executed by:
| 211 | ||||||||||||||||||||||||||||||
2094 | } | - | ||||||||||||||||||||||||||||||
2095 | - | |||||||||||||||||||||||||||||||
2096 | /*! | - | ||||||||||||||||||||||||||||||
2097 | Returns the number of milliseconds that have elapsed since the | - | ||||||||||||||||||||||||||||||
2098 | last time start() or restart() was called. | - | ||||||||||||||||||||||||||||||
2099 | - | |||||||||||||||||||||||||||||||
2100 | Note that the counter wraps to zero 24 hours after the last call | - | ||||||||||||||||||||||||||||||
2101 | to start() or restart. | - | ||||||||||||||||||||||||||||||
2102 | - | |||||||||||||||||||||||||||||||
2103 | Note that the accuracy depends on the accuracy of the underlying | - | ||||||||||||||||||||||||||||||
2104 | operating system; not all systems provide 1-millisecond accuracy. | - | ||||||||||||||||||||||||||||||
2105 | - | |||||||||||||||||||||||||||||||
2106 | \warning If the system's clock setting has been changed since the | - | ||||||||||||||||||||||||||||||
2107 | last time start() or restart() was called, the result is | - | ||||||||||||||||||||||||||||||
2108 | undefined. This can happen when daylight-saving time is turned on | - | ||||||||||||||||||||||||||||||
2109 | or off. | - | ||||||||||||||||||||||||||||||
2110 | - | |||||||||||||||||||||||||||||||
2111 | \sa start(), restart() | - | ||||||||||||||||||||||||||||||
2112 | */ | - | ||||||||||||||||||||||||||||||
2113 | - | |||||||||||||||||||||||||||||||
2114 | int QTime::elapsed() const | - | ||||||||||||||||||||||||||||||
2115 | { | - | ||||||||||||||||||||||||||||||
2116 | int n = msecsTo(currentTime()); | - | ||||||||||||||||||||||||||||||
2117 | if (n < 0) // passed midnight
| 0-6850675 | ||||||||||||||||||||||||||||||
2118 | n += 86400 * 1000; never executed: n += 86400 * 1000; | 0 | ||||||||||||||||||||||||||||||
2119 | return n; executed 6850675 times by 28 tests: return n; Executed by:
| 6850675 | ||||||||||||||||||||||||||||||
2120 | } | - | ||||||||||||||||||||||||||||||
2121 | - | |||||||||||||||||||||||||||||||
2122 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
2123 | QDateTime static helper functions | - | ||||||||||||||||||||||||||||||
2124 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
2125 | - | |||||||||||||||||||||||||||||||
2126 | // Calls the platform variant of tzset | - | ||||||||||||||||||||||||||||||
2127 | static void qt_tzset() | - | ||||||||||||||||||||||||||||||
2128 | { | - | ||||||||||||||||||||||||||||||
2129 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
2130 | // WinCE doesn't use tzset | - | ||||||||||||||||||||||||||||||
2131 | return; | - | ||||||||||||||||||||||||||||||
2132 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||||||||||||||
2133 | _tzset(); | - | ||||||||||||||||||||||||||||||
2134 | #else | - | ||||||||||||||||||||||||||||||
2135 | tzset(); | - | ||||||||||||||||||||||||||||||
2136 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||||||||
2137 | } executed 6864044 times by 94 tests: end of block Executed by:
| 6864044 | ||||||||||||||||||||||||||||||
2138 | - | |||||||||||||||||||||||||||||||
2139 | // Returns the platform variant of timezone, i.e. the standard time offset | - | ||||||||||||||||||||||||||||||
2140 | // The timezone external variable is documented as always holding the | - | ||||||||||||||||||||||||||||||
2141 | // Standard Time offset as seconds west of Greenwich, i.e. UTC+01:00 is -3600 | - | ||||||||||||||||||||||||||||||
2142 | // Note this may not be historicaly accurate. | - | ||||||||||||||||||||||||||||||
2143 | // Relies on tzset, mktime, or localtime having been called to populate timezone | - | ||||||||||||||||||||||||||||||
2144 | static int qt_timezone() | - | ||||||||||||||||||||||||||||||
2145 | { | - | ||||||||||||||||||||||||||||||
2146 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
2147 | TIME_ZONE_INFORMATION tzi; | - | ||||||||||||||||||||||||||||||
2148 | GetTimeZoneInformation(&tzi); | - | ||||||||||||||||||||||||||||||
2149 | // Expressed in minutes, convert to seconds | - | ||||||||||||||||||||||||||||||
2150 | return (tzi.Bias + tzi.StandardBias) * 60; | - | ||||||||||||||||||||||||||||||
2151 | #elif defined(_MSC_VER) && _MSC_VER >= 1400 | - | ||||||||||||||||||||||||||||||
2152 | long offset; | - | ||||||||||||||||||||||||||||||
2153 | _get_timezone(&offset); | - | ||||||||||||||||||||||||||||||
2154 | return offset; | - | ||||||||||||||||||||||||||||||
2155 | #elif defined(Q_OS_BSD4) && !defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||||||||
2156 | time_t clock = time(NULL); | - | ||||||||||||||||||||||||||||||
2157 | struct tm t; | - | ||||||||||||||||||||||||||||||
2158 | localtime_r(&clock, &t); | - | ||||||||||||||||||||||||||||||
2159 | // QTBUG-36080 Workaround for systems without the POSIX timezone | - | ||||||||||||||||||||||||||||||
2160 | // variable. This solution is not very efficient but fixing it is up to | - | ||||||||||||||||||||||||||||||
2161 | // the libc implementations. | - | ||||||||||||||||||||||||||||||
2162 | // | - | ||||||||||||||||||||||||||||||
2163 | // tm_gmtoff has some important differences compared to the timezone | - | ||||||||||||||||||||||||||||||
2164 | // variable: | - | ||||||||||||||||||||||||||||||
2165 | // - It returns the number of seconds east of UTC, and we want the | - | ||||||||||||||||||||||||||||||
2166 | // number of seconds west of UTC. | - | ||||||||||||||||||||||||||||||
2167 | // - It also takes DST into account, so we need to adjust it to always | - | ||||||||||||||||||||||||||||||
2168 | // get the Standard Time offset. | - | ||||||||||||||||||||||||||||||
2169 | return -t.tm_gmtoff + (t.tm_isdst ? (long)SECS_PER_HOUR : 0L); | - | ||||||||||||||||||||||||||||||
2170 | #else | - | ||||||||||||||||||||||||||||||
2171 | return timezone; executed 7040 times by 16 tests: return timezone; Executed by:
| 7040 | ||||||||||||||||||||||||||||||
2172 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||||||||
2173 | } | - | ||||||||||||||||||||||||||||||
2174 | - | |||||||||||||||||||||||||||||||
2175 | // Returns the tzname, assume tzset has been called already | - | ||||||||||||||||||||||||||||||
2176 | static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus) | - | ||||||||||||||||||||||||||||||
2177 | { | - | ||||||||||||||||||||||||||||||
2178 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
2179 | TIME_ZONE_INFORMATION tzi; | - | ||||||||||||||||||||||||||||||
2180 | DWORD res = GetTimeZoneInformation(&tzi); | - | ||||||||||||||||||||||||||||||
2181 | if (res == TIME_ZONE_ID_UNKNOWN) | - | ||||||||||||||||||||||||||||||
2182 | return QString(); | - | ||||||||||||||||||||||||||||||
2183 | else if (daylightStatus == QDateTimePrivate::DaylightTime) | - | ||||||||||||||||||||||||||||||
2184 | return QString::fromWCharArray(tzi.DaylightName); | - | ||||||||||||||||||||||||||||||
2185 | else | - | ||||||||||||||||||||||||||||||
2186 | return QString::fromWCharArray(tzi.StandardName); | - | ||||||||||||||||||||||||||||||
2187 | #else | - | ||||||||||||||||||||||||||||||
2188 | int isDst = (daylightStatus == QDateTimePrivate::DaylightTime) ? 1 : 0;
| 248-891 | ||||||||||||||||||||||||||||||
2189 | #if defined(_MSC_VER) && _MSC_VER >= 1400 | - | ||||||||||||||||||||||||||||||
2190 | size_t s = 0; | - | ||||||||||||||||||||||||||||||
2191 | char name[512]; | - | ||||||||||||||||||||||||||||||
2192 | if (_get_tzname(&s, name, 512, isDst)) | - | ||||||||||||||||||||||||||||||
2193 | return QString(); | - | ||||||||||||||||||||||||||||||
2194 | return QString::fromLocal8Bit(name); | - | ||||||||||||||||||||||||||||||
2195 | #else | - | ||||||||||||||||||||||||||||||
2196 | return QString::fromLocal8Bit(tzname[isDst]); executed 1139 times by 12 tests: return QString::fromLocal8Bit(tzname[isDst]); Executed by:
| 1139 | ||||||||||||||||||||||||||||||
2197 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||||||||
2198 | #endif // Q_OS_WINCE | - | ||||||||||||||||||||||||||||||
2199 | } | - | ||||||||||||||||||||||||||||||
2200 | - | |||||||||||||||||||||||||||||||
2201 | // Calls the platform variant of mktime for the given date, time and daylightStatus, | - | ||||||||||||||||||||||||||||||
2202 | // and updates the date, time, daylightStatus and abbreviation with the returned values | - | ||||||||||||||||||||||||||||||
2203 | // If the date falls outside the 1970 to 2037 range supported by mktime / time_t | - | ||||||||||||||||||||||||||||||
2204 | // then null date/time will be returned, you should adjust the date first if | - | ||||||||||||||||||||||||||||||
2205 | // you need a guaranteed result. | - | ||||||||||||||||||||||||||||||
2206 | static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStatus *daylightStatus, | - | ||||||||||||||||||||||||||||||
2207 | QString *abbreviation, bool *ok = 0) | - | ||||||||||||||||||||||||||||||
2208 | { | - | ||||||||||||||||||||||||||||||
2209 | const qint64 msec = time->msec(); | - | ||||||||||||||||||||||||||||||
2210 | int yy, mm, dd; | - | ||||||||||||||||||||||||||||||
2211 | date->getDate(&yy, &mm, &dd); | - | ||||||||||||||||||||||||||||||
2212 | - | |||||||||||||||||||||||||||||||
2213 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
2214 | // WinCE doesn't provide standard C library time functions | - | ||||||||||||||||||||||||||||||
2215 | SYSTEMTIME st; | - | ||||||||||||||||||||||||||||||
2216 | memset(&st, 0, sizeof(SYSTEMTIME)); | - | ||||||||||||||||||||||||||||||
2217 | st.wSecond = time->second(); | - | ||||||||||||||||||||||||||||||
2218 | st.wMinute = time->minute(); | - | ||||||||||||||||||||||||||||||
2219 | st.wHour = time->hour(); | - | ||||||||||||||||||||||||||||||
2220 | st.wDay = dd; | - | ||||||||||||||||||||||||||||||
2221 | st.wMonth = mm; | - | ||||||||||||||||||||||||||||||
2222 | st.wYear = yy; | - | ||||||||||||||||||||||||||||||
2223 | FILETIME lft; | - | ||||||||||||||||||||||||||||||
2224 | bool valid = SystemTimeToFileTime(&st, &lft); | - | ||||||||||||||||||||||||||||||
2225 | FILETIME ft; | - | ||||||||||||||||||||||||||||||
2226 | if (valid) | - | ||||||||||||||||||||||||||||||
2227 | valid = LocalFileTimeToFileTime(&lft, &ft); | - | ||||||||||||||||||||||||||||||
2228 | const time_t secsSinceEpoch = ftToTime_t(ft); | - | ||||||||||||||||||||||||||||||
2229 | const time_t localSecs = ftToTime_t(lft); | - | ||||||||||||||||||||||||||||||
2230 | TIME_ZONE_INFORMATION tzi; | - | ||||||||||||||||||||||||||||||
2231 | GetTimeZoneInformation(&tzi); | - | ||||||||||||||||||||||||||||||
2232 | bool isDaylight = false; | - | ||||||||||||||||||||||||||||||
2233 | // Check for overflow | - | ||||||||||||||||||||||||||||||
2234 | qint64 localDiff = qAbs(localSecs - secsSinceEpoch); | - | ||||||||||||||||||||||||||||||
2235 | int daylightOffset = qAbs(tzi.Bias + tzi.DaylightBias) * 60; | - | ||||||||||||||||||||||||||||||
2236 | if (localDiff > daylightOffset) | - | ||||||||||||||||||||||||||||||
2237 | valid = false; | - | ||||||||||||||||||||||||||||||
2238 | else | - | ||||||||||||||||||||||||||||||
2239 | isDaylight = (localDiff == daylightOffset); | - | ||||||||||||||||||||||||||||||
2240 | if (daylightStatus) { | - | ||||||||||||||||||||||||||||||
2241 | if (isDaylight) | - | ||||||||||||||||||||||||||||||
2242 | *daylightStatus = QDateTimePrivate::DaylightTime; | - | ||||||||||||||||||||||||||||||
2243 | else | - | ||||||||||||||||||||||||||||||
2244 | *daylightStatus = QDateTimePrivate::StandardTime; | - | ||||||||||||||||||||||||||||||
2245 | } | - | ||||||||||||||||||||||||||||||
2246 | if (abbreviation) { | - | ||||||||||||||||||||||||||||||
2247 | if (isDaylight) | - | ||||||||||||||||||||||||||||||
2248 | *abbreviation = QString::fromWCharArray(tzi.DaylightName); | - | ||||||||||||||||||||||||||||||
2249 | else | - | ||||||||||||||||||||||||||||||
2250 | *abbreviation = QString::fromWCharArray(tzi.StandardName); | - | ||||||||||||||||||||||||||||||
2251 | } | - | ||||||||||||||||||||||||||||||
2252 | if (ok) | - | ||||||||||||||||||||||||||||||
2253 | *ok = valid; | - | ||||||||||||||||||||||||||||||
2254 | #else | - | ||||||||||||||||||||||||||||||
2255 | // All other platforms provide standard C library time functions | - | ||||||||||||||||||||||||||||||
2256 | tm local; | - | ||||||||||||||||||||||||||||||
2257 | memset(&local, 0, sizeof(local)); // tm_[wy]day plus any non-standard fields | - | ||||||||||||||||||||||||||||||
2258 | local.tm_sec = time->second(); | - | ||||||||||||||||||||||||||||||
2259 | local.tm_min = time->minute(); | - | ||||||||||||||||||||||||||||||
2260 | local.tm_hour = time->hour(); | - | ||||||||||||||||||||||||||||||
2261 | local.tm_mday = dd; | - | ||||||||||||||||||||||||||||||
2262 | local.tm_mon = mm - 1; | - | ||||||||||||||||||||||||||||||
2263 | local.tm_year = yy - 1900; | - | ||||||||||||||||||||||||||||||
2264 | if (daylightStatus)
| 0-13748163 | ||||||||||||||||||||||||||||||
2265 | local.tm_isdst = int(*daylightStatus); executed 13748163 times by 97 tests: local.tm_isdst = int(*daylightStatus); Executed by:
| 13748163 | ||||||||||||||||||||||||||||||
2266 | else | - | ||||||||||||||||||||||||||||||
2267 | local.tm_isdst = -1; never executed: local.tm_isdst = -1; | 0 | ||||||||||||||||||||||||||||||
2268 | - | |||||||||||||||||||||||||||||||
2269 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||||||||
2270 | int hh = local.tm_hour; | - | ||||||||||||||||||||||||||||||
2271 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||||||||
2272 | time_t secsSinceEpoch = mktime(&local); | - | ||||||||||||||||||||||||||||||
2273 | if (secsSinceEpoch != time_t(-1)) {
| 36-13740582 | ||||||||||||||||||||||||||||||
2274 | *date = QDate(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday); | - | ||||||||||||||||||||||||||||||
2275 | *time = QTime(local.tm_hour, local.tm_min, local.tm_sec, msec); | - | ||||||||||||||||||||||||||||||
2276 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||||||||
2277 | // Windows mktime for the missing hour subtracts 1 hour from the time | - | ||||||||||||||||||||||||||||||
2278 | // instead of adding 1 hour. If time differs and is standard time then | - | ||||||||||||||||||||||||||||||
2279 | // this has happened, so add 2 hours to the time and 1 hour to the msecs | - | ||||||||||||||||||||||||||||||
2280 | if (local.tm_isdst == 0 && local.tm_hour != hh) { | - | ||||||||||||||||||||||||||||||
2281 | if (time->hour() >= 22) | - | ||||||||||||||||||||||||||||||
2282 | *date = date->addDays(1); | - | ||||||||||||||||||||||||||||||
2283 | *time = time->addSecs(2 * SECS_PER_HOUR); | - | ||||||||||||||||||||||||||||||
2284 | secsSinceEpoch += SECS_PER_HOUR; | - | ||||||||||||||||||||||||||||||
2285 | local.tm_isdst = 1; | - | ||||||||||||||||||||||||||||||
2286 | } | - | ||||||||||||||||||||||||||||||
2287 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||||||||
2288 | if (local.tm_isdst >= 1) {
| 16600-13718652 | ||||||||||||||||||||||||||||||
2289 | if (daylightStatus)
| 0-13730284 | ||||||||||||||||||||||||||||||
2290 | *daylightStatus = QDateTimePrivate::DaylightTime; executed 13731527 times by 82 tests: *daylightStatus = QDateTimePrivate::DaylightTime; Executed by:
| 13731527 | ||||||||||||||||||||||||||||||
2291 | if (abbreviation)
| 248-13719955 | ||||||||||||||||||||||||||||||
2292 | *abbreviation = qt_tzname(QDateTimePrivate::DaylightTime); executed 248 times by 10 tests: *abbreviation = qt_tzname(QDateTimePrivate::DaylightTime); Executed by:
| 248 | ||||||||||||||||||||||||||||||
2293 | } else if (local.tm_isdst == 0) { executed 13731527 times by 82 tests: end of block Executed by:
| 0-13731527 | ||||||||||||||||||||||||||||||
2294 | if (daylightStatus)
| 0-16600 | ||||||||||||||||||||||||||||||
2295 | *daylightStatus = QDateTimePrivate::StandardTime; executed 16600 times by 41 tests: *daylightStatus = QDateTimePrivate::StandardTime; Executed by:
| 16600 | ||||||||||||||||||||||||||||||
2296 | if (abbreviation)
| 609-15991 | ||||||||||||||||||||||||||||||
2297 | *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); executed 609 times by 4 tests: *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); Executed by:
| 609 | ||||||||||||||||||||||||||||||
2298 | } else { executed 16600 times by 41 tests: end of block Executed by:
| 16600 | ||||||||||||||||||||||||||||||
2299 | if (daylightStatus)
| 0 | ||||||||||||||||||||||||||||||
2300 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; never executed: *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | 0 | ||||||||||||||||||||||||||||||
2301 | if (abbreviation)
| 0 | ||||||||||||||||||||||||||||||
2302 | *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); never executed: *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); | 0 | ||||||||||||||||||||||||||||||
2303 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2304 | if (ok)
| 1142-13746985 | ||||||||||||||||||||||||||||||
2305 | *ok = true; executed 1142 times by 8 tests: *ok = true; Executed by:
| 1142 | ||||||||||||||||||||||||||||||
2306 | } else { executed 13748127 times by 97 tests: end of block Executed by:
| 13748127 | ||||||||||||||||||||||||||||||
2307 | *date = QDate(); | - | ||||||||||||||||||||||||||||||
2308 | *time = QTime(); | - | ||||||||||||||||||||||||||||||
2309 | if (daylightStatus)
| 0-36 | ||||||||||||||||||||||||||||||
2310 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; executed 36 times by 1 test: *daylightStatus = QDateTimePrivate::UnknownDaylightTime; Executed by:
| 36 | ||||||||||||||||||||||||||||||
2311 | if (abbreviation)
| 11-25 | ||||||||||||||||||||||||||||||
2312 | *abbreviation = QString(); executed 11 times by 1 test: *abbreviation = QString(); Executed by:
| 11 | ||||||||||||||||||||||||||||||
2313 | if (ok)
| 0-36 | ||||||||||||||||||||||||||||||
2314 | *ok = false; executed 36 times by 1 test: *ok = false; Executed by:
| 36 | ||||||||||||||||||||||||||||||
2315 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||||||||||||||
2316 | #endif // Q_OS_WINCE | - | ||||||||||||||||||||||||||||||
2317 | - | |||||||||||||||||||||||||||||||
2318 | return ((qint64)secsSinceEpoch * 1000) + msec; executed 13735894 times by 97 tests: return ((qint64)secsSinceEpoch * 1000) + msec; Executed by:
| 13735894 | ||||||||||||||||||||||||||||||
2319 | } | - | ||||||||||||||||||||||||||||||
2320 | - | |||||||||||||||||||||||||||||||
2321 | // Calls the platform variant of localtime for the given msecs, and updates | - | ||||||||||||||||||||||||||||||
2322 | // the date, time, and DST status with the returned values. | - | ||||||||||||||||||||||||||||||
2323 | static bool qt_localtime(qint64 msecsSinceEpoch, QDate *localDate, QTime *localTime, | - | ||||||||||||||||||||||||||||||
2324 | QDateTimePrivate::DaylightStatus *daylightStatus) | - | ||||||||||||||||||||||||||||||
2325 | { | - | ||||||||||||||||||||||||||||||
2326 | const time_t secsSinceEpoch = msecsSinceEpoch / 1000; | - | ||||||||||||||||||||||||||||||
2327 | const int msec = msecsSinceEpoch % 1000; | - | ||||||||||||||||||||||||||||||
2328 | - | |||||||||||||||||||||||||||||||
2329 | tm local; | - | ||||||||||||||||||||||||||||||
2330 | bool valid = false; | - | ||||||||||||||||||||||||||||||
2331 | - | |||||||||||||||||||||||||||||||
2332 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
2333 | FILETIME utcTime = time_tToFt(secsSinceEpoch); | - | ||||||||||||||||||||||||||||||
2334 | FILETIME resultTime; | - | ||||||||||||||||||||||||||||||
2335 | valid = FileTimeToLocalFileTime(&utcTime , &resultTime); | - | ||||||||||||||||||||||||||||||
2336 | SYSTEMTIME sysTime; | - | ||||||||||||||||||||||||||||||
2337 | if (valid) | - | ||||||||||||||||||||||||||||||
2338 | valid = FileTimeToSystemTime(&resultTime , &sysTime); | - | ||||||||||||||||||||||||||||||
2339 | - | |||||||||||||||||||||||||||||||
2340 | if (valid) { | - | ||||||||||||||||||||||||||||||
2341 | local.tm_sec = sysTime.wSecond; | - | ||||||||||||||||||||||||||||||
2342 | local.tm_min = sysTime.wMinute; | - | ||||||||||||||||||||||||||||||
2343 | local.tm_hour = sysTime.wHour; | - | ||||||||||||||||||||||||||||||
2344 | local.tm_mday = sysTime.wDay; | - | ||||||||||||||||||||||||||||||
2345 | local.tm_mon = sysTime.wMonth - 1; | - | ||||||||||||||||||||||||||||||
2346 | local.tm_year = sysTime.wYear - 1900; | - | ||||||||||||||||||||||||||||||
2347 | } | - | ||||||||||||||||||||||||||||||
2348 | #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | - | ||||||||||||||||||||||||||||||
2349 | // localtime() is required to work as if tzset() was called before it. | - | ||||||||||||||||||||||||||||||
2350 | // localtime_r() does not have this requirement, so make an explicit call. | - | ||||||||||||||||||||||||||||||
2351 | qt_tzset(); | - | ||||||||||||||||||||||||||||||
2352 | // Use the reentrant version of localtime() where available | - | ||||||||||||||||||||||||||||||
2353 | // as is thread-safe and doesn't use a shared static data area | - | ||||||||||||||||||||||||||||||
2354 | tm *res = 0; | - | ||||||||||||||||||||||||||||||
2355 | res = localtime_r(&secsSinceEpoch, &local); | - | ||||||||||||||||||||||||||||||
2356 | if (res)
| 0-6859161 | ||||||||||||||||||||||||||||||
2357 | valid = true; executed 6859161 times by 91 tests: valid = true; Executed by:
| 6859161 | ||||||||||||||||||||||||||||||
2358 | #elif defined(_MSC_VER) && _MSC_VER >= 1400 | - | ||||||||||||||||||||||||||||||
2359 | if (!_localtime64_s(&local, &secsSinceEpoch)) | - | ||||||||||||||||||||||||||||||
2360 | valid = true; | - | ||||||||||||||||||||||||||||||
2361 | #else | - | ||||||||||||||||||||||||||||||
2362 | // Returns shared static data which may be overwritten at any time | - | ||||||||||||||||||||||||||||||
2363 | // So copy the result asap | - | ||||||||||||||||||||||||||||||
2364 | tm *res = 0; | - | ||||||||||||||||||||||||||||||
2365 | res = localtime(&secsSinceEpoch); | - | ||||||||||||||||||||||||||||||
2366 | if (res) { | - | ||||||||||||||||||||||||||||||
2367 | local = *res; | - | ||||||||||||||||||||||||||||||
2368 | valid = true; | - | ||||||||||||||||||||||||||||||
2369 | } | - | ||||||||||||||||||||||||||||||
2370 | #endif | - | ||||||||||||||||||||||||||||||
2371 | if (valid) {
| 0-6859161 | ||||||||||||||||||||||||||||||
2372 | *localDate = QDate(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday); | - | ||||||||||||||||||||||||||||||
2373 | *localTime = QTime(local.tm_hour, local.tm_min, local.tm_sec, msec); | - | ||||||||||||||||||||||||||||||
2374 | if (daylightStatus) {
| 0-6856259 | ||||||||||||||||||||||||||||||
2375 | if (local.tm_isdst > 0)
| 696-6858465 | ||||||||||||||||||||||||||||||
2376 | *daylightStatus = QDateTimePrivate::DaylightTime; executed 6858465 times by 78 tests: *daylightStatus = QDateTimePrivate::DaylightTime; Executed by:
| 6858465 | ||||||||||||||||||||||||||||||
2377 | else if (local.tm_isdst < 0)
| 0-696 | ||||||||||||||||||||||||||||||
2378 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; never executed: *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | 0 | ||||||||||||||||||||||||||||||
2379 | else | - | ||||||||||||||||||||||||||||||
2380 | *daylightStatus = QDateTimePrivate::StandardTime; executed 696 times by 28 tests: *daylightStatus = QDateTimePrivate::StandardTime; Executed by:
| 696 | ||||||||||||||||||||||||||||||
2381 | } | - | ||||||||||||||||||||||||||||||
2382 | return true; executed 6856991 times by 91 tests: return true; Executed by:
| 6856991 | ||||||||||||||||||||||||||||||
2383 | } else { | - | ||||||||||||||||||||||||||||||
2384 | *localDate = QDate(); | - | ||||||||||||||||||||||||||||||
2385 | *localTime = QTime(); | - | ||||||||||||||||||||||||||||||
2386 | if (daylightStatus)
| 0 | ||||||||||||||||||||||||||||||
2387 | *daylightStatus = QDateTimePrivate::UnknownDaylightTime; never executed: *daylightStatus = QDateTimePrivate::UnknownDaylightTime; | 0 | ||||||||||||||||||||||||||||||
2388 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
2389 | } | - | ||||||||||||||||||||||||||||||
2390 | } | - | ||||||||||||||||||||||||||||||
2391 | - | |||||||||||||||||||||||||||||||
2392 | // Converts an msecs value into a date and time | - | ||||||||||||||||||||||||||||||
2393 | static void msecsToTime(qint64 msecs, QDate *date, QTime *time) | - | ||||||||||||||||||||||||||||||
2394 | { | - | ||||||||||||||||||||||||||||||
2395 | qint64 jd = JULIAN_DAY_FOR_EPOCH; | - | ||||||||||||||||||||||||||||||
2396 | qint64 ds = 0; | - | ||||||||||||||||||||||||||||||
2397 | - | |||||||||||||||||||||||||||||||
2398 | if (qAbs(msecs) >= MSECS_PER_DAY) {
| 1699-20783660 | ||||||||||||||||||||||||||||||
2399 | jd += (msecs / MSECS_PER_DAY); | - | ||||||||||||||||||||||||||||||
2400 | msecs %= MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
2401 | } executed 20783660 times by 99 tests: end of block Executed by:
| 20783660 | ||||||||||||||||||||||||||||||
2402 | - | |||||||||||||||||||||||||||||||
2403 | if (msecs < 0) {
| 5747-20774921 | ||||||||||||||||||||||||||||||
2404 | ds = MSECS_PER_DAY - msecs - 1; | - | ||||||||||||||||||||||||||||||
2405 | jd -= ds / MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
2406 | ds = ds % MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
2407 | ds = MSECS_PER_DAY - ds - 1; | - | ||||||||||||||||||||||||||||||
2408 | } else { executed 5747 times by 6 tests: end of block Executed by:
| 5747 | ||||||||||||||||||||||||||||||
2409 | ds = msecs; | - | ||||||||||||||||||||||||||||||
2410 | } executed 20779612 times by 98 tests: end of block Executed by:
| 20779612 | ||||||||||||||||||||||||||||||
2411 | - | |||||||||||||||||||||||||||||||
2412 | if (date)
| 6918892-13864443 | ||||||||||||||||||||||||||||||
2413 | *date = QDate::fromJulianDay(jd); executed 13866467 times by 99 tests: *date = QDate::fromJulianDay(jd); Executed by:
| 13866467 | ||||||||||||||||||||||||||||||
2414 | if (time)
| 84674-20686466 | ||||||||||||||||||||||||||||||
2415 | *time = QTime::fromMSecsSinceStartOfDay(ds); executed 20699795 times by 99 tests: *time = QTime::fromMSecsSinceStartOfDay(ds); Executed by:
| 20699795 | ||||||||||||||||||||||||||||||
2416 | } executed 20777508 times by 99 tests: end of block Executed by:
| 20777508 | ||||||||||||||||||||||||||||||
2417 | - | |||||||||||||||||||||||||||||||
2418 | // Converts a date/time value into msecs | - | ||||||||||||||||||||||||||||||
2419 | static qint64 timeToMSecs(const QDate &date, const QTime &time) | - | ||||||||||||||||||||||||||||||
2420 | { | - | ||||||||||||||||||||||||||||||
2421 | return ((date.toJulianDay() - JULIAN_DAY_FOR_EPOCH) * MSECS_PER_DAY) executed 13763898 times by 98 tests: return ((date.toJulianDay() - JULIAN_DAY_FOR_EPOCH) * MSECS_PER_DAY) + time.msecsSinceStartOfDay(); Executed by:
| 13763898 | ||||||||||||||||||||||||||||||
2422 | + time.msecsSinceStartOfDay(); executed 13763898 times by 98 tests: return ((date.toJulianDay() - JULIAN_DAY_FOR_EPOCH) * MSECS_PER_DAY) + time.msecsSinceStartOfDay(); Executed by:
| 13763898 | ||||||||||||||||||||||||||||||
2423 | } | - | ||||||||||||||||||||||||||||||
2424 | - | |||||||||||||||||||||||||||||||
2425 | // Convert an MSecs Since Epoch into Local Time | - | ||||||||||||||||||||||||||||||
2426 | static bool epochMSecsToLocalTime(qint64 msecs, QDate *localDate, QTime *localTime, | - | ||||||||||||||||||||||||||||||
2427 | QDateTimePrivate::DaylightStatus *daylightStatus = 0) | - | ||||||||||||||||||||||||||||||
2428 | { | - | ||||||||||||||||||||||||||||||
2429 | if (msecs < 0) {
| 85-6855776 | ||||||||||||||||||||||||||||||
2430 | // Docs state any LocalTime before 1970-01-01 will *not* have any Daylight Time applied | - | ||||||||||||||||||||||||||||||
2431 | // Instead just use the standard offset from UTC to convert to UTC time | - | ||||||||||||||||||||||||||||||
2432 | qt_tzset(); | - | ||||||||||||||||||||||||||||||
2433 | msecsToTime(msecs - qt_timezone() * 1000, localDate, localTime); | - | ||||||||||||||||||||||||||||||
2434 | if (daylightStatus)
| 0-85 | ||||||||||||||||||||||||||||||
2435 | *daylightStatus = QDateTimePrivate::StandardTime; executed 85 times by 2 tests: *daylightStatus = QDateTimePrivate::StandardTime; Executed by:
| 85 | ||||||||||||||||||||||||||||||
2436 | return true; executed 85 times by 2 tests: return true; Executed by:
| 85 | ||||||||||||||||||||||||||||||
2437 | } else if (msecs > (qint64(TIME_T_MAX) * 1000)) {
| 58-6858508 | ||||||||||||||||||||||||||||||
2438 | // Docs state any LocalTime after 2037-12-31 *will* have any DST applied | - | ||||||||||||||||||||||||||||||
2439 | // but this may fall outside the supported time_t range, so need to fake it. | - | ||||||||||||||||||||||||||||||
2440 | // Use existing method to fake the conversion, but this is deeply flawed as it may | - | ||||||||||||||||||||||||||||||
2441 | // apply the conversion from the wrong day number, e.g. if rule is last Sunday of month | - | ||||||||||||||||||||||||||||||
2442 | // TODO Use QTimeZone when available to apply the future rule correctly | - | ||||||||||||||||||||||||||||||
2443 | QDate utcDate; | - | ||||||||||||||||||||||||||||||
2444 | QTime utcTime; | - | ||||||||||||||||||||||||||||||
2445 | msecsToTime(msecs, &utcDate, &utcTime); | - | ||||||||||||||||||||||||||||||
2446 | int year, month, day; | - | ||||||||||||||||||||||||||||||
2447 | utcDate.getDate(&year, &month, &day); | - | ||||||||||||||||||||||||||||||
2448 | // 2037 is not a leap year, so make sure date isn't Feb 29 | - | ||||||||||||||||||||||||||||||
2449 | if (month == 2 && day == 29)
| 3-49 | ||||||||||||||||||||||||||||||
2450 | --day; executed 3 times by 1 test: --day; Executed by:
| 3 | ||||||||||||||||||||||||||||||
2451 | QDate fakeDate(2037, month, day); | - | ||||||||||||||||||||||||||||||
2452 | qint64 fakeMsecs = QDateTime(fakeDate, utcTime, Qt::UTC).toMSecsSinceEpoch(); | - | ||||||||||||||||||||||||||||||
2453 | bool res = qt_localtime(fakeMsecs, localDate, localTime, daylightStatus); | - | ||||||||||||||||||||||||||||||
2454 | *localDate = localDate->addDays(fakeDate.daysTo(utcDate)); | - | ||||||||||||||||||||||||||||||
2455 | return res; executed 58 times by 2 tests: return res; Executed by:
| 58 | ||||||||||||||||||||||||||||||
2456 | } else { | - | ||||||||||||||||||||||||||||||
2457 | // Falls inside time_t suported range so can use localtime | - | ||||||||||||||||||||||||||||||
2458 | return qt_localtime(msecs, localDate, localTime, daylightStatus); executed 6857684 times by 91 tests: return qt_localtime(msecs, localDate, localTime, daylightStatus); Executed by:
| 6857684 | ||||||||||||||||||||||||||||||
2459 | } | - | ||||||||||||||||||||||||||||||
2460 | } | - | ||||||||||||||||||||||||||||||
2461 | - | |||||||||||||||||||||||||||||||
2462 | // Convert a LocalTime expressed in local msecs encoding and the corresponding | - | ||||||||||||||||||||||||||||||
2463 | // DST status into a UTC epoch msecs. Optionally populate the returned | - | ||||||||||||||||||||||||||||||
2464 | // values from mktime for the adjusted local date and time. | - | ||||||||||||||||||||||||||||||
2465 | static qint64 localMSecsToEpochMSecs(qint64 localMsecs, | - | ||||||||||||||||||||||||||||||
2466 | QDateTimePrivate::DaylightStatus *daylightStatus, | - | ||||||||||||||||||||||||||||||
2467 | QDate *localDate = 0, QTime *localTime = 0, | - | ||||||||||||||||||||||||||||||
2468 | QString *abbreviation = 0) | - | ||||||||||||||||||||||||||||||
2469 | { | - | ||||||||||||||||||||||||||||||
2470 | QDate dt; | - | ||||||||||||||||||||||||||||||
2471 | QTime tm; | - | ||||||||||||||||||||||||||||||
2472 | msecsToTime(localMsecs, &dt, &tm); | - | ||||||||||||||||||||||||||||||
2473 | - | |||||||||||||||||||||||||||||||
2474 | const qint64 msecsMax = qint64(TIME_T_MAX) * 1000; | - | ||||||||||||||||||||||||||||||
2475 | - | |||||||||||||||||||||||||||||||
2476 | if (localMsecs <= qint64(MSECS_PER_DAY)) {
| 7031-13740808 | ||||||||||||||||||||||||||||||
2477 | - | |||||||||||||||||||||||||||||||
2478 | // Docs state any LocalTime before 1970-01-01 will *not* have any DST applied | - | ||||||||||||||||||||||||||||||
2479 | - | |||||||||||||||||||||||||||||||
2480 | // First, if localMsecs is within +/- 1 day of minimum time_t try mktime in case it does | - | ||||||||||||||||||||||||||||||
2481 | // fall after minimum and needs proper DST conversion | - | ||||||||||||||||||||||||||||||
2482 | if (localMsecs >= -qint64(MSECS_PER_DAY)) {
| 1136-5895 | ||||||||||||||||||||||||||||||
2483 | bool valid; | - | ||||||||||||||||||||||||||||||
2484 | qint64 utcMsecs = qt_mktime(&dt, &tm, daylightStatus, abbreviation, &valid); | - | ||||||||||||||||||||||||||||||
2485 | if (valid && utcMsecs >= 0) {
| 36-1100 | ||||||||||||||||||||||||||||||
2486 | // mktime worked and falls in valid range, so use it | - | ||||||||||||||||||||||||||||||
2487 | if (localDate)
| 30-46 | ||||||||||||||||||||||||||||||
2488 | *localDate = dt; executed 30 times by 2 tests: *localDate = dt; Executed by:
| 30 | ||||||||||||||||||||||||||||||
2489 | if (localTime)
| 30-46 | ||||||||||||||||||||||||||||||
2490 | *localTime = tm; executed 30 times by 2 tests: *localTime = tm; Executed by:
| 30 | ||||||||||||||||||||||||||||||
2491 | return utcMsecs; executed 76 times by 2 tests: return utcMsecs; Executed by:
| 76 | ||||||||||||||||||||||||||||||
2492 | } | - | ||||||||||||||||||||||||||||||
2493 | } else { executed 1060 times by 7 tests: end of block Executed by:
| 1060 | ||||||||||||||||||||||||||||||
2494 | // If we don't call mktime then need to call tzset to get offset | - | ||||||||||||||||||||||||||||||
2495 | qt_tzset(); | - | ||||||||||||||||||||||||||||||
2496 | } executed 5895 times by 14 tests: end of block Executed by:
| 5895 | ||||||||||||||||||||||||||||||
2497 | // Time is clearly before 1970-01-01 so just use standard offset to convert | - | ||||||||||||||||||||||||||||||
2498 | qint64 utcMsecs = localMsecs + qt_timezone() * 1000; | - | ||||||||||||||||||||||||||||||
2499 | if (localDate || localTime)
| 0-4980 | ||||||||||||||||||||||||||||||
2500 | msecsToTime(localMsecs, localDate, localTime); executed 4980 times by 15 tests: msecsToTime(localMsecs, localDate, localTime); Executed by:
| 4980 | ||||||||||||||||||||||||||||||
2501 | if (daylightStatus)
| 0-6955 | ||||||||||||||||||||||||||||||
2502 | *daylightStatus = QDateTimePrivate::StandardTime; executed 6955 times by 16 tests: *daylightStatus = QDateTimePrivate::StandardTime; Executed by:
| 6955 | ||||||||||||||||||||||||||||||
2503 | if (abbreviation)
| 282-6673 | ||||||||||||||||||||||||||||||
2504 | *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); executed 282 times by 3 tests: *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); Executed by:
| 282 | ||||||||||||||||||||||||||||||
2505 | return utcMsecs; executed 6955 times by 16 tests: return utcMsecs; Executed by:
| 6955 | ||||||||||||||||||||||||||||||
2506 | - | |||||||||||||||||||||||||||||||
2507 | } else if (localMsecs >= msecsMax - MSECS_PER_DAY) {
| 15189-13727424 | ||||||||||||||||||||||||||||||
2508 | - | |||||||||||||||||||||||||||||||
2509 | // Docs state any LocalTime after 2037-12-31 *will* have any DST applied | - | ||||||||||||||||||||||||||||||
2510 | // but this may fall outside the supported time_t range, so need to fake it. | - | ||||||||||||||||||||||||||||||
2511 | - | |||||||||||||||||||||||||||||||
2512 | // First, if localMsecs is within +/- 1 day of maximum time_t try mktime in case it does | - | ||||||||||||||||||||||||||||||
2513 | // fall before maximum and can use proper DST conversion | - | ||||||||||||||||||||||||||||||
2514 | if (localMsecs <= msecsMax + MSECS_PER_DAY) {
| 42-15147 | ||||||||||||||||||||||||||||||
2515 | bool valid; | - | ||||||||||||||||||||||||||||||
2516 | qint64 utcMsecs = qt_mktime(&dt, &tm, daylightStatus, abbreviation, &valid); | - | ||||||||||||||||||||||||||||||
2517 | if (valid && utcMsecs <= msecsMax) {
| 0-42 | ||||||||||||||||||||||||||||||
2518 | // mktime worked and falls in valid range, so use it | - | ||||||||||||||||||||||||||||||
2519 | if (localDate)
| 9-24 | ||||||||||||||||||||||||||||||
2520 | *localDate = dt; executed 9 times by 1 test: *localDate = dt; Executed by:
| 9 | ||||||||||||||||||||||||||||||
2521 | if (localTime)
| 9-24 | ||||||||||||||||||||||||||||||
2522 | *localTime = tm; executed 9 times by 1 test: *localTime = tm; Executed by:
| 9 | ||||||||||||||||||||||||||||||
2523 | return utcMsecs; executed 33 times by 1 test: return utcMsecs; Executed by:
| 33 | ||||||||||||||||||||||||||||||
2524 | } | - | ||||||||||||||||||||||||||||||
2525 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||||||||||||||
2526 | // Use existing method to fake the conversion, but this is deeply flawed as it may | - | ||||||||||||||||||||||||||||||
2527 | // apply the conversion from the wrong day number, e.g. if rule is last Sunday of month | - | ||||||||||||||||||||||||||||||
2528 | // TODO Use QTimeZone when available to apply the future rule correctly | - | ||||||||||||||||||||||||||||||
2529 | int year, month, day; | - | ||||||||||||||||||||||||||||||
2530 | dt.getDate(&year, &month, &day); | - | ||||||||||||||||||||||||||||||
2531 | // 2037 is not a leap year, so make sure date isn't Feb 29 | - | ||||||||||||||||||||||||||||||
2532 | if (month == 2 && day == 29)
| 33-15081 | ||||||||||||||||||||||||||||||
2533 | --day; executed 33 times by 1 test: --day; Executed by:
| 33 | ||||||||||||||||||||||||||||||
2534 | QDate fakeDate(2037, month, day); | - | ||||||||||||||||||||||||||||||
2535 | qint64 fakeDiff = fakeDate.daysTo(dt); | - | ||||||||||||||||||||||||||||||
2536 | qint64 utcMsecs = qt_mktime(&fakeDate, &tm, daylightStatus, abbreviation); | - | ||||||||||||||||||||||||||||||
2537 | if (localDate)
| 819-14337 | ||||||||||||||||||||||||||||||
2538 | *localDate = fakeDate.addDays(fakeDiff); executed 14337 times by 12 tests: *localDate = fakeDate.addDays(fakeDiff); Executed by:
| 14337 | ||||||||||||||||||||||||||||||
2539 | if (localTime)
| 819-14337 | ||||||||||||||||||||||||||||||
2540 | *localTime = tm; executed 14337 times by 12 tests: *localTime = tm; Executed by:
| 14337 | ||||||||||||||||||||||||||||||
2541 | QDate utcDate; | - | ||||||||||||||||||||||||||||||
2542 | QTime utcTime; | - | ||||||||||||||||||||||||||||||
2543 | msecsToTime(utcMsecs, &utcDate, &utcTime); | - | ||||||||||||||||||||||||||||||
2544 | utcDate = utcDate.addDays(fakeDiff); | - | ||||||||||||||||||||||||||||||
2545 | utcMsecs = timeToMSecs(utcDate, utcTime); | - | ||||||||||||||||||||||||||||||
2546 | return utcMsecs; executed 15156 times by 12 tests: return utcMsecs; Executed by:
| 15156 | ||||||||||||||||||||||||||||||
2547 | - | |||||||||||||||||||||||||||||||
2548 | } else { | - | ||||||||||||||||||||||||||||||
2549 | - | |||||||||||||||||||||||||||||||
2550 | // Clearly falls inside 1970-2037 suported range so can use mktime | - | ||||||||||||||||||||||||||||||
2551 | qint64 utcMsecs = qt_mktime(&dt, &tm, daylightStatus, abbreviation); | - | ||||||||||||||||||||||||||||||
2552 | if (localDate)
| 1807-13701999 | ||||||||||||||||||||||||||||||
2553 | *localDate = dt; executed 13730022 times by 97 tests: *localDate = dt; Executed by:
| 13730022 | ||||||||||||||||||||||||||||||
2554 | if (localTime)
| 1807-13725546 | ||||||||||||||||||||||||||||||
2555 | *localTime = tm; executed 13725984 times by 97 tests: *localTime = tm; Executed by:
| 13725984 | ||||||||||||||||||||||||||||||
2556 | return utcMsecs; executed 13726426 times by 97 tests: return utcMsecs; Executed by:
| 13726426 | ||||||||||||||||||||||||||||||
2557 | - | |||||||||||||||||||||||||||||||
2558 | } | - | ||||||||||||||||||||||||||||||
2559 | } | - | ||||||||||||||||||||||||||||||
2560 | - | |||||||||||||||||||||||||||||||
2561 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
2562 | QDateTimePrivate member functions | - | ||||||||||||||||||||||||||||||
2563 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
2564 | - | |||||||||||||||||||||||||||||||
2565 | QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, | - | ||||||||||||||||||||||||||||||
2566 | int offsetSeconds) | - | ||||||||||||||||||||||||||||||
2567 | : m_msecs(0), | - | ||||||||||||||||||||||||||||||
2568 | m_spec(Qt::LocalTime), | - | ||||||||||||||||||||||||||||||
2569 | m_offsetFromUtc(0), | - | ||||||||||||||||||||||||||||||
2570 | m_status(0) | - | ||||||||||||||||||||||||||||||
2571 | { | - | ||||||||||||||||||||||||||||||
2572 | setTimeSpec(toSpec, offsetSeconds); | - | ||||||||||||||||||||||||||||||
2573 | setDateTime(toDate, toTime); | - | ||||||||||||||||||||||||||||||
2574 | } executed 66003 times by 35 tests: end of block Executed by:
| 66003 | ||||||||||||||||||||||||||||||
2575 | - | |||||||||||||||||||||||||||||||
2576 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2577 | QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime, | - | ||||||||||||||||||||||||||||||
2578 | const QTimeZone &toTimeZone) | - | ||||||||||||||||||||||||||||||
2579 | : m_spec(Qt::TimeZone), | - | ||||||||||||||||||||||||||||||
2580 | m_offsetFromUtc(0), | - | ||||||||||||||||||||||||||||||
2581 | m_timeZone(toTimeZone), | - | ||||||||||||||||||||||||||||||
2582 | m_status(0) | - | ||||||||||||||||||||||||||||||
2583 | { | - | ||||||||||||||||||||||||||||||
2584 | setDateTime(toDate, toTime); | - | ||||||||||||||||||||||||||||||
2585 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||||||||||||||||||||
2586 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2587 | - | |||||||||||||||||||||||||||||||
2588 | void QDateTimePrivate::setTimeSpec(Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||||||||
2589 | { | - | ||||||||||||||||||||||||||||||
2590 | clearValidDateTime(); | - | ||||||||||||||||||||||||||||||
2591 | clearSetToDaylightStatus(); | - | ||||||||||||||||||||||||||||||
2592 | - | |||||||||||||||||||||||||||||||
2593 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2594 | m_timeZone = QTimeZone(); | - | ||||||||||||||||||||||||||||||
2595 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2596 | - | |||||||||||||||||||||||||||||||
2597 | switch (spec) { | - | ||||||||||||||||||||||||||||||
2598 | case Qt::OffsetFromUTC: executed 230 times by 5 tests: case Qt::OffsetFromUTC: Executed by:
| 230 | ||||||||||||||||||||||||||||||
2599 | if (offsetSeconds == 0) {
| 74-156 | ||||||||||||||||||||||||||||||
2600 | m_spec = Qt::UTC; | - | ||||||||||||||||||||||||||||||
2601 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
2602 | } else { executed 74 times by 2 tests: end of block Executed by:
| 74 | ||||||||||||||||||||||||||||||
2603 | m_spec = Qt::OffsetFromUTC; | - | ||||||||||||||||||||||||||||||
2604 | m_offsetFromUtc = offsetSeconds; | - | ||||||||||||||||||||||||||||||
2605 | } executed 156 times by 5 tests: end of block Executed by:
| 156 | ||||||||||||||||||||||||||||||
2606 | break; executed 230 times by 5 tests: break; Executed by:
| 230 | ||||||||||||||||||||||||||||||
2607 | case Qt::TimeZone: never executed: case Qt::TimeZone: | 0 | ||||||||||||||||||||||||||||||
2608 | // Use system time zone instead | - | ||||||||||||||||||||||||||||||
2609 | m_spec = Qt::LocalTime; | - | ||||||||||||||||||||||||||||||
2610 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
2611 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
2612 | case Qt::UTC: executed 60625 times by 28 tests: case Qt::UTC: Executed by:
| 60625 | ||||||||||||||||||||||||||||||
2613 | case Qt::LocalTime: executed 6877491 times by 98 tests: case Qt::LocalTime: Executed by:
| 6877491 | ||||||||||||||||||||||||||||||
2614 | m_spec = spec; | - | ||||||||||||||||||||||||||||||
2615 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
2616 | break; executed 6938116 times by 104 tests: break; Executed by:
| 6938116 | ||||||||||||||||||||||||||||||
2617 | } | - | ||||||||||||||||||||||||||||||
2618 | } executed 6938347 times by 104 tests: end of block Executed by:
| 6938347 | ||||||||||||||||||||||||||||||
2619 | - | |||||||||||||||||||||||||||||||
2620 | void QDateTimePrivate::setDateTime(const QDate &date, const QTime &time) | - | ||||||||||||||||||||||||||||||
2621 | { | - | ||||||||||||||||||||||||||||||
2622 | // If the date is valid and the time is not we set time to 00:00:00 | - | ||||||||||||||||||||||||||||||
2623 | QTime useTime = time; | - | ||||||||||||||||||||||||||||||
2624 | if (!useTime.isValid() && date.isValid())
| 304-6930414 | ||||||||||||||||||||||||||||||
2625 | useTime = QTime::fromMSecsSinceStartOfDay(0); executed 1320 times by 6 tests: useTime = QTime::fromMSecsSinceStartOfDay(0); Executed by:
| 1320 | ||||||||||||||||||||||||||||||
2626 | - | |||||||||||||||||||||||||||||||
2627 | StatusFlags newStatus; | - | ||||||||||||||||||||||||||||||
2628 | - | |||||||||||||||||||||||||||||||
2629 | // Set date value and status | - | ||||||||||||||||||||||||||||||
2630 | qint64 days = 0; | - | ||||||||||||||||||||||||||||||
2631 | if (date.isValid()) {
| 348-6930609 | ||||||||||||||||||||||||||||||
2632 | days = date.toJulianDay() - JULIAN_DAY_FOR_EPOCH; | - | ||||||||||||||||||||||||||||||
2633 | newStatus = ValidDate; | - | ||||||||||||||||||||||||||||||
2634 | } else if (date.isNull()) { executed 6930008 times by 102 tests: end of block Executed by:
| 0-6930008 | ||||||||||||||||||||||||||||||
2635 | newStatus = NullDate; | - | ||||||||||||||||||||||||||||||
2636 | } executed 348 times by 10 tests: end of block Executed by:
| 348 | ||||||||||||||||||||||||||||||
2637 | - | |||||||||||||||||||||||||||||||
2638 | // Set time value and status | - | ||||||||||||||||||||||||||||||
2639 | int ds = 0; | - | ||||||||||||||||||||||||||||||
2640 | if (useTime.isValid()) {
| 304-6930742 | ||||||||||||||||||||||||||||||
2641 | ds = useTime.msecsSinceStartOfDay(); | - | ||||||||||||||||||||||||||||||
2642 | newStatus |= ValidTime; | - | ||||||||||||||||||||||||||||||
2643 | } else if (time.isNull()) { executed 6929581 times by 102 tests: end of block Executed by:
| 0-6929581 | ||||||||||||||||||||||||||||||
2644 | newStatus |= NullTime; | - | ||||||||||||||||||||||||||||||
2645 | } executed 304 times by 9 tests: end of block Executed by:
| 304 | ||||||||||||||||||||||||||||||
2646 | - | |||||||||||||||||||||||||||||||
2647 | // Set msecs serial value | - | ||||||||||||||||||||||||||||||
2648 | m_msecs = (days * MSECS_PER_DAY) + ds; | - | ||||||||||||||||||||||||||||||
2649 | m_status = newStatus; | - | ||||||||||||||||||||||||||||||
2650 | - | |||||||||||||||||||||||||||||||
2651 | // Set if date and time are valid | - | ||||||||||||||||||||||||||||||
2652 | checkValidDateTime(); | - | ||||||||||||||||||||||||||||||
2653 | } executed 6928410 times by 102 tests: end of block Executed by:
| 6928410 | ||||||||||||||||||||||||||||||
2654 | - | |||||||||||||||||||||||||||||||
2655 | QPair<QDate, QTime> QDateTimePrivate::getDateTime() const | - | ||||||||||||||||||||||||||||||
2656 | { | - | ||||||||||||||||||||||||||||||
2657 | QPair<QDate, QTime> result; | - | ||||||||||||||||||||||||||||||
2658 | msecsToTime(m_msecs, &result.first, &result.second); | - | ||||||||||||||||||||||||||||||
2659 | - | |||||||||||||||||||||||||||||||
2660 | if (isNullDate())
| 122-7330 | ||||||||||||||||||||||||||||||
2661 | result.first = QDate(); executed 122 times by 5 tests: result.first = QDate(); Executed by:
| 122 | ||||||||||||||||||||||||||||||
2662 | - | |||||||||||||||||||||||||||||||
2663 | if (isNullTime())
| 122-7330 | ||||||||||||||||||||||||||||||
2664 | result.second = QTime(); executed 122 times by 5 tests: result.second = QTime(); Executed by:
| 122 | ||||||||||||||||||||||||||||||
2665 | - | |||||||||||||||||||||||||||||||
2666 | return result; executed 7452 times by 14 tests: return result; Executed by:
| 7452 | ||||||||||||||||||||||||||||||
2667 | } | - | ||||||||||||||||||||||||||||||
2668 | - | |||||||||||||||||||||||||||||||
2669 | // Set the Daylight Status if LocalTime set via msecs | - | ||||||||||||||||||||||||||||||
2670 | void QDateTimePrivate::setDaylightStatus(QDateTimePrivate::DaylightStatus status) | - | ||||||||||||||||||||||||||||||
2671 | { | - | ||||||||||||||||||||||||||||||
2672 | if (status == DaylightTime) {
| 781-6858465 | ||||||||||||||||||||||||||||||
2673 | m_status = m_status & ~SetToStandardTime; | - | ||||||||||||||||||||||||||||||
2674 | m_status = m_status | SetToDaylightTime; | - | ||||||||||||||||||||||||||||||
2675 | } else if (status == StandardTime) { executed 6858465 times by 78 tests: end of block Executed by:
| 0-6858465 | ||||||||||||||||||||||||||||||
2676 | m_status = m_status & ~SetToDaylightTime; | - | ||||||||||||||||||||||||||||||
2677 | m_status = m_status | SetToStandardTime; | - | ||||||||||||||||||||||||||||||
2678 | } else { executed 781 times by 28 tests: end of block Executed by:
| 781 | ||||||||||||||||||||||||||||||
2679 | clearSetToDaylightStatus(); | - | ||||||||||||||||||||||||||||||
2680 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
2681 | } | - | ||||||||||||||||||||||||||||||
2682 | - | |||||||||||||||||||||||||||||||
2683 | // Get the DST Status if LocalTime set via msecs | - | ||||||||||||||||||||||||||||||
2684 | QDateTimePrivate::DaylightStatus QDateTimePrivate::daylightStatus() const | - | ||||||||||||||||||||||||||||||
2685 | { | - | ||||||||||||||||||||||||||||||
2686 | if ((m_status & SetToDaylightTime) == SetToDaylightTime)
| 6857279-6888095 | ||||||||||||||||||||||||||||||
2687 | return DaylightTime; executed 6859029 times by 78 tests: return DaylightTime; Executed by:
| 6859029 | ||||||||||||||||||||||||||||||
2688 | if ((m_status & SetToStandardTime) == SetToStandardTime)
| 1615-6887015 | ||||||||||||||||||||||||||||||
2689 | return StandardTime; executed 1615 times by 28 tests: return StandardTime; Executed by:
| 1615 | ||||||||||||||||||||||||||||||
2690 | return UnknownDaylightTime; executed 6885948 times by 98 tests: return UnknownDaylightTime; Executed by:
| 6885948 | ||||||||||||||||||||||||||||||
2691 | } | - | ||||||||||||||||||||||||||||||
2692 | - | |||||||||||||||||||||||||||||||
2693 | qint64 QDateTimePrivate::toMSecsSinceEpoch() const | - | ||||||||||||||||||||||||||||||
2694 | { | - | ||||||||||||||||||||||||||||||
2695 | switch (m_spec) { | - | ||||||||||||||||||||||||||||||
2696 | case Qt::OffsetFromUTC: executed 189 times by 4 tests: case Qt::OffsetFromUTC: Executed by:
| 189 | ||||||||||||||||||||||||||||||
2697 | case Qt::UTC: executed 131701 times by 24 tests: case Qt::UTC: Executed by:
| 131701 | ||||||||||||||||||||||||||||||
2698 | return (m_msecs - (m_offsetFromUtc * 1000)); executed 131890 times by 25 tests: return (m_msecs - (m_offsetFromUtc * 1000)); Executed by:
| 131890 | ||||||||||||||||||||||||||||||
2699 | - | |||||||||||||||||||||||||||||||
2700 | case Qt::LocalTime: { executed 3552 times by 26 tests: case Qt::LocalTime: Executed by:
| 3552 | ||||||||||||||||||||||||||||||
2701 | // recalculate the local timezone | - | ||||||||||||||||||||||||||||||
2702 | DaylightStatus status = daylightStatus(); | - | ||||||||||||||||||||||||||||||
2703 | return localMSecsToEpochMSecs(m_msecs, &status); executed 3552 times by 26 tests: return localMSecsToEpochMSecs(m_msecs, &status); Executed by:
| 3552 | ||||||||||||||||||||||||||||||
2704 | } | - | ||||||||||||||||||||||||||||||
2705 | - | |||||||||||||||||||||||||||||||
2706 | case Qt::TimeZone: executed 489 times by 2 tests: case Qt::TimeZone: Executed by:
| 489 | ||||||||||||||||||||||||||||||
2707 | #ifdef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2708 | return 0; | - | ||||||||||||||||||||||||||||||
2709 | #else | - | ||||||||||||||||||||||||||||||
2710 | return zoneMSecsToEpochMSecs(m_msecs, m_timeZone); executed 489 times by 2 tests: return zoneMSecsToEpochMSecs(m_msecs, m_timeZone); Executed by:
| 489 | ||||||||||||||||||||||||||||||
2711 | #endif | - | ||||||||||||||||||||||||||||||
2712 | } | - | ||||||||||||||||||||||||||||||
2713 | Q_UNREACHABLE(); | - | ||||||||||||||||||||||||||||||
2714 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
2715 | } | - | ||||||||||||||||||||||||||||||
2716 | - | |||||||||||||||||||||||||||||||
2717 | // Check the UTC / offsetFromUTC validity | - | ||||||||||||||||||||||||||||||
2718 | void QDateTimePrivate::checkValidDateTime() | - | ||||||||||||||||||||||||||||||
2719 | { | - | ||||||||||||||||||||||||||||||
2720 | switch (m_spec) { | - | ||||||||||||||||||||||||||||||
2721 | case Qt::OffsetFromUTC: executed 202 times by 5 tests: case Qt::OffsetFromUTC: Executed by:
| 202 | ||||||||||||||||||||||||||||||
2722 | case Qt::UTC: executed 49267 times by 25 tests: case Qt::UTC: Executed by:
| 49267 | ||||||||||||||||||||||||||||||
2723 | // for these, a valid date and a valid time imply a valid QDateTime | - | ||||||||||||||||||||||||||||||
2724 | if (isValidDate() && isValidTime())
| 0-48946 | ||||||||||||||||||||||||||||||
2725 | setValidDateTime(); executed 48946 times by 25 tests: setValidDateTime(); Executed by:
| 48946 | ||||||||||||||||||||||||||||||
2726 | else | - | ||||||||||||||||||||||||||||||
2727 | clearValidDateTime(); executed 523 times by 6 tests: clearValidDateTime(); Executed by:
| 523 | ||||||||||||||||||||||||||||||
2728 | break; executed 49469 times by 26 tests: break; Executed by:
| 49469 | ||||||||||||||||||||||||||||||
2729 | case Qt::TimeZone: executed 22 times by 1 test: case Qt::TimeZone: Executed by:
| 22 | ||||||||||||||||||||||||||||||
2730 | case Qt::LocalTime: executed 6881958 times by 98 tests: case Qt::LocalTime: Executed by:
| 6881958 | ||||||||||||||||||||||||||||||
2731 | // for these, we need to check whether the timezone is valid and whether | - | ||||||||||||||||||||||||||||||
2732 | // the time is valid in that timezone. Expensive, but no other option. | - | ||||||||||||||||||||||||||||||
2733 | refreshDateTime(); | - | ||||||||||||||||||||||||||||||
2734 | break; executed 6876462 times by 98 tests: break; Executed by:
| 6876462 | ||||||||||||||||||||||||||||||
2735 | } | - | ||||||||||||||||||||||||||||||
2736 | } executed 6926895 times by 102 tests: end of block Executed by:
| 6926895 | ||||||||||||||||||||||||||||||
2737 | - | |||||||||||||||||||||||||||||||
2738 | // Refresh the LocalTime validity and offset | - | ||||||||||||||||||||||||||||||
2739 | void QDateTimePrivate::refreshDateTime() | - | ||||||||||||||||||||||||||||||
2740 | { | - | ||||||||||||||||||||||||||||||
2741 | switch (m_spec) { | - | ||||||||||||||||||||||||||||||
2742 | case Qt::OffsetFromUTC: never executed: case Qt::OffsetFromUTC: | 0 | ||||||||||||||||||||||||||||||
2743 | case Qt::UTC: never executed: case Qt::UTC: | 0 | ||||||||||||||||||||||||||||||
2744 | // Always set by setDateTime so just return | - | ||||||||||||||||||||||||||||||
2745 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
2746 | case Qt::TimeZone: executed 524 times by 2 tests: case Qt::TimeZone: Executed by:
| 524 | ||||||||||||||||||||||||||||||
2747 | case Qt::LocalTime: executed 13738092 times by 98 tests: case Qt::LocalTime: Executed by:
| 13738092 | ||||||||||||||||||||||||||||||
2748 | break; executed 13743879 times by 98 tests: break; Executed by:
| 13743879 | ||||||||||||||||||||||||||||||
2749 | } | - | ||||||||||||||||||||||||||||||
2750 | - | |||||||||||||||||||||||||||||||
2751 | // If not valid date and time then is invalid | - | ||||||||||||||||||||||||||||||
2752 | if (!isValidDate() || !isValidTime()) {
| 0-13742898 | ||||||||||||||||||||||||||||||
2753 | clearValidDateTime(); | - | ||||||||||||||||||||||||||||||
2754 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
2755 | return; executed 374 times by 10 tests: return; Executed by:
| 374 | ||||||||||||||||||||||||||||||
2756 | } | - | ||||||||||||||||||||||||||||||
2757 | - | |||||||||||||||||||||||||||||||
2758 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2759 | // If not valid time zone then is invalid | - | ||||||||||||||||||||||||||||||
2760 | if (m_spec == Qt::TimeZone && !m_timeZone.isValid()) {
| 1-13733494 | ||||||||||||||||||||||||||||||
2761 | clearValidDateTime(); | - | ||||||||||||||||||||||||||||||
2762 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
2763 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||||||||||||||
2764 | } | - | ||||||||||||||||||||||||||||||
2765 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2766 | - | |||||||||||||||||||||||||||||||
2767 | // We have a valid date and time and a Qt::LocalTime or Qt::TimeZone that needs calculating | - | ||||||||||||||||||||||||||||||
2768 | // LocalTime and TimeZone might fall into a "missing" DST transition hour | - | ||||||||||||||||||||||||||||||
2769 | // Calling toEpochMSecs will adjust the returned date/time if it does | - | ||||||||||||||||||||||||||||||
2770 | QDate testDate; | - | ||||||||||||||||||||||||||||||
2771 | QTime testTime; | - | ||||||||||||||||||||||||||||||
2772 | qint64 epochMSecs = 0; | - | ||||||||||||||||||||||||||||||
2773 | if (m_spec == Qt::LocalTime) {
| 502-13739533 | ||||||||||||||||||||||||||||||
2774 | DaylightStatus status = daylightStatus(); | - | ||||||||||||||||||||||||||||||
2775 | epochMSecs = localMSecsToEpochMSecs(m_msecs, &status, &testDate, &testTime); | - | ||||||||||||||||||||||||||||||
2776 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2777 | } else { executed 13743002 times by 98 tests: end of block Executed by:
| 13743002 | ||||||||||||||||||||||||||||||
2778 | epochMSecs = zoneMSecsToEpochMSecs(m_msecs, m_timeZone, &testDate, &testTime); | - | ||||||||||||||||||||||||||||||
2779 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2780 | } executed 502 times by 2 tests: end of block Executed by:
| 502 | ||||||||||||||||||||||||||||||
2781 | if (timeToMSecs(testDate, testTime) == m_msecs) {
| 4-13742501 | ||||||||||||||||||||||||||||||
2782 | setValidDateTime(); | - | ||||||||||||||||||||||||||||||
2783 | // Cache the offset to use in toMSecsSinceEpoch() | - | ||||||||||||||||||||||||||||||
2784 | m_offsetFromUtc = (m_msecs - epochMSecs) / 1000; | - | ||||||||||||||||||||||||||||||
2785 | } else { executed 13738099 times by 98 tests: end of block Executed by:
| 13738099 | ||||||||||||||||||||||||||||||
2786 | clearValidDateTime(); | - | ||||||||||||||||||||||||||||||
2787 | m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
2788 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||
2789 | } | - | ||||||||||||||||||||||||||||||
2790 | - | |||||||||||||||||||||||||||||||
2791 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2792 | // Convert a TimeZone time expressed in zone msecs encoding into a UTC epoch msecs | - | ||||||||||||||||||||||||||||||
2793 | qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QTimeZone &zone, | - | ||||||||||||||||||||||||||||||
2794 | QDate *localDate, QTime *localTime) | - | ||||||||||||||||||||||||||||||
2795 | { | - | ||||||||||||||||||||||||||||||
2796 | // Get the effective data from QTimeZone | - | ||||||||||||||||||||||||||||||
2797 | QTimeZonePrivate::Data data = zone.d->dataForLocalTime(zoneMSecs); | - | ||||||||||||||||||||||||||||||
2798 | // Docs state any LocalTime before 1970-01-01 will *not* have any DST applied | - | ||||||||||||||||||||||||||||||
2799 | // but all affected times afterwards will have DST applied. | - | ||||||||||||||||||||||||||||||
2800 | if (data.atMSecsSinceEpoch >= 0) {
| 5-986 | ||||||||||||||||||||||||||||||
2801 | msecsToTime(data.atMSecsSinceEpoch + (data.offsetFromUtc * 1000), localDate, localTime); | - | ||||||||||||||||||||||||||||||
2802 | return data.atMSecsSinceEpoch; executed 986 times by 2 tests: return data.atMSecsSinceEpoch; Executed by:
| 986 | ||||||||||||||||||||||||||||||
2803 | } else { | - | ||||||||||||||||||||||||||||||
2804 | msecsToTime(zoneMSecs, localDate, localTime); | - | ||||||||||||||||||||||||||||||
2805 | return zoneMSecs - (data.standardTimeOffset * 1000); executed 5 times by 1 test: return zoneMSecs - (data.standardTimeOffset * 1000); Executed by:
| 5 | ||||||||||||||||||||||||||||||
2806 | } | - | ||||||||||||||||||||||||||||||
2807 | } | - | ||||||||||||||||||||||||||||||
2808 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
2809 | - | |||||||||||||||||||||||||||||||
2810 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
2811 | QDateTime member functions | - | ||||||||||||||||||||||||||||||
2812 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
2813 | - | |||||||||||||||||||||||||||||||
2814 | /*! | - | ||||||||||||||||||||||||||||||
2815 | \class QDateTime | - | ||||||||||||||||||||||||||||||
2816 | \inmodule QtCore | - | ||||||||||||||||||||||||||||||
2817 | \ingroup shared | - | ||||||||||||||||||||||||||||||
2818 | \reentrant | - | ||||||||||||||||||||||||||||||
2819 | \brief The QDateTime class provides date and time functions. | - | ||||||||||||||||||||||||||||||
2820 | - | |||||||||||||||||||||||||||||||
2821 | - | |||||||||||||||||||||||||||||||
2822 | A QDateTime object contains a calendar date and a clock time (a | - | ||||||||||||||||||||||||||||||
2823 | "datetime"). It is a combination of the QDate and QTime classes. | - | ||||||||||||||||||||||||||||||
2824 | It can read the current datetime from the system clock. It | - | ||||||||||||||||||||||||||||||
2825 | provides functions for comparing datetimes and for manipulating a | - | ||||||||||||||||||||||||||||||
2826 | datetime by adding a number of seconds, days, months, or years. | - | ||||||||||||||||||||||||||||||
2827 | - | |||||||||||||||||||||||||||||||
2828 | A QDateTime object is typically created either by giving a date | - | ||||||||||||||||||||||||||||||
2829 | and time explicitly in the constructor, or by using the static | - | ||||||||||||||||||||||||||||||
2830 | function currentDateTime() that returns a QDateTime object set | - | ||||||||||||||||||||||||||||||
2831 | to the system clock's time. The date and time can be changed with | - | ||||||||||||||||||||||||||||||
2832 | setDate() and setTime(). A datetime can also be set using the | - | ||||||||||||||||||||||||||||||
2833 | setTime_t() function that takes a POSIX-standard "number of | - | ||||||||||||||||||||||||||||||
2834 | seconds since 00:00:00 on January 1, 1970" value. The fromString() | - | ||||||||||||||||||||||||||||||
2835 | function returns a QDateTime, given a string and a date format | - | ||||||||||||||||||||||||||||||
2836 | used to interpret the date within the string. | - | ||||||||||||||||||||||||||||||
2837 | - | |||||||||||||||||||||||||||||||
2838 | The date() and time() functions provide access to the date and | - | ||||||||||||||||||||||||||||||
2839 | time parts of the datetime. The same information is provided in | - | ||||||||||||||||||||||||||||||
2840 | textual format by the toString() function. | - | ||||||||||||||||||||||||||||||
2841 | - | |||||||||||||||||||||||||||||||
2842 | QDateTime provides a full set of operators to compare two | - | ||||||||||||||||||||||||||||||
2843 | QDateTime objects, where smaller means earlier and larger means | - | ||||||||||||||||||||||||||||||
2844 | later. | - | ||||||||||||||||||||||||||||||
2845 | - | |||||||||||||||||||||||||||||||
2846 | You can increment (or decrement) a datetime by a given number of | - | ||||||||||||||||||||||||||||||
2847 | milliseconds using addMSecs(), seconds using addSecs(), or days | - | ||||||||||||||||||||||||||||||
2848 | using addDays(). Similarly, you can use addMonths() and addYears(). | - | ||||||||||||||||||||||||||||||
2849 | The daysTo() function returns the number of days between two datetimes, | - | ||||||||||||||||||||||||||||||
2850 | secsTo() returns the number of seconds between two datetimes, and | - | ||||||||||||||||||||||||||||||
2851 | msecsTo() returns the number of milliseconds between two datetimes. | - | ||||||||||||||||||||||||||||||
2852 | - | |||||||||||||||||||||||||||||||
2853 | QDateTime can store datetimes as \l{Qt::LocalTime}{local time} or | - | ||||||||||||||||||||||||||||||
2854 | as \l{Qt::UTC}{UTC}. QDateTime::currentDateTime() returns a | - | ||||||||||||||||||||||||||||||
2855 | QDateTime expressed as local time; use toUTC() to convert it to | - | ||||||||||||||||||||||||||||||
2856 | UTC. You can also use timeSpec() to find out if a QDateTime | - | ||||||||||||||||||||||||||||||
2857 | object stores a UTC time or a local time. Operations such as | - | ||||||||||||||||||||||||||||||
2858 | addSecs() and secsTo() are aware of daylight-saving time (DST). | - | ||||||||||||||||||||||||||||||
2859 | - | |||||||||||||||||||||||||||||||
2860 | \note QDateTime does not account for leap seconds. | - | ||||||||||||||||||||||||||||||
2861 | - | |||||||||||||||||||||||||||||||
2862 | \section1 | - | ||||||||||||||||||||||||||||||
2863 | - | |||||||||||||||||||||||||||||||
2864 | \section2 No Year 0 | - | ||||||||||||||||||||||||||||||
2865 | - | |||||||||||||||||||||||||||||||
2866 | There is no year 0. Dates in that year are considered invalid. The | - | ||||||||||||||||||||||||||||||
2867 | year -1 is the year "1 before Christ" or "1 before current era." | - | ||||||||||||||||||||||||||||||
2868 | The day before 1 January 1 CE is 31 December 1 BCE. | - | ||||||||||||||||||||||||||||||
2869 | - | |||||||||||||||||||||||||||||||
2870 | \section2 Range of Valid Dates | - | ||||||||||||||||||||||||||||||
2871 | - | |||||||||||||||||||||||||||||||
2872 | The range of valid values able to be stored in QDateTime is dependent on | - | ||||||||||||||||||||||||||||||
2873 | the internal storage implementation. QDateTime is currently stored in a | - | ||||||||||||||||||||||||||||||
2874 | qint64 as a serial msecs value encoding the date and time. This restricts | - | ||||||||||||||||||||||||||||||
2875 | the date range to about +/- 292 million years, compared to the QDate range | - | ||||||||||||||||||||||||||||||
2876 | of +/- 2 billion years. Care must be taken when creating a QDateTime with | - | ||||||||||||||||||||||||||||||
2877 | extreme values that you do not overflow the storage. The exact range of | - | ||||||||||||||||||||||||||||||
2878 | supported values varies depending on the Qt::TimeSpec and time zone. | - | ||||||||||||||||||||||||||||||
2879 | - | |||||||||||||||||||||||||||||||
2880 | \section2 | - | ||||||||||||||||||||||||||||||
2881 | Use of System Timezone | - | ||||||||||||||||||||||||||||||
2882 | - | |||||||||||||||||||||||||||||||
2883 | QDateTime uses the system's time zone information to determine the | - | ||||||||||||||||||||||||||||||
2884 | offset of local time from UTC. If the system is not configured | - | ||||||||||||||||||||||||||||||
2885 | correctly or not up-to-date, QDateTime will give wrong results as | - | ||||||||||||||||||||||||||||||
2886 | well. | - | ||||||||||||||||||||||||||||||
2887 | - | |||||||||||||||||||||||||||||||
2888 | \section2 Daylight-Saving Time (DST) | - | ||||||||||||||||||||||||||||||
2889 | - | |||||||||||||||||||||||||||||||
2890 | QDateTime takes into account the system's time zone information | - | ||||||||||||||||||||||||||||||
2891 | when dealing with DST. On modern Unix systems, this means it | - | ||||||||||||||||||||||||||||||
2892 | applies the correct historical DST data whenever possible. On | - | ||||||||||||||||||||||||||||||
2893 | Windows and Windows CE, where the system doesn't support | - | ||||||||||||||||||||||||||||||
2894 | historical DST data, historical accuracy is not maintained with | - | ||||||||||||||||||||||||||||||
2895 | respect to DST. | - | ||||||||||||||||||||||||||||||
2896 | - | |||||||||||||||||||||||||||||||
2897 | The range of valid dates taking DST into account is 1970-01-01 to | - | ||||||||||||||||||||||||||||||
2898 | the present, and rules are in place for handling DST correctly | - | ||||||||||||||||||||||||||||||
2899 | until 2037-12-31, but these could change. For dates falling | - | ||||||||||||||||||||||||||||||
2900 | outside that range, QDateTime makes a \e{best guess} using the | - | ||||||||||||||||||||||||||||||
2901 | rules for year 1970 or 2037, but we can't guarantee accuracy. This | - | ||||||||||||||||||||||||||||||
2902 | means QDateTime doesn't take into account changes in a locale's | - | ||||||||||||||||||||||||||||||
2903 | time zone before 1970, even if the system's time zone database | - | ||||||||||||||||||||||||||||||
2904 | supports that information. | - | ||||||||||||||||||||||||||||||
2905 | - | |||||||||||||||||||||||||||||||
2906 | QDateTime takes into consideration the Standard Time to Daylight-Saving Time | - | ||||||||||||||||||||||||||||||
2907 | transition. For example if the transition is at 2am and the clock goes | - | ||||||||||||||||||||||||||||||
2908 | forward to 3am, then there is a "missing" hour from 02:00:00 to 02:59:59.999 | - | ||||||||||||||||||||||||||||||
2909 | which QDateTime considers to be invalid. Any date maths performed | - | ||||||||||||||||||||||||||||||
2910 | will take this missing hour into account and return a valid result. | - | ||||||||||||||||||||||||||||||
2911 | - | |||||||||||||||||||||||||||||||
2912 | \section2 Offset From UTC | - | ||||||||||||||||||||||||||||||
2913 | - | |||||||||||||||||||||||||||||||
2914 | A Qt::TimeSpec of Qt::OffsetFromUTC is also supported. This allows you | - | ||||||||||||||||||||||||||||||
2915 | to define a QDateTime relative to UTC at a fixed offset of a given number | - | ||||||||||||||||||||||||||||||
2916 | of seconds from UTC. For example, an offset of +3600 seconds is one hour | - | ||||||||||||||||||||||||||||||
2917 | ahead of UTC and is usually written in ISO standard notation as | - | ||||||||||||||||||||||||||||||
2918 | "UTC+01:00". Daylight-Saving Time never applies with this TimeSpec. | - | ||||||||||||||||||||||||||||||
2919 | - | |||||||||||||||||||||||||||||||
2920 | There is no explicit size restriction to the offset seconds, but there is | - | ||||||||||||||||||||||||||||||
2921 | an implicit limit imposed when using the toString() and fromString() | - | ||||||||||||||||||||||||||||||
2922 | methods which use a format of [+|-]hh:mm, effectively limiting the range | - | ||||||||||||||||||||||||||||||
2923 | to +/- 99 hours and 59 minutes and whole minutes only. Note that currently | - | ||||||||||||||||||||||||||||||
2924 | no time zone lies outside the range of +/- 14 hours. | - | ||||||||||||||||||||||||||||||
2925 | - | |||||||||||||||||||||||||||||||
2926 | \section2 Time Zone Support | - | ||||||||||||||||||||||||||||||
2927 | - | |||||||||||||||||||||||||||||||
2928 | A Qt::TimeSpec of Qt::TimeZone is also supported in conjunction with the | - | ||||||||||||||||||||||||||||||
2929 | QTimeZone class. This allows you to define a datetime in a named time zone | - | ||||||||||||||||||||||||||||||
2930 | adhering to a consistent set of daylight-saving transition rules. For | - | ||||||||||||||||||||||||||||||
2931 | example a time zone of "Europe/Berlin" will apply the daylight-saving | - | ||||||||||||||||||||||||||||||
2932 | rules as used in Germany since 1970. Note that the transition rules | - | ||||||||||||||||||||||||||||||
2933 | applied depend on the platform support. See the QTimeZone documentation | - | ||||||||||||||||||||||||||||||
2934 | for more details. | - | ||||||||||||||||||||||||||||||
2935 | - | |||||||||||||||||||||||||||||||
2936 | \sa QDate, QTime, QDateTimeEdit, QTimeZone | - | ||||||||||||||||||||||||||||||
2937 | */ | - | ||||||||||||||||||||||||||||||
2938 | - | |||||||||||||||||||||||||||||||
2939 | /*! | - | ||||||||||||||||||||||||||||||
2940 | Constructs a null datetime (i.e. null date and null time). A null | - | ||||||||||||||||||||||||||||||
2941 | datetime is invalid, since the date is invalid. | - | ||||||||||||||||||||||||||||||
2942 | - | |||||||||||||||||||||||||||||||
2943 | \sa isValid() | - | ||||||||||||||||||||||||||||||
2944 | */ | - | ||||||||||||||||||||||||||||||
2945 | QDateTime::QDateTime() | - | ||||||||||||||||||||||||||||||
2946 | : d(new QDateTimePrivate) | - | ||||||||||||||||||||||||||||||
2947 | { | - | ||||||||||||||||||||||||||||||
2948 | } executed 7008628 times by 123 tests: end of block Executed by:
| 7008628 | ||||||||||||||||||||||||||||||
2949 | - | |||||||||||||||||||||||||||||||
2950 | - | |||||||||||||||||||||||||||||||
2951 | /*! | - | ||||||||||||||||||||||||||||||
2952 | Constructs a datetime with the given \a date, a valid | - | ||||||||||||||||||||||||||||||
2953 | time(00:00:00.000), and sets the timeSpec() to Qt::LocalTime. | - | ||||||||||||||||||||||||||||||
2954 | */ | - | ||||||||||||||||||||||||||||||
2955 | - | |||||||||||||||||||||||||||||||
2956 | QDateTime::QDateTime(const QDate &date) | - | ||||||||||||||||||||||||||||||
2957 | : d(new QDateTimePrivate(date, QTime(0, 0, 0), Qt::LocalTime, 0)) | - | ||||||||||||||||||||||||||||||
2958 | { | - | ||||||||||||||||||||||||||||||
2959 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||||||||||||||||||||||||||
2960 | - | |||||||||||||||||||||||||||||||
2961 | /*! | - | ||||||||||||||||||||||||||||||
2962 | Constructs a datetime with the given \a date and \a time, using | - | ||||||||||||||||||||||||||||||
2963 | the time specification defined by \a spec. | - | ||||||||||||||||||||||||||||||
2964 | - | |||||||||||||||||||||||||||||||
2965 | If \a date is valid and \a time is not, the time will be set to midnight. | - | ||||||||||||||||||||||||||||||
2966 | - | |||||||||||||||||||||||||||||||
2967 | If \a spec is Qt::OffsetFromUTC then it will be set to Qt::UTC, i.e. an | - | ||||||||||||||||||||||||||||||
2968 | offset of 0 seconds. To create a Qt::OffsetFromUTC datetime use the | - | ||||||||||||||||||||||||||||||
2969 | correct constructor. | - | ||||||||||||||||||||||||||||||
2970 | - | |||||||||||||||||||||||||||||||
2971 | If \a spec is Qt::TimeZone then the spec will be set to Qt::LocalTime, | - | ||||||||||||||||||||||||||||||
2972 | i.e. the current system time zone. To create a Qt::TimeZone datetime | - | ||||||||||||||||||||||||||||||
2973 | use the correct constructor. | - | ||||||||||||||||||||||||||||||
2974 | */ | - | ||||||||||||||||||||||||||||||
2975 | - | |||||||||||||||||||||||||||||||
2976 | QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec) | - | ||||||||||||||||||||||||||||||
2977 | : d(new QDateTimePrivate(date, time, spec, 0)) | - | ||||||||||||||||||||||||||||||
2978 | { | - | ||||||||||||||||||||||||||||||
2979 | } executed 65725 times by 34 tests: end of block Executed by:
| 65725 | ||||||||||||||||||||||||||||||
2980 | - | |||||||||||||||||||||||||||||||
2981 | /*! | - | ||||||||||||||||||||||||||||||
2982 | \since 5.2 | - | ||||||||||||||||||||||||||||||
2983 | - | |||||||||||||||||||||||||||||||
2984 | Constructs a datetime with the given \a date and \a time, using | - | ||||||||||||||||||||||||||||||
2985 | the time specification defined by \a spec and \a offsetSeconds seconds. | - | ||||||||||||||||||||||||||||||
2986 | - | |||||||||||||||||||||||||||||||
2987 | If \a date is valid and \a time is not, the time will be set to midnight. | - | ||||||||||||||||||||||||||||||
2988 | - | |||||||||||||||||||||||||||||||
2989 | If the \a spec is not Qt::OffsetFromUTC then \a offsetSeconds will be ignored. | - | ||||||||||||||||||||||||||||||
2990 | - | |||||||||||||||||||||||||||||||
2991 | If the \a spec is Qt::OffsetFromUTC and \a offsetSeconds is 0 then the | - | ||||||||||||||||||||||||||||||
2992 | timeSpec() will be set to Qt::UTC, i.e. an offset of 0 seconds. | - | ||||||||||||||||||||||||||||||
2993 | - | |||||||||||||||||||||||||||||||
2994 | If \a spec is Qt::TimeZone then the spec will be set to Qt::LocalTime, | - | ||||||||||||||||||||||||||||||
2995 | i.e. the current system time zone. To create a Qt::TimeZone datetime | - | ||||||||||||||||||||||||||||||
2996 | use the correct constructor. | - | ||||||||||||||||||||||||||||||
2997 | */ | - | ||||||||||||||||||||||||||||||
2998 | - | |||||||||||||||||||||||||||||||
2999 | QDateTime::QDateTime(const QDate &date, const QTime &time, Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||||||||
3000 | : d(new QDateTimePrivate(date, time, spec, offsetSeconds)) | - | ||||||||||||||||||||||||||||||
3001 | { | - | ||||||||||||||||||||||||||||||
3002 | } executed 272 times by 7 tests: end of block Executed by:
| 272 | ||||||||||||||||||||||||||||||
3003 | - | |||||||||||||||||||||||||||||||
3004 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3005 | /*! | - | ||||||||||||||||||||||||||||||
3006 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3007 | - | |||||||||||||||||||||||||||||||
3008 | Constructs a datetime with the given \a date and \a time, using | - | ||||||||||||||||||||||||||||||
3009 | the Time Zone specified by \a timeZone. | - | ||||||||||||||||||||||||||||||
3010 | - | |||||||||||||||||||||||||||||||
3011 | If \a date is valid and \a time is not, the time will be set to 00:00:00. | - | ||||||||||||||||||||||||||||||
3012 | - | |||||||||||||||||||||||||||||||
3013 | If \a timeZone is invalid then the datetime will be invalid. | - | ||||||||||||||||||||||||||||||
3014 | */ | - | ||||||||||||||||||||||||||||||
3015 | - | |||||||||||||||||||||||||||||||
3016 | QDateTime::QDateTime(const QDate &date, const QTime &time, const QTimeZone &timeZone) | - | ||||||||||||||||||||||||||||||
3017 | : d(new QDateTimePrivate(date, time, timeZone)) | - | ||||||||||||||||||||||||||||||
3018 | { | - | ||||||||||||||||||||||||||||||
3019 | } executed 22 times by 1 test: end of block Executed by:
| 22 | ||||||||||||||||||||||||||||||
3020 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3021 | - | |||||||||||||||||||||||||||||||
3022 | /*! | - | ||||||||||||||||||||||||||||||
3023 | Constructs a copy of the \a other datetime. | - | ||||||||||||||||||||||||||||||
3024 | */ | - | ||||||||||||||||||||||||||||||
3025 | - | |||||||||||||||||||||||||||||||
3026 | QDateTime::QDateTime(const QDateTime &other) | - | ||||||||||||||||||||||||||||||
3027 | : d(other.d) | - | ||||||||||||||||||||||||||||||
3028 | { | - | ||||||||||||||||||||||||||||||
3029 | } executed 472937 times by 63 tests: end of block Executed by:
| 472937 | ||||||||||||||||||||||||||||||
3030 | - | |||||||||||||||||||||||||||||||
3031 | /*! | - | ||||||||||||||||||||||||||||||
3032 | Destroys the datetime. | - | ||||||||||||||||||||||||||||||
3033 | */ | - | ||||||||||||||||||||||||||||||
3034 | QDateTime::~QDateTime() | - | ||||||||||||||||||||||||||||||
3035 | { | - | ||||||||||||||||||||||||||||||
3036 | } | - | ||||||||||||||||||||||||||||||
3037 | - | |||||||||||||||||||||||||||||||
3038 | /*! | - | ||||||||||||||||||||||||||||||
3039 | Makes a copy of the \a other datetime and returns a reference to the | - | ||||||||||||||||||||||||||||||
3040 | copy. | - | ||||||||||||||||||||||||||||||
3041 | */ | - | ||||||||||||||||||||||||||||||
3042 | - | |||||||||||||||||||||||||||||||
3043 | QDateTime &QDateTime::operator=(const QDateTime &other) | - | ||||||||||||||||||||||||||||||
3044 | { | - | ||||||||||||||||||||||||||||||
3045 | d = other.d; | - | ||||||||||||||||||||||||||||||
3046 | return *this; executed 1834 times by 12 tests: return *this; Executed by:
| 1834 | ||||||||||||||||||||||||||||||
3047 | } | - | ||||||||||||||||||||||||||||||
3048 | /*! | - | ||||||||||||||||||||||||||||||
3049 | \fn void QDateTime::swap(QDateTime &other) | - | ||||||||||||||||||||||||||||||
3050 | \since 5.0 | - | ||||||||||||||||||||||||||||||
3051 | - | |||||||||||||||||||||||||||||||
3052 | Swaps this datetime with \a other. This operation is very fast | - | ||||||||||||||||||||||||||||||
3053 | and never fails. | - | ||||||||||||||||||||||||||||||
3054 | */ | - | ||||||||||||||||||||||||||||||
3055 | - | |||||||||||||||||||||||||||||||
3056 | /*! | - | ||||||||||||||||||||||||||||||
3057 | Returns \c true if both the date and the time are null; otherwise | - | ||||||||||||||||||||||||||||||
3058 | returns \c false. A null datetime is invalid. | - | ||||||||||||||||||||||||||||||
3059 | - | |||||||||||||||||||||||||||||||
3060 | \sa QDate::isNull(), QTime::isNull(), isValid() | - | ||||||||||||||||||||||||||||||
3061 | */ | - | ||||||||||||||||||||||||||||||
3062 | - | |||||||||||||||||||||||||||||||
3063 | bool QDateTime::isNull() const | - | ||||||||||||||||||||||||||||||
3064 | { | - | ||||||||||||||||||||||||||||||
3065 | return d->isNullDate() && d->isNullTime(); executed 4853 times by 10 tests: return d->isNullDate() && d->isNullTime(); Executed by:
| 23-4853 | ||||||||||||||||||||||||||||||
3066 | } | - | ||||||||||||||||||||||||||||||
3067 | - | |||||||||||||||||||||||||||||||
3068 | /*! | - | ||||||||||||||||||||||||||||||
3069 | Returns \c true if both the date and the time are valid and they are valid in | - | ||||||||||||||||||||||||||||||
3070 | the current Qt::TimeSpec, otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
3071 | - | |||||||||||||||||||||||||||||||
3072 | If the timeSpec() is Qt::LocalTime or Qt::TimeZone then the date and time are | - | ||||||||||||||||||||||||||||||
3073 | checked to see if they fall in the Standard Time to Daylight-Saving Time transition | - | ||||||||||||||||||||||||||||||
3074 | hour, i.e. if the transition is at 2am and the clock goes forward to 3am | - | ||||||||||||||||||||||||||||||
3075 | then the time from 02:00:00 to 02:59:59.999 is considered to be invalid. | - | ||||||||||||||||||||||||||||||
3076 | - | |||||||||||||||||||||||||||||||
3077 | \sa QDate::isValid(), QTime::isValid() | - | ||||||||||||||||||||||||||||||
3078 | */ | - | ||||||||||||||||||||||||||||||
3079 | - | |||||||||||||||||||||||||||||||
3080 | bool QDateTime::isValid() const | - | ||||||||||||||||||||||||||||||
3081 | { | - | ||||||||||||||||||||||||||||||
3082 | return (d->isValidDateTime()); executed 109787 times by 75 tests: return (d->isValidDateTime()); Executed by:
| 109787 | ||||||||||||||||||||||||||||||
3083 | } | - | ||||||||||||||||||||||||||||||
3084 | - | |||||||||||||||||||||||||||||||
3085 | /*! | - | ||||||||||||||||||||||||||||||
3086 | Returns the date part of the datetime. | - | ||||||||||||||||||||||||||||||
3087 | - | |||||||||||||||||||||||||||||||
3088 | \sa setDate(), time(), timeSpec() | - | ||||||||||||||||||||||||||||||
3089 | */ | - | ||||||||||||||||||||||||||||||
3090 | - | |||||||||||||||||||||||||||||||
3091 | QDate QDateTime::date() const | - | ||||||||||||||||||||||||||||||
3092 | { | - | ||||||||||||||||||||||||||||||
3093 | if (d->isNullDate())
| 71-84185 | ||||||||||||||||||||||||||||||
3094 | return QDate(); executed 71 times by 6 tests: return QDate(); Executed by:
| 71 | ||||||||||||||||||||||||||||||
3095 | QDate dt; | - | ||||||||||||||||||||||||||||||
3096 | msecsToTime(d->m_msecs, &dt, 0); | - | ||||||||||||||||||||||||||||||
3097 | return dt; executed 84185 times by 42 tests: return dt; Executed by:
| 84185 | ||||||||||||||||||||||||||||||
3098 | } | - | ||||||||||||||||||||||||||||||
3099 | - | |||||||||||||||||||||||||||||||
3100 | /*! | - | ||||||||||||||||||||||||||||||
3101 | Returns the time part of the datetime. | - | ||||||||||||||||||||||||||||||
3102 | - | |||||||||||||||||||||||||||||||
3103 | \sa setTime(), date(), timeSpec() | - | ||||||||||||||||||||||||||||||
3104 | */ | - | ||||||||||||||||||||||||||||||
3105 | - | |||||||||||||||||||||||||||||||
3106 | QTime QDateTime::time() const | - | ||||||||||||||||||||||||||||||
3107 | { | - | ||||||||||||||||||||||||||||||
3108 | if (d->isNullTime())
| 70-6918403 | ||||||||||||||||||||||||||||||
3109 | return QTime(); executed 70 times by 6 tests: return QTime(); Executed by:
| 70 | ||||||||||||||||||||||||||||||
3110 | QTime tm; | - | ||||||||||||||||||||||||||||||
3111 | msecsToTime(d->m_msecs, 0, &tm); | - | ||||||||||||||||||||||||||||||
3112 | return tm; executed 6918121 times by 71 tests: return tm; Executed by:
| 6918121 | ||||||||||||||||||||||||||||||
3113 | } | - | ||||||||||||||||||||||||||||||
3114 | - | |||||||||||||||||||||||||||||||
3115 | /*! | - | ||||||||||||||||||||||||||||||
3116 | Returns the time specification of the datetime. | - | ||||||||||||||||||||||||||||||
3117 | - | |||||||||||||||||||||||||||||||
3118 | \sa setTimeSpec(), date(), time(), Qt::TimeSpec | - | ||||||||||||||||||||||||||||||
3119 | */ | - | ||||||||||||||||||||||||||||||
3120 | - | |||||||||||||||||||||||||||||||
3121 | Qt::TimeSpec QDateTime::timeSpec() const | - | ||||||||||||||||||||||||||||||
3122 | { | - | ||||||||||||||||||||||||||||||
3123 | return d->m_spec; executed 2109 times by 19 tests: return d->m_spec; Executed by:
| 2109 | ||||||||||||||||||||||||||||||
3124 | } | - | ||||||||||||||||||||||||||||||
3125 | - | |||||||||||||||||||||||||||||||
3126 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3127 | /*! | - | ||||||||||||||||||||||||||||||
3128 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3129 | - | |||||||||||||||||||||||||||||||
3130 | Returns the time zone of the datetime. | - | ||||||||||||||||||||||||||||||
3131 | - | |||||||||||||||||||||||||||||||
3132 | If the timeSpec() is Qt::LocalTime then an instance of the current system | - | ||||||||||||||||||||||||||||||
3133 | time zone will be returned. Note however that if you copy this time zone | - | ||||||||||||||||||||||||||||||
3134 | the instance will not remain in sync if the system time zone changes. | - | ||||||||||||||||||||||||||||||
3135 | - | |||||||||||||||||||||||||||||||
3136 | \sa setTimeZone(), Qt::TimeSpec | - | ||||||||||||||||||||||||||||||
3137 | */ | - | ||||||||||||||||||||||||||||||
3138 | - | |||||||||||||||||||||||||||||||
3139 | QTimeZone QDateTime::timeZone() const | - | ||||||||||||||||||||||||||||||
3140 | { | - | ||||||||||||||||||||||||||||||
3141 | switch (d->m_spec) { | - | ||||||||||||||||||||||||||||||
3142 | case Qt::UTC: never executed: case Qt::UTC: | 0 | ||||||||||||||||||||||||||||||
3143 | return QTimeZone::utc(); never executed: return QTimeZone::utc(); | 0 | ||||||||||||||||||||||||||||||
3144 | case Qt::OffsetFromUTC: executed 1 time by 1 test: case Qt::OffsetFromUTC: Executed by:
| 1 | ||||||||||||||||||||||||||||||
3145 | return QTimeZone(d->m_offsetFromUtc); executed 1 time by 1 test: return QTimeZone(d->m_offsetFromUtc); Executed by:
| 1 | ||||||||||||||||||||||||||||||
3146 | case Qt::TimeZone: executed 22 times by 1 test: case Qt::TimeZone: Executed by:
| 22 | ||||||||||||||||||||||||||||||
3147 | Q_ASSERT(d->m_timeZone.isValid()); | - | ||||||||||||||||||||||||||||||
3148 | return d->m_timeZone; executed 22 times by 1 test: return d->m_timeZone; Executed by:
| 22 | ||||||||||||||||||||||||||||||
3149 | case Qt::LocalTime: never executed: case Qt::LocalTime: | 0 | ||||||||||||||||||||||||||||||
3150 | return QTimeZone::systemTimeZone(); never executed: return QTimeZone::systemTimeZone(); | 0 | ||||||||||||||||||||||||||||||
3151 | } | - | ||||||||||||||||||||||||||||||
3152 | return QTimeZone(); never executed: return QTimeZone(); | 0 | ||||||||||||||||||||||||||||||
3153 | } | - | ||||||||||||||||||||||||||||||
3154 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3155 | - | |||||||||||||||||||||||||||||||
3156 | /*! | - | ||||||||||||||||||||||||||||||
3157 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3158 | - | |||||||||||||||||||||||||||||||
3159 | Returns the current Offset From UTC in seconds. | - | ||||||||||||||||||||||||||||||
3160 | - | |||||||||||||||||||||||||||||||
3161 | If the timeSpec() is Qt::OffsetFromUTC this will be the value originally set. | - | ||||||||||||||||||||||||||||||
3162 | - | |||||||||||||||||||||||||||||||
3163 | If the timeSpec() is Qt::TimeZone this will be the offset effective in the | - | ||||||||||||||||||||||||||||||
3164 | Time Zone including any Daylight-Saving Offset. | - | ||||||||||||||||||||||||||||||
3165 | - | |||||||||||||||||||||||||||||||
3166 | If the timeSpec() is Qt::LocalTime this will be the difference between the | - | ||||||||||||||||||||||||||||||
3167 | Local Time and UTC including any Daylight-Saving Offset. | - | ||||||||||||||||||||||||||||||
3168 | - | |||||||||||||||||||||||||||||||
3169 | If the timeSpec() is Qt::UTC this will be 0. | - | ||||||||||||||||||||||||||||||
3170 | - | |||||||||||||||||||||||||||||||
3171 | \sa setOffsetFromUtc() | - | ||||||||||||||||||||||||||||||
3172 | */ | - | ||||||||||||||||||||||||||||||
3173 | - | |||||||||||||||||||||||||||||||
3174 | int QDateTime::offsetFromUtc() const | - | ||||||||||||||||||||||||||||||
3175 | { | - | ||||||||||||||||||||||||||||||
3176 | return d->m_offsetFromUtc; executed 580 times by 5 tests: return d->m_offsetFromUtc; Executed by:
| 580 | ||||||||||||||||||||||||||||||
3177 | } | - | ||||||||||||||||||||||||||||||
3178 | - | |||||||||||||||||||||||||||||||
3179 | /*! | - | ||||||||||||||||||||||||||||||
3180 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3181 | - | |||||||||||||||||||||||||||||||
3182 | Returns the Time Zone Abbreviation for the datetime. | - | ||||||||||||||||||||||||||||||
3183 | - | |||||||||||||||||||||||||||||||
3184 | If the timeSpec() is Qt::UTC this will be "UTC". | - | ||||||||||||||||||||||||||||||
3185 | - | |||||||||||||||||||||||||||||||
3186 | If the timeSpec() is Qt::OffsetFromUTC this will be in the format | - | ||||||||||||||||||||||||||||||
3187 | "UTC[+-]00:00". | - | ||||||||||||||||||||||||||||||
3188 | - | |||||||||||||||||||||||||||||||
3189 | If the timeSpec() is Qt::LocalTime then the host system is queried for the | - | ||||||||||||||||||||||||||||||
3190 | correct abbreviation. | - | ||||||||||||||||||||||||||||||
3191 | - | |||||||||||||||||||||||||||||||
3192 | Note that abbreviations may or may not be localized. | - | ||||||||||||||||||||||||||||||
3193 | - | |||||||||||||||||||||||||||||||
3194 | Note too that the abbreviation is not guaranteed to be a unique value, | - | ||||||||||||||||||||||||||||||
3195 | i.e. different time zones may have the same abbreviation. | - | ||||||||||||||||||||||||||||||
3196 | - | |||||||||||||||||||||||||||||||
3197 | \sa timeSpec() | - | ||||||||||||||||||||||||||||||
3198 | */ | - | ||||||||||||||||||||||||||||||
3199 | - | |||||||||||||||||||||||||||||||
3200 | QString QDateTime::timeZoneAbbreviation() const | - | ||||||||||||||||||||||||||||||
3201 | { | - | ||||||||||||||||||||||||||||||
3202 | switch (d->m_spec) { | - | ||||||||||||||||||||||||||||||
3203 | case Qt::UTC: executed 980 times by 7 tests: case Qt::UTC: Executed by:
| 980 | ||||||||||||||||||||||||||||||
3204 | return QTimeZonePrivate::utcQString(); executed 980 times by 7 tests: return QTimeZonePrivate::utcQString(); Executed by:
| 980 | ||||||||||||||||||||||||||||||
3205 | case Qt::OffsetFromUTC: executed 86 times by 3 tests: case Qt::OffsetFromUTC: Executed by:
| 86 | ||||||||||||||||||||||||||||||
3206 | return QTimeZonePrivate::utcQString() + toOffsetString(Qt::ISODate, d->m_offsetFromUtc); executed 86 times by 3 tests: return QTimeZonePrivate::utcQString() + toOffsetString(Qt::ISODate, d->m_offsetFromUtc); Executed by:
| 86 | ||||||||||||||||||||||||||||||
3207 | case Qt::TimeZone: executed 466 times by 2 tests: case Qt::TimeZone: Executed by:
| 466 | ||||||||||||||||||||||||||||||
3208 | #ifdef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3209 | break; | - | ||||||||||||||||||||||||||||||
3210 | #else | - | ||||||||||||||||||||||||||||||
3211 | return d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch()); executed 466 times by 2 tests: return d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch()); Executed by:
| 466 | ||||||||||||||||||||||||||||||
3212 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3213 | case Qt::LocalTime: { executed 1117 times by 12 tests: case Qt::LocalTime: Executed by:
| 1117 | ||||||||||||||||||||||||||||||
3214 | QString abbrev; | - | ||||||||||||||||||||||||||||||
3215 | QDateTimePrivate::DaylightStatus status = d->daylightStatus(); | - | ||||||||||||||||||||||||||||||
3216 | localMSecsToEpochMSecs(d->m_msecs, &status, 0, 0, &abbrev); | - | ||||||||||||||||||||||||||||||
3217 | return abbrev; executed 1117 times by 12 tests: return abbrev; Executed by:
| 1117 | ||||||||||||||||||||||||||||||
3218 | } | - | ||||||||||||||||||||||||||||||
3219 | } | - | ||||||||||||||||||||||||||||||
3220 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
3221 | } | - | ||||||||||||||||||||||||||||||
3222 | - | |||||||||||||||||||||||||||||||
3223 | /*! | - | ||||||||||||||||||||||||||||||
3224 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3225 | - | |||||||||||||||||||||||||||||||
3226 | Returns if this datetime falls in Daylight-Saving Time. | - | ||||||||||||||||||||||||||||||
3227 | - | |||||||||||||||||||||||||||||||
3228 | If the Qt::TimeSpec is not Qt::LocalTime or Qt::TimeZone then will always | - | ||||||||||||||||||||||||||||||
3229 | return false. | - | ||||||||||||||||||||||||||||||
3230 | - | |||||||||||||||||||||||||||||||
3231 | \sa timeSpec() | - | ||||||||||||||||||||||||||||||
3232 | */ | - | ||||||||||||||||||||||||||||||
3233 | - | |||||||||||||||||||||||||||||||
3234 | bool QDateTime::isDaylightTime() const | - | ||||||||||||||||||||||||||||||
3235 | { | - | ||||||||||||||||||||||||||||||
3236 | switch (d->m_spec) { | - | ||||||||||||||||||||||||||||||
3237 | case Qt::UTC: executed 2 times by 1 test: case Qt::UTC: Executed by:
| 2 | ||||||||||||||||||||||||||||||
3238 | case Qt::OffsetFromUTC: executed 2 times by 1 test: case Qt::OffsetFromUTC: Executed by:
| 2 | ||||||||||||||||||||||||||||||
3239 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||||||||||||||||||||
3240 | case Qt::TimeZone: executed 3 times by 1 test: case Qt::TimeZone: Executed by:
| 3 | ||||||||||||||||||||||||||||||
3241 | #ifdef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3242 | break; | - | ||||||||||||||||||||||||||||||
3243 | #else | - | ||||||||||||||||||||||||||||||
3244 | return d->m_timeZone.d->isDaylightTime(toMSecsSinceEpoch()); executed 3 times by 1 test: return d->m_timeZone.d->isDaylightTime(toMSecsSinceEpoch()); Executed by:
| 3 | ||||||||||||||||||||||||||||||
3245 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3246 | case Qt::LocalTime: { executed 2 times by 1 test: case Qt::LocalTime: Executed by:
| 2 | ||||||||||||||||||||||||||||||
3247 | QDateTimePrivate::DaylightStatus status = d->daylightStatus(); | - | ||||||||||||||||||||||||||||||
3248 | if (status == QDateTimePrivate::UnknownDaylightTime)
| 0-2 | ||||||||||||||||||||||||||||||
3249 | localMSecsToEpochMSecs(d->m_msecs, &status); executed 2 times by 1 test: localMSecsToEpochMSecs(d->m_msecs, &status); Executed by:
| 2 | ||||||||||||||||||||||||||||||
3250 | return (status == QDateTimePrivate::DaylightTime); executed 2 times by 1 test: return (status == QDateTimePrivate::DaylightTime); Executed by:
| 2 | ||||||||||||||||||||||||||||||
3251 | } | - | ||||||||||||||||||||||||||||||
3252 | } | - | ||||||||||||||||||||||||||||||
3253 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||
3254 | } | - | ||||||||||||||||||||||||||||||
3255 | - | |||||||||||||||||||||||||||||||
3256 | /*! | - | ||||||||||||||||||||||||||||||
3257 | Sets the date part of this datetime to \a date. If no time is set yet, it | - | ||||||||||||||||||||||||||||||
3258 | is set to midnight. If \a date is invalid, this QDateTime becomes invalid. | - | ||||||||||||||||||||||||||||||
3259 | - | |||||||||||||||||||||||||||||||
3260 | \sa date(), setTime(), setTimeSpec() | - | ||||||||||||||||||||||||||||||
3261 | */ | - | ||||||||||||||||||||||||||||||
3262 | - | |||||||||||||||||||||||||||||||
3263 | void QDateTime::setDate(const QDate &date) | - | ||||||||||||||||||||||||||||||
3264 | { | - | ||||||||||||||||||||||||||||||
3265 | d->setDateTime(date, time()); | - | ||||||||||||||||||||||||||||||
3266 | } executed 133 times by 2 tests: end of block Executed by:
| 133 | ||||||||||||||||||||||||||||||
3267 | - | |||||||||||||||||||||||||||||||
3268 | /*! | - | ||||||||||||||||||||||||||||||
3269 | Sets the time part of this datetime to \a time. If \a time is not valid, | - | ||||||||||||||||||||||||||||||
3270 | this function sets it to midnight. Therefore, it's possible to clear any | - | ||||||||||||||||||||||||||||||
3271 | set time in a QDateTime by setting it to a default QTime: | - | ||||||||||||||||||||||||||||||
3272 | - | |||||||||||||||||||||||||||||||
3273 | \code | - | ||||||||||||||||||||||||||||||
3274 | QDateTime dt = QDateTime::currentDateTime(); | - | ||||||||||||||||||||||||||||||
3275 | dt.setTime(QTime()); | - | ||||||||||||||||||||||||||||||
3276 | \endcode | - | ||||||||||||||||||||||||||||||
3277 | - | |||||||||||||||||||||||||||||||
3278 | \sa time(), setDate(), setTimeSpec() | - | ||||||||||||||||||||||||||||||
3279 | */ | - | ||||||||||||||||||||||||||||||
3280 | - | |||||||||||||||||||||||||||||||
3281 | void QDateTime::setTime(const QTime &time) | - | ||||||||||||||||||||||||||||||
3282 | { | - | ||||||||||||||||||||||||||||||
3283 | d->setDateTime(date(), time); | - | ||||||||||||||||||||||||||||||
3284 | } executed 134 times by 2 tests: end of block Executed by:
| 134 | ||||||||||||||||||||||||||||||
3285 | - | |||||||||||||||||||||||||||||||
3286 | /*! | - | ||||||||||||||||||||||||||||||
3287 | Sets the time specification used in this datetime to \a spec. | - | ||||||||||||||||||||||||||||||
3288 | The datetime will refer to a different point in time. | - | ||||||||||||||||||||||||||||||
3289 | - | |||||||||||||||||||||||||||||||
3290 | If \a spec is Qt::OffsetFromUTC then the timeSpec() will be set | - | ||||||||||||||||||||||||||||||
3291 | to Qt::UTC, i.e. an effective offset of 0. | - | ||||||||||||||||||||||||||||||
3292 | - | |||||||||||||||||||||||||||||||
3293 | If \a spec is Qt::TimeZone then the spec will be set to Qt::LocalTime, | - | ||||||||||||||||||||||||||||||
3294 | i.e. the current system time zone. | - | ||||||||||||||||||||||||||||||
3295 | - | |||||||||||||||||||||||||||||||
3296 | Example: | - | ||||||||||||||||||||||||||||||
3297 | \snippet code/src_corelib_tools_qdatetime.cpp 19 | - | ||||||||||||||||||||||||||||||
3298 | - | |||||||||||||||||||||||||||||||
3299 | \sa timeSpec(), setDate(), setTime(), setTimeZone(), Qt::TimeSpec | - | ||||||||||||||||||||||||||||||
3300 | */ | - | ||||||||||||||||||||||||||||||
3301 | - | |||||||||||||||||||||||||||||||
3302 | void QDateTime::setTimeSpec(Qt::TimeSpec spec) | - | ||||||||||||||||||||||||||||||
3303 | { | - | ||||||||||||||||||||||||||||||
3304 | QDateTimePrivate *d = this->d.data(); // detaches (and shadows d) | - | ||||||||||||||||||||||||||||||
3305 | d->setTimeSpec(spec, 0); | - | ||||||||||||||||||||||||||||||
3306 | d->checkValidDateTime(); | - | ||||||||||||||||||||||||||||||
3307 | } executed 1527 times by 12 tests: end of block Executed by:
| 1527 | ||||||||||||||||||||||||||||||
3308 | - | |||||||||||||||||||||||||||||||
3309 | /*! | - | ||||||||||||||||||||||||||||||
3310 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3311 | - | |||||||||||||||||||||||||||||||
3312 | Sets the timeSpec() to Qt::OffsetFromUTC and the offset to \a offsetSeconds. | - | ||||||||||||||||||||||||||||||
3313 | The datetime will refer to a different point in time. | - | ||||||||||||||||||||||||||||||
3314 | - | |||||||||||||||||||||||||||||||
3315 | The maximum and minimum offset is 14 positive or negative hours. If | - | ||||||||||||||||||||||||||||||
3316 | \a offsetSeconds is larger or smaller than that, then the result is | - | ||||||||||||||||||||||||||||||
3317 | undefined. | - | ||||||||||||||||||||||||||||||
3318 | - | |||||||||||||||||||||||||||||||
3319 | If \a offsetSeconds is 0 then the timeSpec() will be set to Qt::UTC. | - | ||||||||||||||||||||||||||||||
3320 | - | |||||||||||||||||||||||||||||||
3321 | \sa isValid(), offsetFromUtc() | - | ||||||||||||||||||||||||||||||
3322 | */ | - | ||||||||||||||||||||||||||||||
3323 | - | |||||||||||||||||||||||||||||||
3324 | void QDateTime::setOffsetFromUtc(int offsetSeconds) | - | ||||||||||||||||||||||||||||||
3325 | { | - | ||||||||||||||||||||||||||||||
3326 | QDateTimePrivate *d = this->d.data(); // detaches (and shadows d) | - | ||||||||||||||||||||||||||||||
3327 | d->setTimeSpec(Qt::OffsetFromUTC, offsetSeconds); | - | ||||||||||||||||||||||||||||||
3328 | d->checkValidDateTime(); | - | ||||||||||||||||||||||||||||||
3329 | } executed 35 times by 2 tests: end of block Executed by:
| 35 | ||||||||||||||||||||||||||||||
3330 | - | |||||||||||||||||||||||||||||||
3331 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3332 | /*! | - | ||||||||||||||||||||||||||||||
3333 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3334 | - | |||||||||||||||||||||||||||||||
3335 | Sets the time zone used in this datetime to \a toZone. | - | ||||||||||||||||||||||||||||||
3336 | The datetime will refer to a different point in time. | - | ||||||||||||||||||||||||||||||
3337 | - | |||||||||||||||||||||||||||||||
3338 | If \a toZone is invalid then the datetime will be invalid. | - | ||||||||||||||||||||||||||||||
3339 | - | |||||||||||||||||||||||||||||||
3340 | \sa timeZone(), Qt::TimeSpec | - | ||||||||||||||||||||||||||||||
3341 | */ | - | ||||||||||||||||||||||||||||||
3342 | - | |||||||||||||||||||||||||||||||
3343 | void QDateTime::setTimeZone(const QTimeZone &toZone) | - | ||||||||||||||||||||||||||||||
3344 | { | - | ||||||||||||||||||||||||||||||
3345 | QDateTimePrivate *d = this->d.data(); // detaches (and shadows d) | - | ||||||||||||||||||||||||||||||
3346 | d->m_spec = Qt::TimeZone; | - | ||||||||||||||||||||||||||||||
3347 | d->m_offsetFromUtc = 0; | - | ||||||||||||||||||||||||||||||
3348 | d->m_timeZone = toZone; | - | ||||||||||||||||||||||||||||||
3349 | d->refreshDateTime(); | - | ||||||||||||||||||||||||||||||
3350 | } executed 482 times by 2 tests: end of block Executed by:
| 482 | ||||||||||||||||||||||||||||||
3351 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3352 | - | |||||||||||||||||||||||||||||||
3353 | /*! | - | ||||||||||||||||||||||||||||||
3354 | \since 4.7 | - | ||||||||||||||||||||||||||||||
3355 | - | |||||||||||||||||||||||||||||||
3356 | Returns the datetime as the number of milliseconds that have passed | - | ||||||||||||||||||||||||||||||
3357 | since 1970-01-01T00:00:00.000, Coordinated Universal Time (Qt::UTC). | - | ||||||||||||||||||||||||||||||
3358 | - | |||||||||||||||||||||||||||||||
3359 | On systems that do not support time zones, this function will | - | ||||||||||||||||||||||||||||||
3360 | behave as if local time were Qt::UTC. | - | ||||||||||||||||||||||||||||||
3361 | - | |||||||||||||||||||||||||||||||
3362 | The behavior for this function is undefined if the datetime stored in | - | ||||||||||||||||||||||||||||||
3363 | this object is not valid. However, for all valid dates, this function | - | ||||||||||||||||||||||||||||||
3364 | returns a unique value. | - | ||||||||||||||||||||||||||||||
3365 | - | |||||||||||||||||||||||||||||||
3366 | \sa toTime_t(), setMSecsSinceEpoch() | - | ||||||||||||||||||||||||||||||
3367 | */ | - | ||||||||||||||||||||||||||||||
3368 | qint64 QDateTime::toMSecsSinceEpoch() const | - | ||||||||||||||||||||||||||||||
3369 | { | - | ||||||||||||||||||||||||||||||
3370 | return d->toMSecsSinceEpoch(); executed 132174 times by 22 tests: return d->toMSecsSinceEpoch(); Executed by:
| 132174 | ||||||||||||||||||||||||||||||
3371 | } | - | ||||||||||||||||||||||||||||||
3372 | - | |||||||||||||||||||||||||||||||
3373 | /*! | - | ||||||||||||||||||||||||||||||
3374 | Returns the datetime as the number of seconds that have passed | - | ||||||||||||||||||||||||||||||
3375 | since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC). | - | ||||||||||||||||||||||||||||||
3376 | - | |||||||||||||||||||||||||||||||
3377 | On systems that do not support time zones, this function will | - | ||||||||||||||||||||||||||||||
3378 | behave as if local time were Qt::UTC. | - | ||||||||||||||||||||||||||||||
3379 | - | |||||||||||||||||||||||||||||||
3380 | \note This function returns a 32-bit unsigned integer, so it does not | - | ||||||||||||||||||||||||||||||
3381 | support dates before 1970, but it does support dates after | - | ||||||||||||||||||||||||||||||
3382 | 2038-01-19T03:14:06, which may not be valid time_t values. Be careful | - | ||||||||||||||||||||||||||||||
3383 | when passing those time_t values to system functions, which could | - | ||||||||||||||||||||||||||||||
3384 | interpret them as negative dates. | - | ||||||||||||||||||||||||||||||
3385 | - | |||||||||||||||||||||||||||||||
3386 | If the date is outside the range 1970-01-01T00:00:00 to | - | ||||||||||||||||||||||||||||||
3387 | 2106-02-07T06:28:14, this function returns -1 cast to an unsigned integer | - | ||||||||||||||||||||||||||||||
3388 | (i.e., 0xFFFFFFFF). | - | ||||||||||||||||||||||||||||||
3389 | - | |||||||||||||||||||||||||||||||
3390 | To get an extended range, use toMSecsSinceEpoch(). | - | ||||||||||||||||||||||||||||||
3391 | - | |||||||||||||||||||||||||||||||
3392 | \sa toMSecsSinceEpoch(), setTime_t() | - | ||||||||||||||||||||||||||||||
3393 | */ | - | ||||||||||||||||||||||||||||||
3394 | - | |||||||||||||||||||||||||||||||
3395 | uint QDateTime::toTime_t() const | - | ||||||||||||||||||||||||||||||
3396 | { | - | ||||||||||||||||||||||||||||||
3397 | if (!isValid())
| 181-983 | ||||||||||||||||||||||||||||||
3398 | return uint(-1); executed 983 times by 28 tests: return uint(-1); Executed by:
| 983 | ||||||||||||||||||||||||||||||
3399 | qint64 retval = d->toMSecsSinceEpoch() / 1000; | - | ||||||||||||||||||||||||||||||
3400 | if (quint64(retval) >= Q_UINT64_C(0xFFFFFFFF))
| 3-178 | ||||||||||||||||||||||||||||||
3401 | return uint(-1); executed 3 times by 1 test: return uint(-1); Executed by:
| 3 | ||||||||||||||||||||||||||||||
3402 | return uint(retval); executed 178 times by 14 tests: return uint(retval); Executed by:
| 178 | ||||||||||||||||||||||||||||||
3403 | } | - | ||||||||||||||||||||||||||||||
3404 | - | |||||||||||||||||||||||||||||||
3405 | /*! | - | ||||||||||||||||||||||||||||||
3406 | \since 4.7 | - | ||||||||||||||||||||||||||||||
3407 | - | |||||||||||||||||||||||||||||||
3408 | Sets the date and time given the number of milliseconds \a msecs that have | - | ||||||||||||||||||||||||||||||
3409 | passed since 1970-01-01T00:00:00.000, Coordinated Universal Time | - | ||||||||||||||||||||||||||||||
3410 | (Qt::UTC). On systems that do not support time zones this function | - | ||||||||||||||||||||||||||||||
3411 | will behave as if local time were Qt::UTC. | - | ||||||||||||||||||||||||||||||
3412 | - | |||||||||||||||||||||||||||||||
3413 | Note that passing the minimum of \c qint64 | - | ||||||||||||||||||||||||||||||
3414 | (\c{std::numeric_limits<qint64>::min()}) to \a msecs will result in | - | ||||||||||||||||||||||||||||||
3415 | undefined behavior. | - | ||||||||||||||||||||||||||||||
3416 | - | |||||||||||||||||||||||||||||||
3417 | \sa toMSecsSinceEpoch(), setTime_t() | - | ||||||||||||||||||||||||||||||
3418 | */ | - | ||||||||||||||||||||||||||||||
3419 | void QDateTime::setMSecsSinceEpoch(qint64 msecs) | - | ||||||||||||||||||||||||||||||
3420 | { | - | ||||||||||||||||||||||||||||||
3421 | QDateTimePrivate *d = this->d.data(); // detaches (and shadows d) | - | ||||||||||||||||||||||||||||||
3422 | - | |||||||||||||||||||||||||||||||
3423 | d->m_status = 0; | - | ||||||||||||||||||||||||||||||
3424 | switch (d->m_spec) { | - | ||||||||||||||||||||||||||||||
3425 | case Qt::UTC: executed 11646 times by 20 tests: case Qt::UTC: Executed by:
| 11646 | ||||||||||||||||||||||||||||||
3426 | d->m_msecs = msecs; | - | ||||||||||||||||||||||||||||||
3427 | d->m_status = d->m_status | - | ||||||||||||||||||||||||||||||
3428 | | QDateTimePrivate::ValidDate | - | ||||||||||||||||||||||||||||||
3429 | | QDateTimePrivate::ValidTime | - | ||||||||||||||||||||||||||||||
3430 | | QDateTimePrivate::ValidDateTime; | - | ||||||||||||||||||||||||||||||
3431 | break; executed 11646 times by 20 tests: break; Executed by:
| 11646 | ||||||||||||||||||||||||||||||
3432 | case Qt::OffsetFromUTC: executed 17 times by 2 tests: case Qt::OffsetFromUTC: Executed by:
| 17 | ||||||||||||||||||||||||||||||
3433 | d->m_msecs = msecs + (d->m_offsetFromUtc * 1000); | - | ||||||||||||||||||||||||||||||
3434 | d->m_status = d->m_status | - | ||||||||||||||||||||||||||||||
3435 | | QDateTimePrivate::ValidDate | - | ||||||||||||||||||||||||||||||
3436 | | QDateTimePrivate::ValidTime | - | ||||||||||||||||||||||||||||||
3437 | | QDateTimePrivate::ValidDateTime; | - | ||||||||||||||||||||||||||||||
3438 | break; executed 17 times by 2 tests: break; Executed by:
| 17 | ||||||||||||||||||||||||||||||
3439 | case Qt::TimeZone: executed 20 times by 1 test: case Qt::TimeZone: Executed by:
| 20 | ||||||||||||||||||||||||||||||
3440 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3441 | // Docs state any LocalTime before 1970-01-01 will *not* have any DST applied | - | ||||||||||||||||||||||||||||||
3442 | // but all affected times afterwards will have DST applied. | - | ||||||||||||||||||||||||||||||
3443 | if (msecs >= 0)
| 4-16 | ||||||||||||||||||||||||||||||
3444 | d->m_offsetFromUtc = d->m_timeZone.d->offsetFromUtc(msecs); executed 16 times by 1 test: d->m_offsetFromUtc = d->m_timeZone.d->offsetFromUtc(msecs); Executed by:
| 16 | ||||||||||||||||||||||||||||||
3445 | else | - | ||||||||||||||||||||||||||||||
3446 | d->m_offsetFromUtc = d->m_timeZone.d->standardTimeOffset(msecs); executed 4 times by 1 test: d->m_offsetFromUtc = d->m_timeZone.d->standardTimeOffset(msecs); Executed by:
| 4 | ||||||||||||||||||||||||||||||
3447 | d->m_msecs = msecs + (d->m_offsetFromUtc * 1000); | - | ||||||||||||||||||||||||||||||
3448 | d->m_status = d->m_status | - | ||||||||||||||||||||||||||||||
3449 | | QDateTimePrivate::ValidDate | - | ||||||||||||||||||||||||||||||
3450 | | QDateTimePrivate::ValidTime | - | ||||||||||||||||||||||||||||||
3451 | | QDateTimePrivate::ValidDateTime; | - | ||||||||||||||||||||||||||||||
3452 | d->refreshDateTime(); | - | ||||||||||||||||||||||||||||||
3453 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3454 | break; executed 20 times by 1 test: break; Executed by:
| 20 | ||||||||||||||||||||||||||||||
3455 | case Qt::LocalTime: { executed 6859246 times by 91 tests: case Qt::LocalTime: Executed by:
| 6859246 | ||||||||||||||||||||||||||||||
3456 | QDate dt; | - | ||||||||||||||||||||||||||||||
3457 | QTime tm; | - | ||||||||||||||||||||||||||||||
3458 | QDateTimePrivate::DaylightStatus status; | - | ||||||||||||||||||||||||||||||
3459 | epochMSecsToLocalTime(msecs, &dt, &tm, &status); | - | ||||||||||||||||||||||||||||||
3460 | d->setDateTime(dt, tm); | - | ||||||||||||||||||||||||||||||
3461 | d->setDaylightStatus(status); | - | ||||||||||||||||||||||||||||||
3462 | d->refreshDateTime(); | - | ||||||||||||||||||||||||||||||
3463 | break; executed 6851885 times by 91 tests: break; Executed by:
| 6851885 | ||||||||||||||||||||||||||||||
3464 | } | - | ||||||||||||||||||||||||||||||
3465 | } | - | ||||||||||||||||||||||||||||||
3466 | } executed 6868791 times by 99 tests: end of block Executed by:
| 6868791 | ||||||||||||||||||||||||||||||
3467 | - | |||||||||||||||||||||||||||||||
3468 | /*! | - | ||||||||||||||||||||||||||||||
3469 | \fn void QDateTime::setTime_t(uint seconds) | - | ||||||||||||||||||||||||||||||
3470 | - | |||||||||||||||||||||||||||||||
3471 | Sets the date and time given the number of \a seconds that have | - | ||||||||||||||||||||||||||||||
3472 | passed since 1970-01-01T00:00:00, Coordinated Universal Time | - | ||||||||||||||||||||||||||||||
3473 | (Qt::UTC). On systems that do not support time zones this function | - | ||||||||||||||||||||||||||||||
3474 | will behave as if local time were Qt::UTC. | - | ||||||||||||||||||||||||||||||
3475 | - | |||||||||||||||||||||||||||||||
3476 | \sa toTime_t() | - | ||||||||||||||||||||||||||||||
3477 | */ | - | ||||||||||||||||||||||||||||||
3478 | - | |||||||||||||||||||||||||||||||
3479 | void QDateTime::setTime_t(uint secsSince1Jan1970UTC) | - | ||||||||||||||||||||||||||||||
3480 | { | - | ||||||||||||||||||||||||||||||
3481 | setMSecsSinceEpoch((qint64)secsSince1Jan1970UTC * 1000); | - | ||||||||||||||||||||||||||||||
3482 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||||||||||||||
3483 | - | |||||||||||||||||||||||||||||||
3484 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
3485 | /*! | - | ||||||||||||||||||||||||||||||
3486 | \fn QString QDateTime::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||||||||
3487 | - | |||||||||||||||||||||||||||||||
3488 | \overload | - | ||||||||||||||||||||||||||||||
3489 | - | |||||||||||||||||||||||||||||||
3490 | Returns the datetime as a string in the \a format given. | - | ||||||||||||||||||||||||||||||
3491 | - | |||||||||||||||||||||||||||||||
3492 | If the \a format is Qt::TextDate, the string is formatted in | - | ||||||||||||||||||||||||||||||
3493 | the default way. QDate::shortDayName(), QDate::shortMonthName(), | - | ||||||||||||||||||||||||||||||
3494 | and QTime::toString() are used to generate the string, so the | - | ||||||||||||||||||||||||||||||
3495 | day and month names will be localized names using the system locale, | - | ||||||||||||||||||||||||||||||
3496 | i.e. QLocale::system(). An example of this formatting is | - | ||||||||||||||||||||||||||||||
3497 | "Wed May 20 03:40:13 1998". | - | ||||||||||||||||||||||||||||||
3498 | - | |||||||||||||||||||||||||||||||
3499 | If the \a format is Qt::ISODate, the string format corresponds | - | ||||||||||||||||||||||||||||||
3500 | to the ISO 8601 extended specification for representations of | - | ||||||||||||||||||||||||||||||
3501 | dates and times, taking the form YYYY-MM-DDTHH:mm:ss[Z|[+|-]HH:mm], | - | ||||||||||||||||||||||||||||||
3502 | depending on the timeSpec() of the QDateTime. If the timeSpec() | - | ||||||||||||||||||||||||||||||
3503 | is Qt::UTC, Z will be appended to the string; if the timeSpec() is | - | ||||||||||||||||||||||||||||||
3504 | Qt::OffsetFromUTC, the offset in hours and minutes from UTC will | - | ||||||||||||||||||||||||||||||
3505 | be appended to the string. | - | ||||||||||||||||||||||||||||||
3506 | - | |||||||||||||||||||||||||||||||
3507 | If the \a format is Qt::SystemLocaleShortDate or | - | ||||||||||||||||||||||||||||||
3508 | Qt::SystemLocaleLongDate, the string format depends on the locale | - | ||||||||||||||||||||||||||||||
3509 | settings of the system. Identical to calling | - | ||||||||||||||||||||||||||||||
3510 | QLocale::system().toString(datetime, QLocale::ShortFormat) or | - | ||||||||||||||||||||||||||||||
3511 | QLocale::system().toString(datetime, QLocale::LongFormat). | - | ||||||||||||||||||||||||||||||
3512 | - | |||||||||||||||||||||||||||||||
3513 | If the \a format is Qt::DefaultLocaleShortDate or | - | ||||||||||||||||||||||||||||||
3514 | Qt::DefaultLocaleLongDate, the string format depends on the | - | ||||||||||||||||||||||||||||||
3515 | default application locale. This is the locale set with | - | ||||||||||||||||||||||||||||||
3516 | QLocale::setDefault(), or the system locale if no default locale | - | ||||||||||||||||||||||||||||||
3517 | has been set. Identical to calling QLocale().toString(datetime, | - | ||||||||||||||||||||||||||||||
3518 | QLocale::ShortFormat) or QLocale().toString(datetime, | - | ||||||||||||||||||||||||||||||
3519 | QLocale::LongFormat). | - | ||||||||||||||||||||||||||||||
3520 | - | |||||||||||||||||||||||||||||||
3521 | If the \a format is Qt::RFC2822Date, the string is formatted | - | ||||||||||||||||||||||||||||||
3522 | following \l{RFC 2822}. | - | ||||||||||||||||||||||||||||||
3523 | - | |||||||||||||||||||||||||||||||
3524 | If the datetime is invalid, an empty string will be returned. | - | ||||||||||||||||||||||||||||||
3525 | - | |||||||||||||||||||||||||||||||
3526 | \warning The Qt::ISODate format is only valid for years in the | - | ||||||||||||||||||||||||||||||
3527 | range 0 to 9999. This restriction may apply to locale-aware | - | ||||||||||||||||||||||||||||||
3528 | formats as well, depending on the locale settings. | - | ||||||||||||||||||||||||||||||
3529 | - | |||||||||||||||||||||||||||||||
3530 | \sa fromString(), QDate::toString(), QTime::toString(), | - | ||||||||||||||||||||||||||||||
3531 | QLocale::toString() | - | ||||||||||||||||||||||||||||||
3532 | */ | - | ||||||||||||||||||||||||||||||
3533 | - | |||||||||||||||||||||||||||||||
3534 | QString QDateTime::toString(Qt::DateFormat format) const | - | ||||||||||||||||||||||||||||||
3535 | { | - | ||||||||||||||||||||||||||||||
3536 | QString buf; | - | ||||||||||||||||||||||||||||||
3537 | if (!isValid())
| 2-3255 | ||||||||||||||||||||||||||||||
3538 | return buf; executed 2 times by 1 test: return buf; Executed by:
| 2 | ||||||||||||||||||||||||||||||
3539 | - | |||||||||||||||||||||||||||||||
3540 | switch (format) { | - | ||||||||||||||||||||||||||||||
3541 | case Qt::SystemLocaleDate: executed 2786 times by 8 tests: case Qt::SystemLocaleDate: Executed by:
| 2786 | ||||||||||||||||||||||||||||||
3542 | case Qt::SystemLocaleShortDate: executed 1 time by 1 test: case Qt::SystemLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
3543 | return QLocale::system().toString(*this, QLocale::ShortFormat); executed 2787 times by 8 tests: return QLocale::system().toString(*this, QLocale::ShortFormat); Executed by:
| 2787 | ||||||||||||||||||||||||||||||
3544 | case Qt::SystemLocaleLongDate: executed 1 time by 1 test: case Qt::SystemLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
3545 | return QLocale::system().toString(*this, QLocale::LongFormat); executed 1 time by 1 test: return QLocale::system().toString(*this, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||||||||
3546 | case Qt::LocaleDate: executed 1 time by 1 test: case Qt::LocaleDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
3547 | case Qt::DefaultLocaleShortDate: executed 1 time by 1 test: case Qt::DefaultLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
3548 | return QLocale().toString(*this, QLocale::ShortFormat); executed 2 times by 1 test: return QLocale().toString(*this, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
3549 | case Qt::DefaultLocaleLongDate: executed 1 time by 1 test: case Qt::DefaultLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
3550 | return QLocale().toString(*this, QLocale::LongFormat); executed 1 time by 1 test: return QLocale().toString(*this, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||||||||
3551 | case Qt::RFC2822Date: { executed 5 times by 1 test: case Qt::RFC2822Date: Executed by:
| 5 | ||||||||||||||||||||||||||||||
3552 | buf = QLocale::c().toString(*this, QStringLiteral("dd MMM yyyy hh:mm:ss ")); executed 5 times by 1 test: return qstring_literal_temp; Executed by:
| 5 | ||||||||||||||||||||||||||||||
3553 | buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc); | - | ||||||||||||||||||||||||||||||
3554 | return buf; executed 5 times by 1 test: return buf; Executed by:
| 5 | ||||||||||||||||||||||||||||||
3555 | } | - | ||||||||||||||||||||||||||||||
3556 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
3557 | #ifndef QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
3558 | case Qt::TextDate: { executed 433 times by 3 tests: case Qt::TextDate: Executed by:
| 433 | ||||||||||||||||||||||||||||||
3559 | const QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||||||||
3560 | const QDate &dt = p.first; | - | ||||||||||||||||||||||||||||||
3561 | const QTime &tm = p.second; | - | ||||||||||||||||||||||||||||||
3562 | //We cant use date.toString(Qt::TextDate) as we need to insert the time before the year | - | ||||||||||||||||||||||||||||||
3563 | buf = QString::fromLatin1("%1 %2 %3 %4 %5").arg(dt.shortDayName(dt.dayOfWeek())) | - | ||||||||||||||||||||||||||||||
3564 | .arg(dt.shortMonthName(dt.month())) | - | ||||||||||||||||||||||||||||||
3565 | .arg(dt.day()) | - | ||||||||||||||||||||||||||||||
3566 | .arg(tm.toString(Qt::TextDate)) | - | ||||||||||||||||||||||||||||||
3567 | .arg(dt.year()); | - | ||||||||||||||||||||||||||||||
3568 | if (timeSpec() != Qt::LocalTime) {
| 3-430 | ||||||||||||||||||||||||||||||
3569 | buf += QStringLiteral(" GMT"); executed 3 times by 1 test: return qstring_literal_temp; Executed by:
| 3 | ||||||||||||||||||||||||||||||
3570 | if (d->m_spec == Qt::OffsetFromUTC)
| 1-2 | ||||||||||||||||||||||||||||||
3571 | buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc); executed 2 times by 1 test: buf += toOffsetString(Qt::TextDate, d->m_offsetFromUtc); Executed by:
| 2 | ||||||||||||||||||||||||||||||
3572 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||||||||
3573 | return buf; executed 433 times by 3 tests: return buf; Executed by:
| 433 | ||||||||||||||||||||||||||||||
3574 | } | - | ||||||||||||||||||||||||||||||
3575 | #endif | - | ||||||||||||||||||||||||||||||
3576 | case Qt::ISODate: { executed 26 times by 4 tests: case Qt::ISODate: Executed by:
| 26 | ||||||||||||||||||||||||||||||
3577 | const QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||||||||
3578 | const QDate &dt = p.first; | - | ||||||||||||||||||||||||||||||
3579 | const QTime &tm = p.second; | - | ||||||||||||||||||||||||||||||
3580 | buf = dt.toString(Qt::ISODate); | - | ||||||||||||||||||||||||||||||
3581 | if (buf.isEmpty())
| 1-25 | ||||||||||||||||||||||||||||||
3582 | return QString(); // failed to convert executed 1 time by 1 test: return QString(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
3583 | buf += QLatin1Char('T'); | - | ||||||||||||||||||||||||||||||
3584 | buf += tm.toString(Qt::ISODate); | - | ||||||||||||||||||||||||||||||
3585 | switch (d->m_spec) { | - | ||||||||||||||||||||||||||||||
3586 | case Qt::UTC: executed 9 times by 2 tests: case Qt::UTC: Executed by:
| 9 | ||||||||||||||||||||||||||||||
3587 | buf += QLatin1Char('Z'); | - | ||||||||||||||||||||||||||||||
3588 | break; executed 9 times by 2 tests: break; Executed by:
| 9 | ||||||||||||||||||||||||||||||
3589 | case Qt::OffsetFromUTC: executed 3 times by 1 test: case Qt::OffsetFromUTC: Executed by:
| 3 | ||||||||||||||||||||||||||||||
3590 | buf += toOffsetString(Qt::ISODate, d->m_offsetFromUtc); | - | ||||||||||||||||||||||||||||||
3591 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||||||||||||||
3592 | default: executed 13 times by 3 tests: default: Executed by:
| 13 | ||||||||||||||||||||||||||||||
3593 | break; executed 13 times by 3 tests: break; Executed by:
| 13 | ||||||||||||||||||||||||||||||
3594 | } | - | ||||||||||||||||||||||||||||||
3595 | return buf; executed 25 times by 4 tests: return buf; Executed by:
| 25 | ||||||||||||||||||||||||||||||
3596 | } | - | ||||||||||||||||||||||||||||||
3597 | } | - | ||||||||||||||||||||||||||||||
3598 | } | - | ||||||||||||||||||||||||||||||
3599 | - | |||||||||||||||||||||||||||||||
3600 | /*! | - | ||||||||||||||||||||||||||||||
3601 | Returns the datetime as a string. The \a format parameter | - | ||||||||||||||||||||||||||||||
3602 | determines the format of the result string. | - | ||||||||||||||||||||||||||||||
3603 | - | |||||||||||||||||||||||||||||||
3604 | These expressions may be used for the date: | - | ||||||||||||||||||||||||||||||
3605 | - | |||||||||||||||||||||||||||||||
3606 | \table | - | ||||||||||||||||||||||||||||||
3607 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
3608 | \row \li d \li the day as number without a leading zero (1 to 31) | - | ||||||||||||||||||||||||||||||
3609 | \row \li dd \li the day as number with a leading zero (01 to 31) | - | ||||||||||||||||||||||||||||||
3610 | \row \li ddd | - | ||||||||||||||||||||||||||||||
3611 | \li the abbreviated localized day name (e.g. 'Mon' to 'Sun'). | - | ||||||||||||||||||||||||||||||
3612 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
3613 | \row \li dddd | - | ||||||||||||||||||||||||||||||
3614 | \li the long localized day name (e.g. 'Monday' to 'Sunday'). | - | ||||||||||||||||||||||||||||||
3615 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
3616 | \row \li M \li the month as number without a leading zero (1-12) | - | ||||||||||||||||||||||||||||||
3617 | \row \li MM \li the month as number with a leading zero (01-12) | - | ||||||||||||||||||||||||||||||
3618 | \row \li MMM | - | ||||||||||||||||||||||||||||||
3619 | \li the abbreviated localized month name (e.g. 'Jan' to 'Dec'). | - | ||||||||||||||||||||||||||||||
3620 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
3621 | \row \li MMMM | - | ||||||||||||||||||||||||||||||
3622 | \li the long localized month name (e.g. 'January' to 'December'). | - | ||||||||||||||||||||||||||||||
3623 | Uses the system locale to localize the name, i.e. QLocale::system(). | - | ||||||||||||||||||||||||||||||
3624 | \row \li yy \li the year as two digit number (00-99) | - | ||||||||||||||||||||||||||||||
3625 | \row \li yyyy \li the year as four digit number | - | ||||||||||||||||||||||||||||||
3626 | \endtable | - | ||||||||||||||||||||||||||||||
3627 | - | |||||||||||||||||||||||||||||||
3628 | These expressions may be used for the time: | - | ||||||||||||||||||||||||||||||
3629 | - | |||||||||||||||||||||||||||||||
3630 | \table | - | ||||||||||||||||||||||||||||||
3631 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
3632 | \row \li h | - | ||||||||||||||||||||||||||||||
3633 | \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
3634 | \row \li hh | - | ||||||||||||||||||||||||||||||
3635 | \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
3636 | \row \li H | - | ||||||||||||||||||||||||||||||
3637 | \li the hour without a leading zero (0 to 23, even with AM/PM display) | - | ||||||||||||||||||||||||||||||
3638 | \row \li HH | - | ||||||||||||||||||||||||||||||
3639 | \li the hour with a leading zero (00 to 23, even with AM/PM display) | - | ||||||||||||||||||||||||||||||
3640 | \row \li m \li the minute without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
3641 | \row \li mm \li the minute with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
3642 | \row \li s \li the second without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
3643 | \row \li ss \li the second with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
3644 | \row \li z \li the milliseconds without leading zeroes (0 to 999) | - | ||||||||||||||||||||||||||||||
3645 | \row \li zzz \li the milliseconds with leading zeroes (000 to 999) | - | ||||||||||||||||||||||||||||||
3646 | \row \li AP or A | - | ||||||||||||||||||||||||||||||
3647 | \li use AM/PM display. \e A/AP will be replaced by either "AM" or "PM". | - | ||||||||||||||||||||||||||||||
3648 | \row \li ap or a | - | ||||||||||||||||||||||||||||||
3649 | \li use am/pm display. \e a/ap will be replaced by either "am" or "pm". | - | ||||||||||||||||||||||||||||||
3650 | \row \li t \li the timezone (for example "CEST") | - | ||||||||||||||||||||||||||||||
3651 | \endtable | - | ||||||||||||||||||||||||||||||
3652 | - | |||||||||||||||||||||||||||||||
3653 | All other input characters will be ignored. Any sequence of characters that | - | ||||||||||||||||||||||||||||||
3654 | are enclosed in single quotes will be treated as text and not be used as an | - | ||||||||||||||||||||||||||||||
3655 | expression. Two consecutive single quotes ("''") are replaced by a singlequote | - | ||||||||||||||||||||||||||||||
3656 | in the output. Formats without separators (e.g. "HHmm") are currently not supported. | - | ||||||||||||||||||||||||||||||
3657 | - | |||||||||||||||||||||||||||||||
3658 | Example format strings (assumed that the QDateTime is 21 May 2001 | - | ||||||||||||||||||||||||||||||
3659 | 14:13:09): | - | ||||||||||||||||||||||||||||||
3660 | - | |||||||||||||||||||||||||||||||
3661 | \table | - | ||||||||||||||||||||||||||||||
3662 | \header \li Format \li Result | - | ||||||||||||||||||||||||||||||
3663 | \row \li dd.MM.yyyy \li 21.05.2001 | - | ||||||||||||||||||||||||||||||
3664 | \row \li ddd MMMM d yy \li Tue May 21 01 | - | ||||||||||||||||||||||||||||||
3665 | \row \li hh:mm:ss.zzz \li 14:13:09.042 | - | ||||||||||||||||||||||||||||||
3666 | \row \li h:m:s ap \li 2:13:9 pm | - | ||||||||||||||||||||||||||||||
3667 | \endtable | - | ||||||||||||||||||||||||||||||
3668 | - | |||||||||||||||||||||||||||||||
3669 | If the datetime is invalid, an empty string will be returned. | - | ||||||||||||||||||||||||||||||
3670 | - | |||||||||||||||||||||||||||||||
3671 | \sa fromString(), QDate::toString(), QTime::toString(), QLocale::toString() | - | ||||||||||||||||||||||||||||||
3672 | */ | - | ||||||||||||||||||||||||||||||
3673 | QString QDateTime::toString(const QString& format) const | - | ||||||||||||||||||||||||||||||
3674 | { | - | ||||||||||||||||||||||||||||||
3675 | return QLocale::system().toString(*this, format); executed 2244 times by 17 tests: return QLocale::system().toString(*this, format); Executed by:
| 2244 | ||||||||||||||||||||||||||||||
3676 | } | - | ||||||||||||||||||||||||||||||
3677 | #endif //QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
3678 | - | |||||||||||||||||||||||||||||||
3679 | static void massageAdjustedDateTime(Qt::TimeSpec spec, | - | ||||||||||||||||||||||||||||||
3680 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3681 | const QTimeZone &zone, | - | ||||||||||||||||||||||||||||||
3682 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3683 | QDate *date, | - | ||||||||||||||||||||||||||||||
3684 | QTime *time) | - | ||||||||||||||||||||||||||||||
3685 | { | - | ||||||||||||||||||||||||||||||
3686 | /* | - | ||||||||||||||||||||||||||||||
3687 | If we have just adjusted to a day with a DST transition, our given time | - | ||||||||||||||||||||||||||||||
3688 | may lie in the transition hour (either missing or duplicated). For any | - | ||||||||||||||||||||||||||||||
3689 | other time, telling mktime (deep in the bowels of localMSecsToEpochMSecs) | - | ||||||||||||||||||||||||||||||
3690 | we don't know its DST-ness will produce no adjustment (just a decision as | - | ||||||||||||||||||||||||||||||
3691 | to its DST-ness); but for a time in spring's missing hour it'll adjust the | - | ||||||||||||||||||||||||||||||
3692 | time while picking a DST-ness. (Handling of autumn is trickier, as either | - | ||||||||||||||||||||||||||||||
3693 | DST-ness is valid, without adjusting the time. We might want to propagate | - | ||||||||||||||||||||||||||||||
3694 | d->daylightStatus() in that case, but it's hard to do so without breaking | - | ||||||||||||||||||||||||||||||
3695 | (far more common) other cases; and it makes little difference, as the two | - | ||||||||||||||||||||||||||||||
3696 | answers do then differ only in DST-ness.) | - | ||||||||||||||||||||||||||||||
3697 | */ | - | ||||||||||||||||||||||||||||||
3698 | if (spec == Qt::LocalTime) {
| 124-6376 | ||||||||||||||||||||||||||||||
3699 | QDateTimePrivate::DaylightStatus status = QDateTimePrivate::UnknownDaylightTime; | - | ||||||||||||||||||||||||||||||
3700 | localMSecsToEpochMSecs(timeToMSecs(*date, *time), &status, date, time); | - | ||||||||||||||||||||||||||||||
3701 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3702 | } else if (spec == Qt::TimeZone) { executed 6376 times by 2 tests: end of block Executed by:
| 0-6376 | ||||||||||||||||||||||||||||||
3703 | QDateTimePrivate::zoneMSecsToEpochMSecs(timeToMSecs(*date, *time), zone, date, time); | - | ||||||||||||||||||||||||||||||
3704 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3705 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
3706 | } executed 6500 times by 2 tests: end of block Executed by:
| 6500 | ||||||||||||||||||||||||||||||
3707 | #ifdef QT_BOOTSTRAPPED // Avoid duplicate #if-ery in uses. | - | ||||||||||||||||||||||||||||||
3708 | #define MASSAGEADJUSTEDDATETIME(s, z, d, t) massageAdjustedDateTime(s, d, t) | - | ||||||||||||||||||||||||||||||
3709 | #else | - | ||||||||||||||||||||||||||||||
3710 | #define MASSAGEADJUSTEDDATETIME(s, z, d, t) massageAdjustedDateTime(s, z, d, t) | - | ||||||||||||||||||||||||||||||
3711 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3712 | - | |||||||||||||||||||||||||||||||
3713 | /*! | - | ||||||||||||||||||||||||||||||
3714 | Returns a QDateTime object containing a datetime \a ndays days | - | ||||||||||||||||||||||||||||||
3715 | later than the datetime of this object (or earlier if \a ndays is | - | ||||||||||||||||||||||||||||||
3716 | negative). | - | ||||||||||||||||||||||||||||||
3717 | - | |||||||||||||||||||||||||||||||
3718 | If the timeSpec() is Qt::LocalTime and the resulting | - | ||||||||||||||||||||||||||||||
3719 | date and time fall in the Standard Time to Daylight-Saving Time transition | - | ||||||||||||||||||||||||||||||
3720 | hour then the result will be adjusted accordingly, i.e. if the transition | - | ||||||||||||||||||||||||||||||
3721 | is at 2am and the clock goes forward to 3am and the result falls between | - | ||||||||||||||||||||||||||||||
3722 | 2am and 3am then the result will be adjusted to fall after 3am. | - | ||||||||||||||||||||||||||||||
3723 | - | |||||||||||||||||||||||||||||||
3724 | \sa daysTo(), addMonths(), addYears(), addSecs() | - | ||||||||||||||||||||||||||||||
3725 | */ | - | ||||||||||||||||||||||||||||||
3726 | - | |||||||||||||||||||||||||||||||
3727 | QDateTime QDateTime::addDays(qint64 ndays) const | - | ||||||||||||||||||||||||||||||
3728 | { | - | ||||||||||||||||||||||||||||||
3729 | QDateTime dt(*this); | - | ||||||||||||||||||||||||||||||
3730 | QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||||||||
3731 | QDate &date = p.first; | - | ||||||||||||||||||||||||||||||
3732 | QTime &time = p.second; | - | ||||||||||||||||||||||||||||||
3733 | date = date.addDays(ndays); | - | ||||||||||||||||||||||||||||||
3734 | MASSAGEADJUSTEDDATETIME(d->m_spec, d->m_timeZone, &date, &time); | - | ||||||||||||||||||||||||||||||
3735 | dt.d->setDateTime(date, time); | - | ||||||||||||||||||||||||||||||
3736 | return dt; executed 6290 times by 2 tests: return dt; Executed by:
| 6290 | ||||||||||||||||||||||||||||||
3737 | } | - | ||||||||||||||||||||||||||||||
3738 | - | |||||||||||||||||||||||||||||||
3739 | /*! | - | ||||||||||||||||||||||||||||||
3740 | Returns a QDateTime object containing a datetime \a nmonths months | - | ||||||||||||||||||||||||||||||
3741 | later than the datetime of this object (or earlier if \a nmonths | - | ||||||||||||||||||||||||||||||
3742 | is negative). | - | ||||||||||||||||||||||||||||||
3743 | - | |||||||||||||||||||||||||||||||
3744 | If the timeSpec() is Qt::LocalTime and the resulting | - | ||||||||||||||||||||||||||||||
3745 | date and time fall in the Standard Time to Daylight-Saving Time transition | - | ||||||||||||||||||||||||||||||
3746 | hour then the result will be adjusted accordingly, i.e. if the transition | - | ||||||||||||||||||||||||||||||
3747 | is at 2am and the clock goes forward to 3am and the result falls between | - | ||||||||||||||||||||||||||||||
3748 | 2am and 3am then the result will be adjusted to fall after 3am. | - | ||||||||||||||||||||||||||||||
3749 | - | |||||||||||||||||||||||||||||||
3750 | \sa daysTo(), addDays(), addYears(), addSecs() | - | ||||||||||||||||||||||||||||||
3751 | */ | - | ||||||||||||||||||||||||||||||
3752 | - | |||||||||||||||||||||||||||||||
3753 | QDateTime QDateTime::addMonths(int nmonths) const | - | ||||||||||||||||||||||||||||||
3754 | { | - | ||||||||||||||||||||||||||||||
3755 | QDateTime dt(*this); | - | ||||||||||||||||||||||||||||||
3756 | QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||||||||
3757 | QDate &date = p.first; | - | ||||||||||||||||||||||||||||||
3758 | QTime &time = p.second; | - | ||||||||||||||||||||||||||||||
3759 | date = date.addMonths(nmonths); | - | ||||||||||||||||||||||||||||||
3760 | MASSAGEADJUSTEDDATETIME(d->m_spec, d->m_timeZone, &date, &time); | - | ||||||||||||||||||||||||||||||
3761 | dt.d->setDateTime(date, time); | - | ||||||||||||||||||||||||||||||
3762 | return dt; executed 119 times by 2 tests: return dt; Executed by:
| 119 | ||||||||||||||||||||||||||||||
3763 | } | - | ||||||||||||||||||||||||||||||
3764 | - | |||||||||||||||||||||||||||||||
3765 | /*! | - | ||||||||||||||||||||||||||||||
3766 | Returns a QDateTime object containing a datetime \a nyears years | - | ||||||||||||||||||||||||||||||
3767 | later than the datetime of this object (or earlier if \a nyears is | - | ||||||||||||||||||||||||||||||
3768 | negative). | - | ||||||||||||||||||||||||||||||
3769 | - | |||||||||||||||||||||||||||||||
3770 | If the timeSpec() is Qt::LocalTime and the resulting | - | ||||||||||||||||||||||||||||||
3771 | date and time fall in the Standard Time to Daylight-Saving Time transition | - | ||||||||||||||||||||||||||||||
3772 | hour then the result will be adjusted accordingly, i.e. if the transition | - | ||||||||||||||||||||||||||||||
3773 | is at 2am and the clock goes forward to 3am and the result falls between | - | ||||||||||||||||||||||||||||||
3774 | 2am and 3am then the result will be adjusted to fall after 3am. | - | ||||||||||||||||||||||||||||||
3775 | - | |||||||||||||||||||||||||||||||
3776 | \sa daysTo(), addDays(), addMonths(), addSecs() | - | ||||||||||||||||||||||||||||||
3777 | */ | - | ||||||||||||||||||||||||||||||
3778 | - | |||||||||||||||||||||||||||||||
3779 | QDateTime QDateTime::addYears(int nyears) const | - | ||||||||||||||||||||||||||||||
3780 | { | - | ||||||||||||||||||||||||||||||
3781 | QDateTime dt(*this); | - | ||||||||||||||||||||||||||||||
3782 | QPair<QDate, QTime> p = d->getDateTime(); | - | ||||||||||||||||||||||||||||||
3783 | QDate &date = p.first; | - | ||||||||||||||||||||||||||||||
3784 | QTime &time = p.second; | - | ||||||||||||||||||||||||||||||
3785 | date = date.addYears(nyears); | - | ||||||||||||||||||||||||||||||
3786 | MASSAGEADJUSTEDDATETIME(d->m_spec, d->m_timeZone, &date, &time); | - | ||||||||||||||||||||||||||||||
3787 | dt.d->setDateTime(date, time); | - | ||||||||||||||||||||||||||||||
3788 | return dt; executed 91 times by 1 test: return dt; Executed by:
| 91 | ||||||||||||||||||||||||||||||
3789 | } | - | ||||||||||||||||||||||||||||||
3790 | #undef MASSAGEADJUSTEDDATETIME | - | ||||||||||||||||||||||||||||||
3791 | - | |||||||||||||||||||||||||||||||
3792 | /*! | - | ||||||||||||||||||||||||||||||
3793 | Returns a QDateTime object containing a datetime \a s seconds | - | ||||||||||||||||||||||||||||||
3794 | later than the datetime of this object (or earlier if \a s is | - | ||||||||||||||||||||||||||||||
3795 | negative). | - | ||||||||||||||||||||||||||||||
3796 | - | |||||||||||||||||||||||||||||||
3797 | If this datetime is invalid, an invalid datetime will be returned. | - | ||||||||||||||||||||||||||||||
3798 | - | |||||||||||||||||||||||||||||||
3799 | \sa addMSecs(), secsTo(), addDays(), addMonths(), addYears() | - | ||||||||||||||||||||||||||||||
3800 | */ | - | ||||||||||||||||||||||||||||||
3801 | - | |||||||||||||||||||||||||||||||
3802 | QDateTime QDateTime::addSecs(qint64 s) const | - | ||||||||||||||||||||||||||||||
3803 | { | - | ||||||||||||||||||||||||||||||
3804 | return addMSecs(s * 1000); executed 41121 times by 17 tests: return addMSecs(s * 1000); Executed by:
| 41121 | ||||||||||||||||||||||||||||||
3805 | } | - | ||||||||||||||||||||||||||||||
3806 | - | |||||||||||||||||||||||||||||||
3807 | /*! | - | ||||||||||||||||||||||||||||||
3808 | Returns a QDateTime object containing a datetime \a msecs miliseconds | - | ||||||||||||||||||||||||||||||
3809 | later than the datetime of this object (or earlier if \a msecs is | - | ||||||||||||||||||||||||||||||
3810 | negative). | - | ||||||||||||||||||||||||||||||
3811 | - | |||||||||||||||||||||||||||||||
3812 | If this datetime is invalid, an invalid datetime will be returned. | - | ||||||||||||||||||||||||||||||
3813 | - | |||||||||||||||||||||||||||||||
3814 | \sa addSecs(), msecsTo(), addDays(), addMonths(), addYears() | - | ||||||||||||||||||||||||||||||
3815 | */ | - | ||||||||||||||||||||||||||||||
3816 | QDateTime QDateTime::addMSecs(qint64 msecs) const | - | ||||||||||||||||||||||||||||||
3817 | { | - | ||||||||||||||||||||||||||||||
3818 | if (!isValid())
| 5-41209 | ||||||||||||||||||||||||||||||
3819 | return QDateTime(); executed 5 times by 1 test: return QDateTime(); Executed by:
| 5 | ||||||||||||||||||||||||||||||
3820 | - | |||||||||||||||||||||||||||||||
3821 | QDateTime dt(*this); | - | ||||||||||||||||||||||||||||||
3822 | if (d->m_spec == Qt::LocalTime || d->m_spec == Qt::TimeZone)
| 0-41126 | ||||||||||||||||||||||||||||||
3823 | // Convert to real UTC first in case crosses DST transition | - | ||||||||||||||||||||||||||||||
3824 | dt.setMSecsSinceEpoch(d->toMSecsSinceEpoch() + msecs); executed 83 times by 2 tests: dt.setMSecsSinceEpoch(d->toMSecsSinceEpoch() + msecs); Executed by:
| 83 | ||||||||||||||||||||||||||||||
3825 | else | - | ||||||||||||||||||||||||||||||
3826 | // No need to convert, just add on | - | ||||||||||||||||||||||||||||||
3827 | dt.d->m_msecs = dt.d->m_msecs + msecs; executed 41126 times by 16 tests: dt.d->m_msecs = dt.d->m_msecs + msecs; Executed by:
| 41126 | ||||||||||||||||||||||||||||||
3828 | return dt; executed 41209 times by 17 tests: return dt; Executed by:
| 41209 | ||||||||||||||||||||||||||||||
3829 | } | - | ||||||||||||||||||||||||||||||
3830 | - | |||||||||||||||||||||||||||||||
3831 | /*! | - | ||||||||||||||||||||||||||||||
3832 | Returns the number of days from this datetime to the \a other | - | ||||||||||||||||||||||||||||||
3833 | datetime. The number of days is counted as the number of times | - | ||||||||||||||||||||||||||||||
3834 | midnight is reached between this datetime to the \a other | - | ||||||||||||||||||||||||||||||
3835 | datetime. This means that a 10 minute difference from 23:55 to | - | ||||||||||||||||||||||||||||||
3836 | 0:05 the next day counts as one day. | - | ||||||||||||||||||||||||||||||
3837 | - | |||||||||||||||||||||||||||||||
3838 | If the \a other datetime is earlier than this datetime, | - | ||||||||||||||||||||||||||||||
3839 | the value returned is negative. | - | ||||||||||||||||||||||||||||||
3840 | - | |||||||||||||||||||||||||||||||
3841 | Example: | - | ||||||||||||||||||||||||||||||
3842 | \snippet code/src_corelib_tools_qdatetime.cpp 15 | - | ||||||||||||||||||||||||||||||
3843 | - | |||||||||||||||||||||||||||||||
3844 | \sa addDays(), secsTo(), msecsTo() | - | ||||||||||||||||||||||||||||||
3845 | */ | - | ||||||||||||||||||||||||||||||
3846 | - | |||||||||||||||||||||||||||||||
3847 | qint64 QDateTime::daysTo(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
3848 | { | - | ||||||||||||||||||||||||||||||
3849 | return date().daysTo(other.date()); executed 114 times by 3 tests: return date().daysTo(other.date()); Executed by:
| 114 | ||||||||||||||||||||||||||||||
3850 | } | - | ||||||||||||||||||||||||||||||
3851 | - | |||||||||||||||||||||||||||||||
3852 | /*! | - | ||||||||||||||||||||||||||||||
3853 | Returns the number of seconds from this datetime to the \a other | - | ||||||||||||||||||||||||||||||
3854 | datetime. If the \a other datetime is earlier than this datetime, | - | ||||||||||||||||||||||||||||||
3855 | the value returned is negative. | - | ||||||||||||||||||||||||||||||
3856 | - | |||||||||||||||||||||||||||||||
3857 | Before performing the comparison, the two datetimes are converted | - | ||||||||||||||||||||||||||||||
3858 | to Qt::UTC to ensure that the result is correct if daylight-saving | - | ||||||||||||||||||||||||||||||
3859 | (DST) applies to one of the two datetimes but not the other. | - | ||||||||||||||||||||||||||||||
3860 | - | |||||||||||||||||||||||||||||||
3861 | Returns 0 if either datetime is invalid. | - | ||||||||||||||||||||||||||||||
3862 | - | |||||||||||||||||||||||||||||||
3863 | Example: | - | ||||||||||||||||||||||||||||||
3864 | \snippet code/src_corelib_tools_qdatetime.cpp 11 | - | ||||||||||||||||||||||||||||||
3865 | - | |||||||||||||||||||||||||||||||
3866 | \sa addSecs(), daysTo(), QTime::secsTo() | - | ||||||||||||||||||||||||||||||
3867 | */ | - | ||||||||||||||||||||||||||||||
3868 | - | |||||||||||||||||||||||||||||||
3869 | qint64 QDateTime::secsTo(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
3870 | { | - | ||||||||||||||||||||||||||||||
3871 | return (msecsTo(other) / 1000); executed 815 times by 11 tests: return (msecsTo(other) / 1000); Executed by:
| 815 | ||||||||||||||||||||||||||||||
3872 | } | - | ||||||||||||||||||||||||||||||
3873 | - | |||||||||||||||||||||||||||||||
3874 | /*! | - | ||||||||||||||||||||||||||||||
3875 | Returns the number of milliseconds from this datetime to the \a other | - | ||||||||||||||||||||||||||||||
3876 | datetime. If the \a other datetime is earlier than this datetime, | - | ||||||||||||||||||||||||||||||
3877 | the value returned is negative. | - | ||||||||||||||||||||||||||||||
3878 | - | |||||||||||||||||||||||||||||||
3879 | Before performing the comparison, the two datetimes are converted | - | ||||||||||||||||||||||||||||||
3880 | to Qt::UTC to ensure that the result is correct if daylight-saving | - | ||||||||||||||||||||||||||||||
3881 | (DST) applies to one of the two datetimes and but not the other. | - | ||||||||||||||||||||||||||||||
3882 | - | |||||||||||||||||||||||||||||||
3883 | Returns 0 if either datetime is invalid. | - | ||||||||||||||||||||||||||||||
3884 | - | |||||||||||||||||||||||||||||||
3885 | \sa addMSecs(), daysTo(), QTime::msecsTo() | - | ||||||||||||||||||||||||||||||
3886 | */ | - | ||||||||||||||||||||||||||||||
3887 | - | |||||||||||||||||||||||||||||||
3888 | qint64 QDateTime::msecsTo(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
3889 | { | - | ||||||||||||||||||||||||||||||
3890 | if (!isValid() || !other.isValid())
| 0-1175 | ||||||||||||||||||||||||||||||
3891 | return 0; executed 4 times by 1 test: return 0; Executed by:
| 4 | ||||||||||||||||||||||||||||||
3892 | - | |||||||||||||||||||||||||||||||
3893 | return other.d->toMSecsSinceEpoch() - d->toMSecsSinceEpoch(); executed 1175 times by 15 tests: return other.d->toMSecsSinceEpoch() - d->toMSecsSinceEpoch(); Executed by:
| 1175 | ||||||||||||||||||||||||||||||
3894 | } | - | ||||||||||||||||||||||||||||||
3895 | - | |||||||||||||||||||||||||||||||
3896 | /*! | - | ||||||||||||||||||||||||||||||
3897 | \fn QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const | - | ||||||||||||||||||||||||||||||
3898 | - | |||||||||||||||||||||||||||||||
3899 | Returns a copy of this datetime converted to the given time | - | ||||||||||||||||||||||||||||||
3900 | \a spec. | - | ||||||||||||||||||||||||||||||
3901 | - | |||||||||||||||||||||||||||||||
3902 | If \a spec is Qt::OffsetFromUTC then it is set to Qt::UTC. To set to a | - | ||||||||||||||||||||||||||||||
3903 | spec of Qt::OffsetFromUTC use toOffsetFromUtc(). | - | ||||||||||||||||||||||||||||||
3904 | - | |||||||||||||||||||||||||||||||
3905 | If \a spec is Qt::TimeZone then it is set to Qt::LocalTime, | - | ||||||||||||||||||||||||||||||
3906 | i.e. the local Time Zone. | - | ||||||||||||||||||||||||||||||
3907 | - | |||||||||||||||||||||||||||||||
3908 | Example: | - | ||||||||||||||||||||||||||||||
3909 | \snippet code/src_corelib_tools_qdatetime.cpp 16 | - | ||||||||||||||||||||||||||||||
3910 | - | |||||||||||||||||||||||||||||||
3911 | \sa timeSpec(), toTimeZone(), toUTC(), toLocalTime() | - | ||||||||||||||||||||||||||||||
3912 | */ | - | ||||||||||||||||||||||||||||||
3913 | - | |||||||||||||||||||||||||||||||
3914 | QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec) const | - | ||||||||||||||||||||||||||||||
3915 | { | - | ||||||||||||||||||||||||||||||
3916 | if (d->m_spec == spec && (spec == Qt::UTC || spec == Qt::LocalTime))
| 0-18105 | ||||||||||||||||||||||||||||||
3917 | return *this; executed 18105 times by 13 tests: return *this; Executed by:
| 18105 | ||||||||||||||||||||||||||||||
3918 | - | |||||||||||||||||||||||||||||||
3919 | if (!isValid()) {
| 505-671 | ||||||||||||||||||||||||||||||
3920 | QDateTime ret = *this; | - | ||||||||||||||||||||||||||||||
3921 | ret.setTimeSpec(spec); | - | ||||||||||||||||||||||||||||||
3922 | return ret; executed 505 times by 6 tests: return ret; Executed by:
| 505 | ||||||||||||||||||||||||||||||
3923 | } | - | ||||||||||||||||||||||||||||||
3924 | - | |||||||||||||||||||||||||||||||
3925 | return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), spec, 0); executed 671 times by 3 tests: return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), spec, 0); Executed by:
| 671 | ||||||||||||||||||||||||||||||
3926 | } | - | ||||||||||||||||||||||||||||||
3927 | - | |||||||||||||||||||||||||||||||
3928 | /*! | - | ||||||||||||||||||||||||||||||
3929 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3930 | - | |||||||||||||||||||||||||||||||
3931 | \fn QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const | - | ||||||||||||||||||||||||||||||
3932 | - | |||||||||||||||||||||||||||||||
3933 | Returns a copy of this datetime converted to a spec of Qt::OffsetFromUTC | - | ||||||||||||||||||||||||||||||
3934 | with the given \a offsetSeconds. | - | ||||||||||||||||||||||||||||||
3935 | - | |||||||||||||||||||||||||||||||
3936 | If the \a offsetSeconds equals 0 then a UTC datetime will be returned | - | ||||||||||||||||||||||||||||||
3937 | - | |||||||||||||||||||||||||||||||
3938 | \sa setOffsetFromUtc(), offsetFromUtc(), toTimeSpec() | - | ||||||||||||||||||||||||||||||
3939 | */ | - | ||||||||||||||||||||||||||||||
3940 | - | |||||||||||||||||||||||||||||||
3941 | QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const | - | ||||||||||||||||||||||||||||||
3942 | { | - | ||||||||||||||||||||||||||||||
3943 | if (d->m_spec == Qt::OffsetFromUTC && d->m_offsetFromUtc == offsetSeconds)
| 0-6 | ||||||||||||||||||||||||||||||
3944 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||||||||
3945 | - | |||||||||||||||||||||||||||||||
3946 | if (!isValid()) {
| 1-5 | ||||||||||||||||||||||||||||||
3947 | QDateTime ret = *this; | - | ||||||||||||||||||||||||||||||
3948 | ret.setOffsetFromUtc(offsetSeconds); | - | ||||||||||||||||||||||||||||||
3949 | return ret; executed 1 time by 1 test: return ret; Executed by:
| 1 | ||||||||||||||||||||||||||||||
3950 | } | - | ||||||||||||||||||||||||||||||
3951 | - | |||||||||||||||||||||||||||||||
3952 | return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), Qt::OffsetFromUTC, offsetSeconds); executed 5 times by 2 tests: return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), Qt::OffsetFromUTC, offsetSeconds); Executed by:
| 5 | ||||||||||||||||||||||||||||||
3953 | } | - | ||||||||||||||||||||||||||||||
3954 | - | |||||||||||||||||||||||||||||||
3955 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3956 | /*! | - | ||||||||||||||||||||||||||||||
3957 | \since 5.2 | - | ||||||||||||||||||||||||||||||
3958 | - | |||||||||||||||||||||||||||||||
3959 | Returns a copy of this datetime converted to the given \a timeZone | - | ||||||||||||||||||||||||||||||
3960 | - | |||||||||||||||||||||||||||||||
3961 | \sa timeZone(), toTimeSpec() | - | ||||||||||||||||||||||||||||||
3962 | */ | - | ||||||||||||||||||||||||||||||
3963 | - | |||||||||||||||||||||||||||||||
3964 | QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const | - | ||||||||||||||||||||||||||||||
3965 | { | - | ||||||||||||||||||||||||||||||
3966 | if (d->m_spec == Qt::TimeZone && d->m_timeZone == timeZone)
| 0-1 | ||||||||||||||||||||||||||||||
3967 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||||||||
3968 | - | |||||||||||||||||||||||||||||||
3969 | if (!isValid()) {
| 1 | ||||||||||||||||||||||||||||||
3970 | QDateTime ret = *this; | - | ||||||||||||||||||||||||||||||
3971 | ret.setTimeZone(timeZone); | - | ||||||||||||||||||||||||||||||
3972 | return ret; executed 1 time by 1 test: return ret; Executed by:
| 1 | ||||||||||||||||||||||||||||||
3973 | } | - | ||||||||||||||||||||||||||||||
3974 | - | |||||||||||||||||||||||||||||||
3975 | return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), timeZone); executed 1 time by 1 test: return fromMSecsSinceEpoch(d->toMSecsSinceEpoch(), timeZone); Executed by:
| 1 | ||||||||||||||||||||||||||||||
3976 | } | - | ||||||||||||||||||||||||||||||
3977 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
3978 | - | |||||||||||||||||||||||||||||||
3979 | /*! | - | ||||||||||||||||||||||||||||||
3980 | Returns \c true if this datetime is equal to the \a other datetime; | - | ||||||||||||||||||||||||||||||
3981 | otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
3982 | - | |||||||||||||||||||||||||||||||
3983 | \sa operator!=() | - | ||||||||||||||||||||||||||||||
3984 | */ | - | ||||||||||||||||||||||||||||||
3985 | - | |||||||||||||||||||||||||||||||
3986 | bool QDateTime::operator==(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
3987 | { | - | ||||||||||||||||||||||||||||||
3988 | if (d->m_spec == Qt::LocalTime
| 1270-62331 | ||||||||||||||||||||||||||||||
3989 | && other.d->m_spec == Qt::LocalTime
| 33-62298 | ||||||||||||||||||||||||||||||
3990 | && d->m_status == other.d->m_status) {
| 709-61589 | ||||||||||||||||||||||||||||||
3991 | return (d->m_msecs == other.d->m_msecs); executed 61589 times by 29 tests: return (d->m_msecs == other.d->m_msecs); Executed by:
| 61589 | ||||||||||||||||||||||||||||||
3992 | } | - | ||||||||||||||||||||||||||||||
3993 | // Convert to UTC and compare | - | ||||||||||||||||||||||||||||||
3994 | return (toMSecsSinceEpoch() == other.toMSecsSinceEpoch()); executed 2012 times by 19 tests: return (toMSecsSinceEpoch() == other.toMSecsSinceEpoch()); Executed by:
| 2012 | ||||||||||||||||||||||||||||||
3995 | } | - | ||||||||||||||||||||||||||||||
3996 | - | |||||||||||||||||||||||||||||||
3997 | /*! | - | ||||||||||||||||||||||||||||||
3998 | \fn bool QDateTime::operator!=(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
3999 | - | |||||||||||||||||||||||||||||||
4000 | Returns \c true if this datetime is different from the \a other | - | ||||||||||||||||||||||||||||||
4001 | datetime; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
4002 | - | |||||||||||||||||||||||||||||||
4003 | Two datetimes are different if either the date, the time, or the | - | ||||||||||||||||||||||||||||||
4004 | time zone components are different. | - | ||||||||||||||||||||||||||||||
4005 | - | |||||||||||||||||||||||||||||||
4006 | \sa operator==() | - | ||||||||||||||||||||||||||||||
4007 | */ | - | ||||||||||||||||||||||||||||||
4008 | - | |||||||||||||||||||||||||||||||
4009 | /*! | - | ||||||||||||||||||||||||||||||
4010 | Returns \c true if this datetime is earlier than the \a other | - | ||||||||||||||||||||||||||||||
4011 | datetime; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
4012 | */ | - | ||||||||||||||||||||||||||||||
4013 | - | |||||||||||||||||||||||||||||||
4014 | bool QDateTime::operator<(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
4015 | { | - | ||||||||||||||||||||||||||||||
4016 | if (d->m_spec == Qt::LocalTime
| 43119-58071 | ||||||||||||||||||||||||||||||
4017 | && other.d->m_spec == Qt::LocalTime
| 9-43110 | ||||||||||||||||||||||||||||||
4018 | && d->m_status == other.d->m_status) {
| 474-42636 | ||||||||||||||||||||||||||||||
4019 | return (d->m_msecs < other.d->m_msecs); executed 42636 times by 12 tests: return (d->m_msecs < other.d->m_msecs); Executed by:
| 42636 | ||||||||||||||||||||||||||||||
4020 | } | - | ||||||||||||||||||||||||||||||
4021 | // Convert to UTC and compare | - | ||||||||||||||||||||||||||||||
4022 | return (toMSecsSinceEpoch() < other.toMSecsSinceEpoch()); executed 58554 times by 11 tests: return (toMSecsSinceEpoch() < other.toMSecsSinceEpoch()); Executed by:
| 58554 | ||||||||||||||||||||||||||||||
4023 | } | - | ||||||||||||||||||||||||||||||
4024 | - | |||||||||||||||||||||||||||||||
4025 | /*! | - | ||||||||||||||||||||||||||||||
4026 | \fn bool QDateTime::operator<=(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
4027 | - | |||||||||||||||||||||||||||||||
4028 | Returns \c true if this datetime is earlier than or equal to the | - | ||||||||||||||||||||||||||||||
4029 | \a other datetime; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
4030 | */ | - | ||||||||||||||||||||||||||||||
4031 | - | |||||||||||||||||||||||||||||||
4032 | /*! | - | ||||||||||||||||||||||||||||||
4033 | \fn bool QDateTime::operator>(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
4034 | - | |||||||||||||||||||||||||||||||
4035 | Returns \c true if this datetime is later than the \a other datetime; | - | ||||||||||||||||||||||||||||||
4036 | otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
4037 | */ | - | ||||||||||||||||||||||||||||||
4038 | - | |||||||||||||||||||||||||||||||
4039 | /*! | - | ||||||||||||||||||||||||||||||
4040 | \fn bool QDateTime::operator>=(const QDateTime &other) const | - | ||||||||||||||||||||||||||||||
4041 | - | |||||||||||||||||||||||||||||||
4042 | Returns \c true if this datetime is later than or equal to the | - | ||||||||||||||||||||||||||||||
4043 | \a other datetime; otherwise returns \c false. | - | ||||||||||||||||||||||||||||||
4044 | */ | - | ||||||||||||||||||||||||||||||
4045 | - | |||||||||||||||||||||||||||||||
4046 | /*! | - | ||||||||||||||||||||||||||||||
4047 | \fn QDateTime QDateTime::currentDateTime() | - | ||||||||||||||||||||||||||||||
4048 | Returns the current datetime, as reported by the system clock, in | - | ||||||||||||||||||||||||||||||
4049 | the local time zone. | - | ||||||||||||||||||||||||||||||
4050 | - | |||||||||||||||||||||||||||||||
4051 | \sa currentDateTimeUtc(), QDate::currentDate(), QTime::currentTime(), toTimeSpec() | - | ||||||||||||||||||||||||||||||
4052 | */ | - | ||||||||||||||||||||||||||||||
4053 | - | |||||||||||||||||||||||||||||||
4054 | /*! | - | ||||||||||||||||||||||||||||||
4055 | \fn QDateTime QDateTime::currentDateTimeUtc() | - | ||||||||||||||||||||||||||||||
4056 | \since 4.7 | - | ||||||||||||||||||||||||||||||
4057 | Returns the current datetime, as reported by the system clock, in | - | ||||||||||||||||||||||||||||||
4058 | UTC. | - | ||||||||||||||||||||||||||||||
4059 | - | |||||||||||||||||||||||||||||||
4060 | \sa currentDateTime(), QDate::currentDate(), QTime::currentTime(), toTimeSpec() | - | ||||||||||||||||||||||||||||||
4061 | */ | - | ||||||||||||||||||||||||||||||
4062 | - | |||||||||||||||||||||||||||||||
4063 | /*! | - | ||||||||||||||||||||||||||||||
4064 | \fn qint64 QDateTime::currentMSecsSinceEpoch() | - | ||||||||||||||||||||||||||||||
4065 | \since 4.7 | - | ||||||||||||||||||||||||||||||
4066 | - | |||||||||||||||||||||||||||||||
4067 | Returns the number of milliseconds since 1970-01-01T00:00:00 Universal | - | ||||||||||||||||||||||||||||||
4068 | Coordinated Time. This number is like the POSIX time_t variable, but | - | ||||||||||||||||||||||||||||||
4069 | expressed in milliseconds instead. | - | ||||||||||||||||||||||||||||||
4070 | - | |||||||||||||||||||||||||||||||
4071 | \sa currentDateTime(), currentDateTimeUtc(), toTime_t(), toTimeSpec() | - | ||||||||||||||||||||||||||||||
4072 | */ | - | ||||||||||||||||||||||||||||||
4073 | - | |||||||||||||||||||||||||||||||
4074 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||||||||
4075 | static inline uint msecsFromDecomposed(int hour, int minute, int sec, int msec = 0) | - | ||||||||||||||||||||||||||||||
4076 | { | - | ||||||||||||||||||||||||||||||
4077 | return MSECS_PER_HOUR * hour + MSECS_PER_MIN * minute + 1000 * sec + msec; | - | ||||||||||||||||||||||||||||||
4078 | } | - | ||||||||||||||||||||||||||||||
4079 | - | |||||||||||||||||||||||||||||||
4080 | QDate QDate::currentDate() | - | ||||||||||||||||||||||||||||||
4081 | { | - | ||||||||||||||||||||||||||||||
4082 | QDate d; | - | ||||||||||||||||||||||||||||||
4083 | SYSTEMTIME st; | - | ||||||||||||||||||||||||||||||
4084 | memset(&st, 0, sizeof(SYSTEMTIME)); | - | ||||||||||||||||||||||||||||||
4085 | GetLocalTime(&st); | - | ||||||||||||||||||||||||||||||
4086 | d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); | - | ||||||||||||||||||||||||||||||
4087 | return d; | - | ||||||||||||||||||||||||||||||
4088 | } | - | ||||||||||||||||||||||||||||||
4089 | - | |||||||||||||||||||||||||||||||
4090 | QTime QTime::currentTime() | - | ||||||||||||||||||||||||||||||
4091 | { | - | ||||||||||||||||||||||||||||||
4092 | QTime ct; | - | ||||||||||||||||||||||||||||||
4093 | SYSTEMTIME st; | - | ||||||||||||||||||||||||||||||
4094 | memset(&st, 0, sizeof(SYSTEMTIME)); | - | ||||||||||||||||||||||||||||||
4095 | GetLocalTime(&st); | - | ||||||||||||||||||||||||||||||
4096 | ct.setHMS(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); | - | ||||||||||||||||||||||||||||||
4097 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||||||||
4098 | ct.startTick = GetTickCount() % MSECS_PER_DAY; | - | ||||||||||||||||||||||||||||||
4099 | #endif | - | ||||||||||||||||||||||||||||||
4100 | return ct; | - | ||||||||||||||||||||||||||||||
4101 | } | - | ||||||||||||||||||||||||||||||
4102 | - | |||||||||||||||||||||||||||||||
4103 | QDateTime QDateTime::currentDateTime() | - | ||||||||||||||||||||||||||||||
4104 | { | - | ||||||||||||||||||||||||||||||
4105 | QDate d; | - | ||||||||||||||||||||||||||||||
4106 | QTime t; | - | ||||||||||||||||||||||||||||||
4107 | SYSTEMTIME st; | - | ||||||||||||||||||||||||||||||
4108 | memset(&st, 0, sizeof(SYSTEMTIME)); | - | ||||||||||||||||||||||||||||||
4109 | GetLocalTime(&st); | - | ||||||||||||||||||||||||||||||
4110 | d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); | - | ||||||||||||||||||||||||||||||
4111 | t.mds = msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); | - | ||||||||||||||||||||||||||||||
4112 | return QDateTime(d, t); | - | ||||||||||||||||||||||||||||||
4113 | } | - | ||||||||||||||||||||||||||||||
4114 | - | |||||||||||||||||||||||||||||||
4115 | QDateTime QDateTime::currentDateTimeUtc() | - | ||||||||||||||||||||||||||||||
4116 | { | - | ||||||||||||||||||||||||||||||
4117 | QDate d; | - | ||||||||||||||||||||||||||||||
4118 | QTime t; | - | ||||||||||||||||||||||||||||||
4119 | SYSTEMTIME st; | - | ||||||||||||||||||||||||||||||
4120 | memset(&st, 0, sizeof(SYSTEMTIME)); | - | ||||||||||||||||||||||||||||||
4121 | GetSystemTime(&st); | - | ||||||||||||||||||||||||||||||
4122 | d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); | - | ||||||||||||||||||||||||||||||
4123 | t.mds = msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); | - | ||||||||||||||||||||||||||||||
4124 | return QDateTime(d, t, Qt::UTC); | - | ||||||||||||||||||||||||||||||
4125 | } | - | ||||||||||||||||||||||||||||||
4126 | - | |||||||||||||||||||||||||||||||
4127 | qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW | - | ||||||||||||||||||||||||||||||
4128 | { | - | ||||||||||||||||||||||||||||||
4129 | SYSTEMTIME st; | - | ||||||||||||||||||||||||||||||
4130 | memset(&st, 0, sizeof(SYSTEMTIME)); | - | ||||||||||||||||||||||||||||||
4131 | GetSystemTime(&st); | - | ||||||||||||||||||||||||||||||
4132 | - | |||||||||||||||||||||||||||||||
4133 | return msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds) + | - | ||||||||||||||||||||||||||||||
4134 | qint64(julianDayFromDate(st.wYear, st.wMonth, st.wDay) | - | ||||||||||||||||||||||||||||||
4135 | - julianDayFromDate(1970, 1, 1)) * Q_INT64_C(86400000); | - | ||||||||||||||||||||||||||||||
4136 | } | - | ||||||||||||||||||||||||||||||
4137 | - | |||||||||||||||||||||||||||||||
4138 | #elif defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||||||||
4139 | QDate QDate::currentDate() | - | ||||||||||||||||||||||||||||||
4140 | { | - | ||||||||||||||||||||||||||||||
4141 | return QDateTime::currentDateTime().date(); executed 202 times by 8 tests: return QDateTime::currentDateTime().date(); Executed by:
| 202 | ||||||||||||||||||||||||||||||
4142 | } | - | ||||||||||||||||||||||||||||||
4143 | - | |||||||||||||||||||||||||||||||
4144 | QTime QTime::currentTime() | - | ||||||||||||||||||||||||||||||
4145 | { | - | ||||||||||||||||||||||||||||||
4146 | return QDateTime::currentDateTime().time(); executed 6848830 times by 39 tests: return QDateTime::currentDateTime().time(); Executed by:
| 6848830 | ||||||||||||||||||||||||||||||
4147 | } | - | ||||||||||||||||||||||||||||||
4148 | - | |||||||||||||||||||||||||||||||
4149 | QDateTime QDateTime::currentDateTime() | - | ||||||||||||||||||||||||||||||
4150 | { | - | ||||||||||||||||||||||||||||||
4151 | return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::LocalTime); executed 6851929 times by 60 tests: return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::LocalTime); Executed by:
| 6851929 | ||||||||||||||||||||||||||||||
4152 | } | - | ||||||||||||||||||||||||||||||
4153 | - | |||||||||||||||||||||||||||||||
4154 | QDateTime QDateTime::currentDateTimeUtc() | - | ||||||||||||||||||||||||||||||
4155 | { | - | ||||||||||||||||||||||||||||||
4156 | return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::UTC); executed 3648 times by 18 tests: return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), Qt::UTC); Executed by:
| 3648 | ||||||||||||||||||||||||||||||
4157 | } | - | ||||||||||||||||||||||||||||||
4158 | - | |||||||||||||||||||||||||||||||
4159 | qint64 QDateTime::currentMSecsSinceEpoch() Q_DECL_NOTHROW | - | ||||||||||||||||||||||||||||||
4160 | { | - | ||||||||||||||||||||||||||||||
4161 | // posix compliant system | - | ||||||||||||||||||||||||||||||
4162 | // we have milliseconds | - | ||||||||||||||||||||||||||||||
4163 | struct timeval tv; | - | ||||||||||||||||||||||||||||||
4164 | gettimeofday(&tv, 0); | - | ||||||||||||||||||||||||||||||
4165 | return qint64(tv.tv_sec) * Q_INT64_C(1000) + tv.tv_usec / 1000; executed 6853721 times by 70 tests: return qint64(tv.tv_sec) * static_cast<long long>(1000LL) + tv.tv_usec / 1000; Executed by:
| 6853721 | ||||||||||||||||||||||||||||||
4166 | } | - | ||||||||||||||||||||||||||||||
4167 | - | |||||||||||||||||||||||||||||||
4168 | #else | - | ||||||||||||||||||||||||||||||
4169 | #error "What system is this?" | - | ||||||||||||||||||||||||||||||
4170 | #endif | - | ||||||||||||||||||||||||||||||
4171 | - | |||||||||||||||||||||||||||||||
4172 | /*! \fn QDateTime QDateTime::fromCFDate(CFDateRef date) | - | ||||||||||||||||||||||||||||||
4173 | \since 5.5 | - | ||||||||||||||||||||||||||||||
4174 | - | |||||||||||||||||||||||||||||||
4175 | Constructs a new QDateTime containing a copy of the CFDate \a date. | - | ||||||||||||||||||||||||||||||
4176 | - | |||||||||||||||||||||||||||||||
4177 | \sa toCFDate() | - | ||||||||||||||||||||||||||||||
4178 | */ | - | ||||||||||||||||||||||||||||||
4179 | - | |||||||||||||||||||||||||||||||
4180 | /*! \fn CFDateRef QDateTime::toCFDate() const | - | ||||||||||||||||||||||||||||||
4181 | \since 5.5 | - | ||||||||||||||||||||||||||||||
4182 | - | |||||||||||||||||||||||||||||||
4183 | Creates a CFDate from a QDateTime. The caller owns the CFDate object | - | ||||||||||||||||||||||||||||||
4184 | and is responsible for releasing it. | - | ||||||||||||||||||||||||||||||
4185 | - | |||||||||||||||||||||||||||||||
4186 | \sa fromCFDate() | - | ||||||||||||||||||||||||||||||
4187 | */ | - | ||||||||||||||||||||||||||||||
4188 | - | |||||||||||||||||||||||||||||||
4189 | /*! \fn QDateTime QDateTime::fromNSDate(const NSDate *date) | - | ||||||||||||||||||||||||||||||
4190 | \since 5.5 | - | ||||||||||||||||||||||||||||||
4191 | - | |||||||||||||||||||||||||||||||
4192 | Constructs a new QDateTime containing a copy of the NSDate \a date. | - | ||||||||||||||||||||||||||||||
4193 | - | |||||||||||||||||||||||||||||||
4194 | \sa toNSDate() | - | ||||||||||||||||||||||||||||||
4195 | */ | - | ||||||||||||||||||||||||||||||
4196 | - | |||||||||||||||||||||||||||||||
4197 | /*! \fn NSDate QDateTime::toNSDate() const | - | ||||||||||||||||||||||||||||||
4198 | \since 5.5 | - | ||||||||||||||||||||||||||||||
4199 | - | |||||||||||||||||||||||||||||||
4200 | Creates an NSDate from a QDateTime. The NSDate object is autoreleased. | - | ||||||||||||||||||||||||||||||
4201 | - | |||||||||||||||||||||||||||||||
4202 | \sa fromNSDate() | - | ||||||||||||||||||||||||||||||
4203 | */ | - | ||||||||||||||||||||||||||||||
4204 | - | |||||||||||||||||||||||||||||||
4205 | /*! | - | ||||||||||||||||||||||||||||||
4206 | \since 4.2 | - | ||||||||||||||||||||||||||||||
4207 | - | |||||||||||||||||||||||||||||||
4208 | Returns a datetime whose date and time are the number of \a seconds | - | ||||||||||||||||||||||||||||||
4209 | that have passed since 1970-01-01T00:00:00, Coordinated Universal | - | ||||||||||||||||||||||||||||||
4210 | Time (Qt::UTC) and converted to Qt::LocalTime. On systems that do not | - | ||||||||||||||||||||||||||||||
4211 | support time zones, the time will be set as if local time were Qt::UTC. | - | ||||||||||||||||||||||||||||||
4212 | - | |||||||||||||||||||||||||||||||
4213 | \sa toTime_t(), setTime_t() | - | ||||||||||||||||||||||||||||||
4214 | */ | - | ||||||||||||||||||||||||||||||
4215 | QDateTime QDateTime::fromTime_t(uint seconds) | - | ||||||||||||||||||||||||||||||
4216 | { | - | ||||||||||||||||||||||||||||||
4217 | return fromMSecsSinceEpoch((qint64)seconds * 1000, Qt::LocalTime); executed 6412 times by 44 tests: return fromMSecsSinceEpoch((qint64)seconds * 1000, Qt::LocalTime); Executed by:
| 6412 | ||||||||||||||||||||||||||||||
4218 | } | - | ||||||||||||||||||||||||||||||
4219 | - | |||||||||||||||||||||||||||||||
4220 | /*! | - | ||||||||||||||||||||||||||||||
4221 | \since 5.2 | - | ||||||||||||||||||||||||||||||
4222 | - | |||||||||||||||||||||||||||||||
4223 | Returns a datetime whose date and time are the number of \a seconds | - | ||||||||||||||||||||||||||||||
4224 | that have passed since 1970-01-01T00:00:00, Coordinated Universal | - | ||||||||||||||||||||||||||||||
4225 | Time (Qt::UTC) and converted to the given \a spec. | - | ||||||||||||||||||||||||||||||
4226 | - | |||||||||||||||||||||||||||||||
4227 | If the \a spec is not Qt::OffsetFromUTC then the \a offsetSeconds will be | - | ||||||||||||||||||||||||||||||
4228 | ignored. If the \a spec is Qt::OffsetFromUTC and the \a offsetSeconds is 0 | - | ||||||||||||||||||||||||||||||
4229 | then the spec will be set to Qt::UTC, i.e. an offset of 0 seconds. | - | ||||||||||||||||||||||||||||||
4230 | - | |||||||||||||||||||||||||||||||
4231 | \sa toTime_t(), setTime_t() | - | ||||||||||||||||||||||||||||||
4232 | */ | - | ||||||||||||||||||||||||||||||
4233 | QDateTime QDateTime::fromTime_t(uint seconds, Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||||||||
4234 | { | - | ||||||||||||||||||||||||||||||
4235 | return fromMSecsSinceEpoch((qint64)seconds * 1000, spec, offsetSeconds); never executed: return fromMSecsSinceEpoch((qint64)seconds * 1000, spec, offsetSeconds); | 0 | ||||||||||||||||||||||||||||||
4236 | } | - | ||||||||||||||||||||||||||||||
4237 | - | |||||||||||||||||||||||||||||||
4238 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4239 | /*! | - | ||||||||||||||||||||||||||||||
4240 | \since 5.2 | - | ||||||||||||||||||||||||||||||
4241 | - | |||||||||||||||||||||||||||||||
4242 | Returns a datetime whose date and time are the number of \a seconds | - | ||||||||||||||||||||||||||||||
4243 | that have passed since 1970-01-01T00:00:00, Coordinated Universal | - | ||||||||||||||||||||||||||||||
4244 | Time (Qt::UTC) and with the given \a timeZone. | - | ||||||||||||||||||||||||||||||
4245 | - | |||||||||||||||||||||||||||||||
4246 | \sa toTime_t(), setTime_t() | - | ||||||||||||||||||||||||||||||
4247 | */ | - | ||||||||||||||||||||||||||||||
4248 | QDateTime QDateTime::fromTime_t(uint seconds, const QTimeZone &timeZone) | - | ||||||||||||||||||||||||||||||
4249 | { | - | ||||||||||||||||||||||||||||||
4250 | return fromMSecsSinceEpoch((qint64)seconds * 1000, timeZone); executed 1 time by 1 test: return fromMSecsSinceEpoch((qint64)seconds * 1000, timeZone); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4251 | } | - | ||||||||||||||||||||||||||||||
4252 | #endif | - | ||||||||||||||||||||||||||||||
4253 | - | |||||||||||||||||||||||||||||||
4254 | /*! | - | ||||||||||||||||||||||||||||||
4255 | \since 4.7 | - | ||||||||||||||||||||||||||||||
4256 | - | |||||||||||||||||||||||||||||||
4257 | Returns a datetime whose date and time are the number of milliseconds, \a msecs, | - | ||||||||||||||||||||||||||||||
4258 | that have passed since 1970-01-01T00:00:00.000, Coordinated Universal | - | ||||||||||||||||||||||||||||||
4259 | Time (Qt::UTC), and converted to Qt::LocalTime. On systems that do not | - | ||||||||||||||||||||||||||||||
4260 | support time zones, the time will be set as if local time were Qt::UTC. | - | ||||||||||||||||||||||||||||||
4261 | - | |||||||||||||||||||||||||||||||
4262 | Note that there are possible values for \a msecs that lie outside the valid | - | ||||||||||||||||||||||||||||||
4263 | range of QDateTime, both negative and positive. The behavior of this | - | ||||||||||||||||||||||||||||||
4264 | function is undefined for those values. | - | ||||||||||||||||||||||||||||||
4265 | - | |||||||||||||||||||||||||||||||
4266 | \sa toTime_t(), setTime_t() | - | ||||||||||||||||||||||||||||||
4267 | */ | - | ||||||||||||||||||||||||||||||
4268 | QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs) | - | ||||||||||||||||||||||||||||||
4269 | { | - | ||||||||||||||||||||||||||||||
4270 | return fromMSecsSinceEpoch(msecs, Qt::LocalTime); never executed: return fromMSecsSinceEpoch(msecs, Qt::LocalTime); | 0 | ||||||||||||||||||||||||||||||
4271 | } | - | ||||||||||||||||||||||||||||||
4272 | - | |||||||||||||||||||||||||||||||
4273 | /*! | - | ||||||||||||||||||||||||||||||
4274 | \since 5.2 | - | ||||||||||||||||||||||||||||||
4275 | - | |||||||||||||||||||||||||||||||
4276 | Returns a datetime whose date and time are the number of milliseconds \a msecs | - | ||||||||||||||||||||||||||||||
4277 | that have passed since 1970-01-01T00:00:00.000, Coordinated Universal | - | ||||||||||||||||||||||||||||||
4278 | Time (Qt::UTC) and converted to the given \a spec. | - | ||||||||||||||||||||||||||||||
4279 | - | |||||||||||||||||||||||||||||||
4280 | Note that there are possible values for \a msecs that lie outside the valid | - | ||||||||||||||||||||||||||||||
4281 | range of QDateTime, both negative and positive. The behavior of this | - | ||||||||||||||||||||||||||||||
4282 | function is undefined for those values. | - | ||||||||||||||||||||||||||||||
4283 | - | |||||||||||||||||||||||||||||||
4284 | If the \a spec is not Qt::OffsetFromUTC then the \a offsetSeconds will be | - | ||||||||||||||||||||||||||||||
4285 | ignored. If the \a spec is Qt::OffsetFromUTC and the \a offsetSeconds is 0 | - | ||||||||||||||||||||||||||||||
4286 | then the spec will be set to Qt::UTC, i.e. an offset of 0 seconds. | - | ||||||||||||||||||||||||||||||
4287 | - | |||||||||||||||||||||||||||||||
4288 | If \a spec is Qt::TimeZone then the spec will be set to Qt::LocalTime, | - | ||||||||||||||||||||||||||||||
4289 | i.e. the current system time zone. | - | ||||||||||||||||||||||||||||||
4290 | - | |||||||||||||||||||||||||||||||
4291 | \sa fromTime_t() | - | ||||||||||||||||||||||||||||||
4292 | */ | - | ||||||||||||||||||||||||||||||
4293 | QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds) | - | ||||||||||||||||||||||||||||||
4294 | { | - | ||||||||||||||||||||||||||||||
4295 | QDateTime dt; | - | ||||||||||||||||||||||||||||||
4296 | dt.d->setTimeSpec(spec, offsetSeconds); | - | ||||||||||||||||||||||||||||||
4297 | dt.setMSecsSinceEpoch(msecs); | - | ||||||||||||||||||||||||||||||
4298 | return dt; executed 6867723 times by 99 tests: return dt; Executed by:
| 6867723 | ||||||||||||||||||||||||||||||
4299 | } | - | ||||||||||||||||||||||||||||||
4300 | - | |||||||||||||||||||||||||||||||
4301 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4302 | /*! | - | ||||||||||||||||||||||||||||||
4303 | \since 5.2 | - | ||||||||||||||||||||||||||||||
4304 | - | |||||||||||||||||||||||||||||||
4305 | Returns a datetime whose date and time are the number of milliseconds \a msecs | - | ||||||||||||||||||||||||||||||
4306 | that have passed since 1970-01-01T00:00:00.000, Coordinated Universal | - | ||||||||||||||||||||||||||||||
4307 | Time (Qt::UTC) and with the given \a timeZone. | - | ||||||||||||||||||||||||||||||
4308 | - | |||||||||||||||||||||||||||||||
4309 | \sa fromTime_t() | - | ||||||||||||||||||||||||||||||
4310 | */ | - | ||||||||||||||||||||||||||||||
4311 | QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone) | - | ||||||||||||||||||||||||||||||
4312 | { | - | ||||||||||||||||||||||||||||||
4313 | QDateTime dt; | - | ||||||||||||||||||||||||||||||
4314 | dt.setTimeZone(timeZone); | - | ||||||||||||||||||||||||||||||
4315 | dt.setMSecsSinceEpoch(msecs); | - | ||||||||||||||||||||||||||||||
4316 | return dt; executed 10 times by 1 test: return dt; Executed by:
| 10 | ||||||||||||||||||||||||||||||
4317 | } | - | ||||||||||||||||||||||||||||||
4318 | #endif | - | ||||||||||||||||||||||||||||||
4319 | - | |||||||||||||||||||||||||||||||
4320 | #if QT_DEPRECATED_SINCE(5, 2) | - | ||||||||||||||||||||||||||||||
4321 | /*! | - | ||||||||||||||||||||||||||||||
4322 | \since 4.4 | - | ||||||||||||||||||||||||||||||
4323 | \internal | - | ||||||||||||||||||||||||||||||
4324 | \obsolete | - | ||||||||||||||||||||||||||||||
4325 | - | |||||||||||||||||||||||||||||||
4326 | This method was added in 4.4 but never documented as public. It was replaced | - | ||||||||||||||||||||||||||||||
4327 | in 5.2 with public method setOffsetFromUtc() for consistency with QTimeZone. | - | ||||||||||||||||||||||||||||||
4328 | - | |||||||||||||||||||||||||||||||
4329 | This method should never be made public. | - | ||||||||||||||||||||||||||||||
4330 | - | |||||||||||||||||||||||||||||||
4331 | \sa setOffsetFromUtc() | - | ||||||||||||||||||||||||||||||
4332 | */ | - | ||||||||||||||||||||||||||||||
4333 | void QDateTime::setUtcOffset(int seconds) | - | ||||||||||||||||||||||||||||||
4334 | { | - | ||||||||||||||||||||||||||||||
4335 | setOffsetFromUtc(seconds); | - | ||||||||||||||||||||||||||||||
4336 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||||||||
4337 | - | |||||||||||||||||||||||||||||||
4338 | /*! | - | ||||||||||||||||||||||||||||||
4339 | \since 4.4 | - | ||||||||||||||||||||||||||||||
4340 | \internal | - | ||||||||||||||||||||||||||||||
4341 | \obsolete | - | ||||||||||||||||||||||||||||||
4342 | - | |||||||||||||||||||||||||||||||
4343 | This method was added in 4.4 but never documented as public. It was replaced | - | ||||||||||||||||||||||||||||||
4344 | in 5.1 with public method offsetFromUTC() for consistency with QTimeZone. | - | ||||||||||||||||||||||||||||||
4345 | - | |||||||||||||||||||||||||||||||
4346 | This method should never be made public. | - | ||||||||||||||||||||||||||||||
4347 | - | |||||||||||||||||||||||||||||||
4348 | \sa offsetFromUTC() | - | ||||||||||||||||||||||||||||||
4349 | */ | - | ||||||||||||||||||||||||||||||
4350 | int QDateTime::utcOffset() const | - | ||||||||||||||||||||||||||||||
4351 | { | - | ||||||||||||||||||||||||||||||
4352 | return offsetFromUtc(); executed 20 times by 1 test: return offsetFromUtc(); Executed by:
| 20 | ||||||||||||||||||||||||||||||
4353 | } | - | ||||||||||||||||||||||||||||||
4354 | #endif // QT_DEPRECATED_SINCE | - | ||||||||||||||||||||||||||||||
4355 | - | |||||||||||||||||||||||||||||||
4356 | #ifndef QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
4357 | - | |||||||||||||||||||||||||||||||
4358 | /*! | - | ||||||||||||||||||||||||||||||
4359 | \fn QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format) | - | ||||||||||||||||||||||||||||||
4360 | - | |||||||||||||||||||||||||||||||
4361 | Returns the QDateTime represented by the \a string, using the | - | ||||||||||||||||||||||||||||||
4362 | \a format given, or an invalid datetime if this is not possible. | - | ||||||||||||||||||||||||||||||
4363 | - | |||||||||||||||||||||||||||||||
4364 | Note for Qt::TextDate: It is recommended that you use the | - | ||||||||||||||||||||||||||||||
4365 | English short month names (e.g. "Jan"). Although localized month | - | ||||||||||||||||||||||||||||||
4366 | names can also be used, they depend on the user's locale settings. | - | ||||||||||||||||||||||||||||||
4367 | - | |||||||||||||||||||||||||||||||
4368 | \sa toString(), QLocale::toDateTime() | - | ||||||||||||||||||||||||||||||
4369 | */ | - | ||||||||||||||||||||||||||||||
4370 | QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format) | - | ||||||||||||||||||||||||||||||
4371 | { | - | ||||||||||||||||||||||||||||||
4372 | if (string.isEmpty())
| 5-147 | ||||||||||||||||||||||||||||||
4373 | return QDateTime(); executed 5 times by 1 test: return QDateTime(); Executed by:
| 5 | ||||||||||||||||||||||||||||||
4374 | - | |||||||||||||||||||||||||||||||
4375 | switch (format) { | - | ||||||||||||||||||||||||||||||
4376 | case Qt::SystemLocaleDate: executed 1 time by 1 test: case Qt::SystemLocaleDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4377 | case Qt::SystemLocaleShortDate: executed 1 time by 1 test: case Qt::SystemLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4378 | return QLocale::system().toDateTime(string, QLocale::ShortFormat); executed 2 times by 1 test: return QLocale::system().toDateTime(string, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
4379 | case Qt::SystemLocaleLongDate: executed 1 time by 1 test: case Qt::SystemLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4380 | return QLocale::system().toDateTime(string, QLocale::LongFormat); executed 1 time by 1 test: return QLocale::system().toDateTime(string, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4381 | case Qt::LocaleDate: executed 1 time by 1 test: case Qt::LocaleDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4382 | case Qt::DefaultLocaleShortDate: executed 1 time by 1 test: case Qt::DefaultLocaleShortDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4383 | return QLocale().toDateTime(string, QLocale::ShortFormat); executed 2 times by 1 test: return QLocale().toDateTime(string, QLocale::ShortFormat); Executed by:
| 2 | ||||||||||||||||||||||||||||||
4384 | case Qt::DefaultLocaleLongDate: executed 1 time by 1 test: case Qt::DefaultLocaleLongDate: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4385 | return QLocale().toDateTime(string, QLocale::LongFormat); executed 1 time by 1 test: return QLocale().toDateTime(string, QLocale::LongFormat); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4386 | case Qt::RFC2822Date: { executed 30 times by 1 test: case Qt::RFC2822Date: Executed by:
| 30 | ||||||||||||||||||||||||||||||
4387 | const ParsedRfcDateTime rfc = rfcDateImpl(string); | - | ||||||||||||||||||||||||||||||
4388 | - | |||||||||||||||||||||||||||||||
4389 | if (!rfc.date.isValid() || !rfc.time.isValid())
| 3-19 | ||||||||||||||||||||||||||||||
4390 | return QDateTime(); executed 14 times by 1 test: return QDateTime(); Executed by:
| 14 | ||||||||||||||||||||||||||||||
4391 | - | |||||||||||||||||||||||||||||||
4392 | QDateTime dateTime(rfc.date, rfc.time, Qt::UTC); | - | ||||||||||||||||||||||||||||||
4393 | dateTime.setOffsetFromUtc(rfc.utcOffset); | - | ||||||||||||||||||||||||||||||
4394 | return dateTime; executed 16 times by 1 test: return dateTime; Executed by:
| 16 | ||||||||||||||||||||||||||||||
4395 | } | - | ||||||||||||||||||||||||||||||
4396 | case Qt::ISODate: { executed 69 times by 4 tests: case Qt::ISODate: Executed by:
| 69 | ||||||||||||||||||||||||||||||
4397 | const int size = string.size(); | - | ||||||||||||||||||||||||||||||
4398 | if (size < 10)
| 4-65 | ||||||||||||||||||||||||||||||
4399 | return QDateTime(); executed 4 times by 1 test: return QDateTime(); Executed by:
| 4 | ||||||||||||||||||||||||||||||
4400 | - | |||||||||||||||||||||||||||||||
4401 | QStringRef isoString(&string); | - | ||||||||||||||||||||||||||||||
4402 | Qt::TimeSpec spec = Qt::LocalTime; | - | ||||||||||||||||||||||||||||||
4403 | - | |||||||||||||||||||||||||||||||
4404 | QDate date = QDate::fromString(string.left(10), Qt::ISODate); | - | ||||||||||||||||||||||||||||||
4405 | if (!date.isValid())
| 7-58 | ||||||||||||||||||||||||||||||
4406 | return QDateTime(); executed 7 times by 2 tests: return QDateTime(); Executed by:
| 7 | ||||||||||||||||||||||||||||||
4407 | if (size == 10)
| 1-57 | ||||||||||||||||||||||||||||||
4408 | return QDateTime(date); executed 1 time by 1 test: return QDateTime(date); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4409 | - | |||||||||||||||||||||||||||||||
4410 | isoString = isoString.right(isoString.length() - 11); | - | ||||||||||||||||||||||||||||||
4411 | int offset = 0; | - | ||||||||||||||||||||||||||||||
4412 | // Check end of string for Time Zone definition, either Z for UTC or [+-]HH:mm for Offset | - | ||||||||||||||||||||||||||||||
4413 | if (isoString.endsWith(QLatin1Char('Z'))) {
| 7-50 | ||||||||||||||||||||||||||||||
4414 | spec = Qt::UTC; | - | ||||||||||||||||||||||||||||||
4415 | isoString = isoString.left(isoString.size() - 1); | - | ||||||||||||||||||||||||||||||
4416 | } else { executed 7 times by 2 tests: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||
4417 | // the loop below is faster but functionally equal to: | - | ||||||||||||||||||||||||||||||
4418 | // const int signIndex = isoString.indexOf(QRegExp(QStringLiteral("[+-]"))); | - | ||||||||||||||||||||||||||||||
4419 | int signIndex = isoString.size() - 1; | - | ||||||||||||||||||||||||||||||
4420 | bool found = false; | - | ||||||||||||||||||||||||||||||
4421 | { | - | ||||||||||||||||||||||||||||||
4422 | const QChar plus = QLatin1Char('+'); | - | ||||||||||||||||||||||||||||||
4423 | const QChar minus = QLatin1Char('-'); | - | ||||||||||||||||||||||||||||||
4424 | do { | - | ||||||||||||||||||||||||||||||
4425 | QChar character(isoString.at(signIndex)); | - | ||||||||||||||||||||||||||||||
4426 | found = character == plus || character == minus;
| 6-414 | ||||||||||||||||||||||||||||||
4427 | } while (--signIndex >= 0 && !found); executed 420 times by 4 tests: end of block Executed by:
| 14-420 | ||||||||||||||||||||||||||||||
4428 | ++signIndex; | - | ||||||||||||||||||||||||||||||
4429 | } | - | ||||||||||||||||||||||||||||||
4430 | - | |||||||||||||||||||||||||||||||
4431 | if (found) {
| 14-36 | ||||||||||||||||||||||||||||||
4432 | bool ok; | - | ||||||||||||||||||||||||||||||
4433 | offset = fromOffsetString(isoString.mid(signIndex), &ok); | - | ||||||||||||||||||||||||||||||
4434 | if (!ok)
| 0-14 | ||||||||||||||||||||||||||||||
4435 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||||||||
4436 | isoString = isoString.left(signIndex); | - | ||||||||||||||||||||||||||||||
4437 | spec = Qt::OffsetFromUTC; | - | ||||||||||||||||||||||||||||||
4438 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||||||||||||||||||||
4439 | } executed 50 times by 4 tests: end of block Executed by:
| 50 | ||||||||||||||||||||||||||||||
4440 | - | |||||||||||||||||||||||||||||||
4441 | // Might be end of day (24:00, including variants), which QTime considers invalid. | - | ||||||||||||||||||||||||||||||
4442 | // ISO 8601 (section 4.2.3) says that 24:00 is equivalent to 00:00 the next day. | - | ||||||||||||||||||||||||||||||
4443 | bool isMidnight24 = false; | - | ||||||||||||||||||||||||||||||
4444 | QTime time = fromIsoTimeString(isoString, Qt::ISODate, &isMidnight24); | - | ||||||||||||||||||||||||||||||
4445 | if (!time.isValid())
| 0-57 | ||||||||||||||||||||||||||||||
4446 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||||||||
4447 | if (isMidnight24)
| 5-52 | ||||||||||||||||||||||||||||||
4448 | date = date.addDays(1); executed 5 times by 1 test: date = date.addDays(1); Executed by:
| 5 | ||||||||||||||||||||||||||||||
4449 | return QDateTime(date, time, spec, offset); executed 57 times by 4 tests: return QDateTime(date, time, spec, offset); Executed by:
| 57 | ||||||||||||||||||||||||||||||
4450 | } | - | ||||||||||||||||||||||||||||||
4451 | #if !defined(QT_NO_TEXTDATE) | - | ||||||||||||||||||||||||||||||
4452 | case Qt::TextDate: { executed 42 times by 3 tests: case Qt::TextDate: Executed by:
| 42 | ||||||||||||||||||||||||||||||
4453 | QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||||||||
4454 | - | |||||||||||||||||||||||||||||||
4455 | if ((parts.count() < 5) || (parts.count() > 6))
| 1-41 | ||||||||||||||||||||||||||||||
4456 | return QDateTime(); executed 2 times by 1 test: return QDateTime(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
4457 | - | |||||||||||||||||||||||||||||||
4458 | // Accept "Sun Dec 1 13:02:00 1974" and "Sun 1. Dec 13:02:00 1974" | - | ||||||||||||||||||||||||||||||
4459 | int month = 0; | - | ||||||||||||||||||||||||||||||
4460 | int day = 0; | - | ||||||||||||||||||||||||||||||
4461 | bool ok = false; | - | ||||||||||||||||||||||||||||||
4462 | - | |||||||||||||||||||||||||||||||
4463 | // First try month then day | - | ||||||||||||||||||||||||||||||
4464 | month = fromShortMonthName(parts.at(1)); | - | ||||||||||||||||||||||||||||||
4465 | if (month)
| 0-40 | ||||||||||||||||||||||||||||||
4466 | day = parts.at(2).toInt(); executed 40 times by 3 tests: day = parts.at(2).toInt(); Executed by:
| 40 | ||||||||||||||||||||||||||||||
4467 | - | |||||||||||||||||||||||||||||||
4468 | // If failed try day then month | - | ||||||||||||||||||||||||||||||
4469 | if (!month || !day) {
| 0-40 | ||||||||||||||||||||||||||||||
4470 | month = fromShortMonthName(parts.at(2)); | - | ||||||||||||||||||||||||||||||
4471 | if (month) {
| 0-14 | ||||||||||||||||||||||||||||||
4472 | QStringRef dayStr = parts.at(1); | - | ||||||||||||||||||||||||||||||
4473 | if (dayStr.endsWith(QLatin1Char('.'))) {
| 2-12 | ||||||||||||||||||||||||||||||
4474 | dayStr = dayStr.left(dayStr.size() - 1); | - | ||||||||||||||||||||||||||||||
4475 | day = dayStr.toInt(); | - | ||||||||||||||||||||||||||||||
4476 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||||||||||||||
4477 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||||||||
4478 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||||||||||||||
4479 | - | |||||||||||||||||||||||||||||||
4480 | // If both failed, give up | - | ||||||||||||||||||||||||||||||
4481 | if (!month || !day)
| 0-40 | ||||||||||||||||||||||||||||||
4482 | return QDateTime(); executed 3 times by 1 test: return QDateTime(); Executed by:
| 3 | ||||||||||||||||||||||||||||||
4483 | - | |||||||||||||||||||||||||||||||
4484 | // Year can be before or after time, "Sun Dec 1 1974 13:02:00" or "Sun Dec 1 13:02:00 1974" | - | ||||||||||||||||||||||||||||||
4485 | // Guess which by looking for ':' in the time | - | ||||||||||||||||||||||||||||||
4486 | int year = 0; | - | ||||||||||||||||||||||||||||||
4487 | int yearPart = 0; | - | ||||||||||||||||||||||||||||||
4488 | int timePart = 0; | - | ||||||||||||||||||||||||||||||
4489 | if (parts.at(3).contains(QLatin1Char(':'))) {
| 14-23 | ||||||||||||||||||||||||||||||
4490 | yearPart = 4; | - | ||||||||||||||||||||||||||||||
4491 | timePart = 3; | - | ||||||||||||||||||||||||||||||
4492 | } else if (parts.at(4).contains(QLatin1Char(':'))) { executed 23 times by 3 tests: end of block Executed by:
| 1-23 | ||||||||||||||||||||||||||||||
4493 | yearPart = 3; | - | ||||||||||||||||||||||||||||||
4494 | timePart = 4; | - | ||||||||||||||||||||||||||||||
4495 | } else { executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||||||||||||||
4496 | return QDateTime(); executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4497 | } | - | ||||||||||||||||||||||||||||||
4498 | - | |||||||||||||||||||||||||||||||
4499 | year = parts.at(yearPart).toInt(&ok); | - | ||||||||||||||||||||||||||||||
4500 | if (!ok)
| 2-34 | ||||||||||||||||||||||||||||||
4501 | return QDateTime(); executed 2 times by 1 test: return QDateTime(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
4502 | - | |||||||||||||||||||||||||||||||
4503 | QDate date(year, month, day); | - | ||||||||||||||||||||||||||||||
4504 | if (!date.isValid())
| 2-32 | ||||||||||||||||||||||||||||||
4505 | return QDateTime(); executed 2 times by 1 test: return QDateTime(); Executed by:
| 2 | ||||||||||||||||||||||||||||||
4506 | - | |||||||||||||||||||||||||||||||
4507 | QVector<QStringRef> timeParts = parts.at(timePart).split(QLatin1Char(':')); | - | ||||||||||||||||||||||||||||||
4508 | if (timeParts.count() < 2 || timeParts.count() > 3)
| 0-32 | ||||||||||||||||||||||||||||||
4509 | return QDateTime(); executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4510 | - | |||||||||||||||||||||||||||||||
4511 | int hour = timeParts.at(0).toInt(&ok); | - | ||||||||||||||||||||||||||||||
4512 | if (!ok)
| 1-30 | ||||||||||||||||||||||||||||||
4513 | return QDateTime(); executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4514 | - | |||||||||||||||||||||||||||||||
4515 | int minute = timeParts.at(1).toInt(&ok); | - | ||||||||||||||||||||||||||||||
4516 | if (!ok)
| 1-29 | ||||||||||||||||||||||||||||||
4517 | return QDateTime(); executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4518 | - | |||||||||||||||||||||||||||||||
4519 | int second = 0; | - | ||||||||||||||||||||||||||||||
4520 | int millisecond = 0; | - | ||||||||||||||||||||||||||||||
4521 | if (timeParts.count() > 2) {
| 1-28 | ||||||||||||||||||||||||||||||
4522 | QVector<QStringRef> secondParts = timeParts.at(2).split(QLatin1Char('.')); | - | ||||||||||||||||||||||||||||||
4523 | if (secondParts.size() > 2) {
| 0-28 | ||||||||||||||||||||||||||||||
4524 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||||||||
4525 | } | - | ||||||||||||||||||||||||||||||
4526 | - | |||||||||||||||||||||||||||||||
4527 | second = secondParts.first().toInt(&ok); | - | ||||||||||||||||||||||||||||||
4528 | if (!ok) {
| 1-27 | ||||||||||||||||||||||||||||||
4529 | return QDateTime(); executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4530 | } | - | ||||||||||||||||||||||||||||||
4531 | - | |||||||||||||||||||||||||||||||
4532 | if (secondParts.size() > 1) {
| 1-26 | ||||||||||||||||||||||||||||||
4533 | millisecond = secondParts.last().toInt(&ok); | - | ||||||||||||||||||||||||||||||
4534 | if (!ok) {
| 0-1 | ||||||||||||||||||||||||||||||
4535 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||||||||
4536 | } | - | ||||||||||||||||||||||||||||||
4537 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||
4538 | } executed 27 times by 3 tests: end of block Executed by:
| 27 | ||||||||||||||||||||||||||||||
4539 | - | |||||||||||||||||||||||||||||||
4540 | QTime time(hour, minute, second, millisecond); | - | ||||||||||||||||||||||||||||||
4541 | if (!time.isValid())
| 0-28 | ||||||||||||||||||||||||||||||
4542 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||||||||
4543 | - | |||||||||||||||||||||||||||||||
4544 | if (parts.count() == 5)
| 13-15 | ||||||||||||||||||||||||||||||
4545 | return QDateTime(date, time, Qt::LocalTime); executed 15 times by 3 tests: return QDateTime(date, time, Qt::LocalTime); Executed by:
| 15 | ||||||||||||||||||||||||||||||
4546 | - | |||||||||||||||||||||||||||||||
4547 | QStringRef tz = parts.at(5); | - | ||||||||||||||||||||||||||||||
4548 | if (!tz.startsWith(QLatin1String("GMT"), Qt::CaseInsensitive))
| 1-12 | ||||||||||||||||||||||||||||||
4549 | return QDateTime(); executed 1 time by 1 test: return QDateTime(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4550 | tz = tz.mid(3); | - | ||||||||||||||||||||||||||||||
4551 | if (!tz.isEmpty()) {
| 3-9 | ||||||||||||||||||||||||||||||
4552 | int offset = fromOffsetString(tz, &ok); | - | ||||||||||||||||||||||||||||||
4553 | if (!ok)
| 4-5 | ||||||||||||||||||||||||||||||
4554 | return QDateTime(); executed 4 times by 1 test: return QDateTime(); Executed by:
| 4 | ||||||||||||||||||||||||||||||
4555 | return QDateTime(date, time, Qt::OffsetFromUTC, offset); executed 5 times by 1 test: return QDateTime(date, time, Qt::OffsetFromUTC, offset); Executed by:
| 5 | ||||||||||||||||||||||||||||||
4556 | } else { | - | ||||||||||||||||||||||||||||||
4557 | return QDateTime(date, time, Qt::UTC); executed 3 times by 1 test: return QDateTime(date, time, Qt::UTC); Executed by:
| 3 | ||||||||||||||||||||||||||||||
4558 | } | - | ||||||||||||||||||||||||||||||
4559 | } | - | ||||||||||||||||||||||||||||||
4560 | #endif //QT_NO_TEXTDATE | - | ||||||||||||||||||||||||||||||
4561 | } | - | ||||||||||||||||||||||||||||||
4562 | - | |||||||||||||||||||||||||||||||
4563 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||||||||||||||||||||||||||
4564 | } | - | ||||||||||||||||||||||||||||||
4565 | - | |||||||||||||||||||||||||||||||
4566 | /*! | - | ||||||||||||||||||||||||||||||
4567 | \fn QDateTime::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||||||||
4568 | - | |||||||||||||||||||||||||||||||
4569 | Returns the QDateTime represented by the \a string, using the \a | - | ||||||||||||||||||||||||||||||
4570 | format given, or an invalid datetime if the string cannot be parsed. | - | ||||||||||||||||||||||||||||||
4571 | - | |||||||||||||||||||||||||||||||
4572 | These expressions may be used for the date part of the format string: | - | ||||||||||||||||||||||||||||||
4573 | - | |||||||||||||||||||||||||||||||
4574 | \table | - | ||||||||||||||||||||||||||||||
4575 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
4576 | \row \li d \li the day as number without a leading zero (1 to 31) | - | ||||||||||||||||||||||||||||||
4577 | \row \li dd \li the day as number with a leading zero (01 to 31) | - | ||||||||||||||||||||||||||||||
4578 | \row \li ddd | - | ||||||||||||||||||||||||||||||
4579 | \li the abbreviated localized day name (e.g. 'Mon' to 'Sun'). | - | ||||||||||||||||||||||||||||||
4580 | Uses QDate::shortDayName(). | - | ||||||||||||||||||||||||||||||
4581 | \row \li dddd | - | ||||||||||||||||||||||||||||||
4582 | \li the long localized day name (e.g. 'Monday' to 'Sunday'). | - | ||||||||||||||||||||||||||||||
4583 | Uses QDate::longDayName(). | - | ||||||||||||||||||||||||||||||
4584 | \row \li M \li the month as number without a leading zero (1-12) | - | ||||||||||||||||||||||||||||||
4585 | \row \li MM \li the month as number with a leading zero (01-12) | - | ||||||||||||||||||||||||||||||
4586 | \row \li MMM | - | ||||||||||||||||||||||||||||||
4587 | \li the abbreviated localized month name (e.g. 'Jan' to 'Dec'). | - | ||||||||||||||||||||||||||||||
4588 | Uses QDate::shortMonthName(). | - | ||||||||||||||||||||||||||||||
4589 | \row \li MMMM | - | ||||||||||||||||||||||||||||||
4590 | \li the long localized month name (e.g. 'January' to 'December'). | - | ||||||||||||||||||||||||||||||
4591 | Uses QDate::longMonthName(). | - | ||||||||||||||||||||||||||||||
4592 | \row \li yy \li the year as two digit number (00-99) | - | ||||||||||||||||||||||||||||||
4593 | \row \li yyyy \li the year as four digit number | - | ||||||||||||||||||||||||||||||
4594 | \endtable | - | ||||||||||||||||||||||||||||||
4595 | - | |||||||||||||||||||||||||||||||
4596 | \note Unlike the other version of this function, day and month names must | - | ||||||||||||||||||||||||||||||
4597 | be given in the user's local language. It is only possible to use the English | - | ||||||||||||||||||||||||||||||
4598 | names if the user's language is English. | - | ||||||||||||||||||||||||||||||
4599 | - | |||||||||||||||||||||||||||||||
4600 | These expressions may be used for the time part of the format string: | - | ||||||||||||||||||||||||||||||
4601 | - | |||||||||||||||||||||||||||||||
4602 | \table | - | ||||||||||||||||||||||||||||||
4603 | \header \li Expression \li Output | - | ||||||||||||||||||||||||||||||
4604 | \row \li h | - | ||||||||||||||||||||||||||||||
4605 | \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
4606 | \row \li hh | - | ||||||||||||||||||||||||||||||
4607 | \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display) | - | ||||||||||||||||||||||||||||||
4608 | \row \li H | - | ||||||||||||||||||||||||||||||
4609 | \li the hour without a leading zero (0 to 23, even with AM/PM display) | - | ||||||||||||||||||||||||||||||
4610 | \row \li HH | - | ||||||||||||||||||||||||||||||
4611 | \li the hour with a leading zero (00 to 23, even with AM/PM display) | - | ||||||||||||||||||||||||||||||
4612 | \row \li m \li the minute without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
4613 | \row \li mm \li the minute with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
4614 | \row \li s \li the second without a leading zero (0 to 59) | - | ||||||||||||||||||||||||||||||
4615 | \row \li ss \li the second with a leading zero (00 to 59) | - | ||||||||||||||||||||||||||||||
4616 | \row \li z \li the milliseconds without leading zeroes (0 to 999) | - | ||||||||||||||||||||||||||||||
4617 | \row \li zzz \li the milliseconds with leading zeroes (000 to 999) | - | ||||||||||||||||||||||||||||||
4618 | \row \li AP or A | - | ||||||||||||||||||||||||||||||
4619 | \li interpret as an AM/PM time. \e AP must be either "AM" or "PM". | - | ||||||||||||||||||||||||||||||
4620 | \row \li ap or a | - | ||||||||||||||||||||||||||||||
4621 | \li Interpret as an AM/PM time. \e ap must be either "am" or "pm". | - | ||||||||||||||||||||||||||||||
4622 | \endtable | - | ||||||||||||||||||||||||||||||
4623 | - | |||||||||||||||||||||||||||||||
4624 | All other input characters will be treated as text. Any sequence | - | ||||||||||||||||||||||||||||||
4625 | of characters that are enclosed in single quotes will also be | - | ||||||||||||||||||||||||||||||
4626 | treated as text and not be used as an expression. | - | ||||||||||||||||||||||||||||||
4627 | - | |||||||||||||||||||||||||||||||
4628 | \snippet code/src_corelib_tools_qdatetime.cpp 12 | - | ||||||||||||||||||||||||||||||
4629 | - | |||||||||||||||||||||||||||||||
4630 | If the format is not satisfied, an invalid QDateTime is returned. | - | ||||||||||||||||||||||||||||||
4631 | The expressions that don't have leading zeroes (d, M, h, m, s, z) will be | - | ||||||||||||||||||||||||||||||
4632 | greedy. This means that they will use two digits even if this will | - | ||||||||||||||||||||||||||||||
4633 | put them outside the range and/or leave too few digits for other | - | ||||||||||||||||||||||||||||||
4634 | sections. | - | ||||||||||||||||||||||||||||||
4635 | - | |||||||||||||||||||||||||||||||
4636 | \snippet code/src_corelib_tools_qdatetime.cpp 13 | - | ||||||||||||||||||||||||||||||
4637 | - | |||||||||||||||||||||||||||||||
4638 | This could have meant 1 January 00:30.00 but the M will grab | - | ||||||||||||||||||||||||||||||
4639 | two digits. | - | ||||||||||||||||||||||||||||||
4640 | - | |||||||||||||||||||||||||||||||
4641 | Incorrectly specified fields of the \a string will cause an invalid | - | ||||||||||||||||||||||||||||||
4642 | QDateTime to be returned. For example, consider the following code, | - | ||||||||||||||||||||||||||||||
4643 | where the two digit year 12 is read as 1912 (see the table below for all | - | ||||||||||||||||||||||||||||||
4644 | field defaults); the resulting datetime is invalid because 23 April 1912 | - | ||||||||||||||||||||||||||||||
4645 | was a Tuesday, not a Monday: | - | ||||||||||||||||||||||||||||||
4646 | - | |||||||||||||||||||||||||||||||
4647 | \snippet code/src_corelib_tools_qdatetime.cpp 20 | - | ||||||||||||||||||||||||||||||
4648 | - | |||||||||||||||||||||||||||||||
4649 | The correct code is: | - | ||||||||||||||||||||||||||||||
4650 | - | |||||||||||||||||||||||||||||||
4651 | \snippet code/src_corelib_tools_qdatetime.cpp 21 | - | ||||||||||||||||||||||||||||||
4652 | - | |||||||||||||||||||||||||||||||
4653 | For any field that is not represented in the format, the following | - | ||||||||||||||||||||||||||||||
4654 | defaults are used: | - | ||||||||||||||||||||||||||||||
4655 | - | |||||||||||||||||||||||||||||||
4656 | \table | - | ||||||||||||||||||||||||||||||
4657 | \header \li Field \li Default value | - | ||||||||||||||||||||||||||||||
4658 | \row \li Year \li 1900 | - | ||||||||||||||||||||||||||||||
4659 | \row \li Month \li 1 (January) | - | ||||||||||||||||||||||||||||||
4660 | \row \li Day \li 1 | - | ||||||||||||||||||||||||||||||
4661 | \row \li Hour \li 0 | - | ||||||||||||||||||||||||||||||
4662 | \row \li Minute \li 0 | - | ||||||||||||||||||||||||||||||
4663 | \row \li Second \li 0 | - | ||||||||||||||||||||||||||||||
4664 | \endtable | - | ||||||||||||||||||||||||||||||
4665 | - | |||||||||||||||||||||||||||||||
4666 | For example: | - | ||||||||||||||||||||||||||||||
4667 | - | |||||||||||||||||||||||||||||||
4668 | \snippet code/src_corelib_tools_qdatetime.cpp 14 | - | ||||||||||||||||||||||||||||||
4669 | - | |||||||||||||||||||||||||||||||
4670 | \sa toString(), QDate::fromString(), QTime::fromString(), | - | ||||||||||||||||||||||||||||||
4671 | QLocale::toDateTime() | - | ||||||||||||||||||||||||||||||
4672 | */ | - | ||||||||||||||||||||||||||||||
4673 | - | |||||||||||||||||||||||||||||||
4674 | QDateTime QDateTime::fromString(const QString &string, const QString &format) | - | ||||||||||||||||||||||||||||||
4675 | { | - | ||||||||||||||||||||||||||||||
4676 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4677 | QTime time; | - | ||||||||||||||||||||||||||||||
4678 | QDate date; | - | ||||||||||||||||||||||||||||||
4679 | - | |||||||||||||||||||||||||||||||
4680 | QDateTimeParser dt(QVariant::DateTime, QDateTimeParser::FromString); | - | ||||||||||||||||||||||||||||||
4681 | if (dt.parseFormat(format) && dt.fromString(string, &date, &time))
| 0-49 | ||||||||||||||||||||||||||||||
4682 | return QDateTime(date, time); executed 41 times by 4 tests: return QDateTime(date, time); Executed by:
| 41 | ||||||||||||||||||||||||||||||
4683 | #else | - | ||||||||||||||||||||||||||||||
4684 | Q_UNUSED(string); | - | ||||||||||||||||||||||||||||||
4685 | Q_UNUSED(format); | - | ||||||||||||||||||||||||||||||
4686 | #endif | - | ||||||||||||||||||||||||||||||
4687 | return QDateTime(QDate(), QTime(-1, -1, -1)); executed 8 times by 1 test: return QDateTime(QDate(), QTime(-1, -1, -1)); Executed by:
| 8 | ||||||||||||||||||||||||||||||
4688 | } | - | ||||||||||||||||||||||||||||||
4689 | - | |||||||||||||||||||||||||||||||
4690 | #endif // QT_NO_DATESTRING | - | ||||||||||||||||||||||||||||||
4691 | /*! | - | ||||||||||||||||||||||||||||||
4692 | \fn QDateTime QDateTime::toLocalTime() const | - | ||||||||||||||||||||||||||||||
4693 | - | |||||||||||||||||||||||||||||||
4694 | Returns a datetime containing the date and time information in | - | ||||||||||||||||||||||||||||||
4695 | this datetime, but specified using the Qt::LocalTime definition. | - | ||||||||||||||||||||||||||||||
4696 | - | |||||||||||||||||||||||||||||||
4697 | Example: | - | ||||||||||||||||||||||||||||||
4698 | - | |||||||||||||||||||||||||||||||
4699 | \snippet code/src_corelib_tools_qdatetime.cpp 17 | - | ||||||||||||||||||||||||||||||
4700 | - | |||||||||||||||||||||||||||||||
4701 | \sa toTimeSpec() | - | ||||||||||||||||||||||||||||||
4702 | */ | - | ||||||||||||||||||||||||||||||
4703 | - | |||||||||||||||||||||||||||||||
4704 | /*! | - | ||||||||||||||||||||||||||||||
4705 | \fn QDateTime QDateTime::toUTC() const | - | ||||||||||||||||||||||||||||||
4706 | - | |||||||||||||||||||||||||||||||
4707 | Returns a datetime containing the date and time information in | - | ||||||||||||||||||||||||||||||
4708 | this datetime, but specified using the Qt::UTC definition. | - | ||||||||||||||||||||||||||||||
4709 | - | |||||||||||||||||||||||||||||||
4710 | Example: | - | ||||||||||||||||||||||||||||||
4711 | - | |||||||||||||||||||||||||||||||
4712 | \snippet code/src_corelib_tools_qdatetime.cpp 18 | - | ||||||||||||||||||||||||||||||
4713 | - | |||||||||||||||||||||||||||||||
4714 | \sa toTimeSpec() | - | ||||||||||||||||||||||||||||||
4715 | */ | - | ||||||||||||||||||||||||||||||
4716 | - | |||||||||||||||||||||||||||||||
4717 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
4718 | Date/time stream functions | - | ||||||||||||||||||||||||||||||
4719 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
4720 | - | |||||||||||||||||||||||||||||||
4721 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||
4722 | /*! | - | ||||||||||||||||||||||||||||||
4723 | \relates QDate | - | ||||||||||||||||||||||||||||||
4724 | - | |||||||||||||||||||||||||||||||
4725 | Writes the \a date to stream \a out. | - | ||||||||||||||||||||||||||||||
4726 | - | |||||||||||||||||||||||||||||||
4727 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||||||||
4728 | */ | - | ||||||||||||||||||||||||||||||
4729 | - | |||||||||||||||||||||||||||||||
4730 | QDataStream &operator<<(QDataStream &out, const QDate &date) | - | ||||||||||||||||||||||||||||||
4731 | { | - | ||||||||||||||||||||||||||||||
4732 | if (out.version() < QDataStream::Qt_5_0)
| 248-495 | ||||||||||||||||||||||||||||||
4733 | return out << quint32(date.jd); executed 248 times by 4 tests: return out << quint32(date.jd); Executed by:
| 248 | ||||||||||||||||||||||||||||||
4734 | else | - | ||||||||||||||||||||||||||||||
4735 | return out << qint64(date.jd); executed 495 times by 10 tests: return out << qint64(date.jd); Executed by:
| 495 | ||||||||||||||||||||||||||||||
4736 | } | - | ||||||||||||||||||||||||||||||
4737 | - | |||||||||||||||||||||||||||||||
4738 | /*! | - | ||||||||||||||||||||||||||||||
4739 | \relates QDate | - | ||||||||||||||||||||||||||||||
4740 | - | |||||||||||||||||||||||||||||||
4741 | Reads a date from stream \a in into the \a date. | - | ||||||||||||||||||||||||||||||
4742 | - | |||||||||||||||||||||||||||||||
4743 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||||||||
4744 | */ | - | ||||||||||||||||||||||||||||||
4745 | - | |||||||||||||||||||||||||||||||
4746 | QDataStream &operator>>(QDataStream &in, QDate &date) | - | ||||||||||||||||||||||||||||||
4747 | { | - | ||||||||||||||||||||||||||||||
4748 | if (in.version() < QDataStream::Qt_5_0) {
| 250-491 | ||||||||||||||||||||||||||||||
4749 | quint32 jd; | - | ||||||||||||||||||||||||||||||
4750 | in >> jd; | - | ||||||||||||||||||||||||||||||
4751 | // Older versions consider 0 an invalid jd. | - | ||||||||||||||||||||||||||||||
4752 | date.jd = (jd != 0 ? jd : QDate::nullJd());
| 16-234 | ||||||||||||||||||||||||||||||
4753 | } else { executed 250 times by 4 tests: end of block Executed by:
| 250 | ||||||||||||||||||||||||||||||
4754 | qint64 jd; | - | ||||||||||||||||||||||||||||||
4755 | in >> jd; | - | ||||||||||||||||||||||||||||||
4756 | date.jd = jd; | - | ||||||||||||||||||||||||||||||
4757 | } executed 491 times by 10 tests: end of block Executed by:
| 491 | ||||||||||||||||||||||||||||||
4758 | - | |||||||||||||||||||||||||||||||
4759 | return in; executed 741 times by 10 tests: return in; Executed by:
| 741 | ||||||||||||||||||||||||||||||
4760 | } | - | ||||||||||||||||||||||||||||||
4761 | - | |||||||||||||||||||||||||||||||
4762 | /*! | - | ||||||||||||||||||||||||||||||
4763 | \relates QTime | - | ||||||||||||||||||||||||||||||
4764 | - | |||||||||||||||||||||||||||||||
4765 | Writes \a time to stream \a out. | - | ||||||||||||||||||||||||||||||
4766 | - | |||||||||||||||||||||||||||||||
4767 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||||||||
4768 | */ | - | ||||||||||||||||||||||||||||||
4769 | - | |||||||||||||||||||||||||||||||
4770 | QDataStream &operator<<(QDataStream &out, const QTime &time) | - | ||||||||||||||||||||||||||||||
4771 | { | - | ||||||||||||||||||||||||||||||
4772 | if (out.version() >= QDataStream::Qt_4_0) {
| 73-872 | ||||||||||||||||||||||||||||||
4773 | return out << quint32(time.mds); executed 872 times by 9 tests: return out << quint32(time.mds); Executed by:
| 872 | ||||||||||||||||||||||||||||||
4774 | } else { | - | ||||||||||||||||||||||||||||||
4775 | // Qt3 had no support for reading -1, QTime() was valid and serialized as 0 | - | ||||||||||||||||||||||||||||||
4776 | return out << quint32(time.isNull() ? 0 : time.mds); executed 73 times by 2 tests: return out << quint32(time.isNull() ? 0 : time.mds); Executed by:
| 73 | ||||||||||||||||||||||||||||||
4777 | } | - | ||||||||||||||||||||||||||||||
4778 | } | - | ||||||||||||||||||||||||||||||
4779 | - | |||||||||||||||||||||||||||||||
4780 | /*! | - | ||||||||||||||||||||||||||||||
4781 | \relates QTime | - | ||||||||||||||||||||||||||||||
4782 | - | |||||||||||||||||||||||||||||||
4783 | Reads a time from stream \a in into the given \a time. | - | ||||||||||||||||||||||||||||||
4784 | - | |||||||||||||||||||||||||||||||
4785 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||||||||
4786 | */ | - | ||||||||||||||||||||||||||||||
4787 | - | |||||||||||||||||||||||||||||||
4788 | QDataStream &operator>>(QDataStream &in, QTime &time) | - | ||||||||||||||||||||||||||||||
4789 | { | - | ||||||||||||||||||||||||||||||
4790 | quint32 ds; | - | ||||||||||||||||||||||||||||||
4791 | in >> ds; | - | ||||||||||||||||||||||||||||||
4792 | if (in.version() >= QDataStream::Qt_4_0) {
| 73-870 | ||||||||||||||||||||||||||||||
4793 | time.mds = int(ds); | - | ||||||||||||||||||||||||||||||
4794 | } else { executed 870 times by 9 tests: end of block Executed by:
| 870 | ||||||||||||||||||||||||||||||
4795 | // Qt3 would write 0 for a null time | - | ||||||||||||||||||||||||||||||
4796 | time.mds = (ds == 0) ? QTime::NullTime : int(ds);
| 25-48 | ||||||||||||||||||||||||||||||
4797 | } executed 73 times by 2 tests: end of block Executed by:
| 73 | ||||||||||||||||||||||||||||||
4798 | return in; executed 943 times by 9 tests: return in; Executed by:
| 943 | ||||||||||||||||||||||||||||||
4799 | } | - | ||||||||||||||||||||||||||||||
4800 | - | |||||||||||||||||||||||||||||||
4801 | /*! | - | ||||||||||||||||||||||||||||||
4802 | \relates QDateTime | - | ||||||||||||||||||||||||||||||
4803 | - | |||||||||||||||||||||||||||||||
4804 | Writes \a dateTime to the \a out stream. | - | ||||||||||||||||||||||||||||||
4805 | - | |||||||||||||||||||||||||||||||
4806 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||||||||
4807 | */ | - | ||||||||||||||||||||||||||||||
4808 | QDataStream &operator<<(QDataStream &out, const QDateTime &dateTime) | - | ||||||||||||||||||||||||||||||
4809 | { | - | ||||||||||||||||||||||||||||||
4810 | QPair<QDate, QTime> dateAndTime; | - | ||||||||||||||||||||||||||||||
4811 | - | |||||||||||||||||||||||||||||||
4812 | if (out.version() >= QDataStream::Qt_5_2) {
| 168-325 | ||||||||||||||||||||||||||||||
4813 | - | |||||||||||||||||||||||||||||||
4814 | // In 5.2 we switched to using Qt::TimeSpec and added offset support | - | ||||||||||||||||||||||||||||||
4815 | dateAndTime = dateTime.d->getDateTime(); | - | ||||||||||||||||||||||||||||||
4816 | out << dateAndTime << qint8(dateTime.timeSpec()); | - | ||||||||||||||||||||||||||||||
4817 | if (dateTime.timeSpec() == Qt::OffsetFromUTC)
| 11-314 | ||||||||||||||||||||||||||||||
4818 | out << qint32(dateTime.offsetFromUtc()); executed 11 times by 3 tests: out << qint32(dateTime.offsetFromUtc()); Executed by:
| 11 | ||||||||||||||||||||||||||||||
4819 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4820 | else if (dateTime.timeSpec() == Qt::TimeZone)
| 1-313 | ||||||||||||||||||||||||||||||
4821 | out << dateTime.timeZone(); executed 1 time by 1 test: out << dateTime.timeZone(); Executed by:
| 1 | ||||||||||||||||||||||||||||||
4822 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4823 | - | |||||||||||||||||||||||||||||||
4824 | } else if (out.version() == QDataStream::Qt_5_0) { executed 325 times by 9 tests: end of block Executed by:
| 9-325 | ||||||||||||||||||||||||||||||
4825 | - | |||||||||||||||||||||||||||||||
4826 | // In Qt 5.0 we incorrectly serialised all datetimes as UTC. | - | ||||||||||||||||||||||||||||||
4827 | // This approach is wrong and should not be used again; it breaks | - | ||||||||||||||||||||||||||||||
4828 | // the guarantee that a deserialised local datetime is the same time | - | ||||||||||||||||||||||||||||||
4829 | // of day, regardless of which timezone it was serialised in. | - | ||||||||||||||||||||||||||||||
4830 | dateAndTime = (dateTime.isValid() ? dateTime.toUTC() : dateTime).d->getDateTime();
| 1-8 | ||||||||||||||||||||||||||||||
4831 | out << dateAndTime << qint8(dateTime.timeSpec()); | - | ||||||||||||||||||||||||||||||
4832 | - | |||||||||||||||||||||||||||||||
4833 | } else if (out.version() >= QDataStream::Qt_4_0) { executed 9 times by 2 tests: end of block Executed by:
| 9-87 | ||||||||||||||||||||||||||||||
4834 | - | |||||||||||||||||||||||||||||||
4835 | // From 4.0 to 5.1 (except 5.0) we used QDateTimePrivate::Spec | - | ||||||||||||||||||||||||||||||
4836 | dateAndTime = dateTime.d->getDateTime(); | - | ||||||||||||||||||||||||||||||
4837 | out << dateAndTime; | - | ||||||||||||||||||||||||||||||
4838 | switch (dateTime.timeSpec()) { | - | ||||||||||||||||||||||||||||||
4839 | case Qt::UTC: executed 56 times by 1 test: case Qt::UTC: Executed by:
| 56 | ||||||||||||||||||||||||||||||
4840 | out << (qint8)QDateTimePrivate::UTC; | - | ||||||||||||||||||||||||||||||
4841 | break; executed 56 times by 1 test: break; Executed by:
| 56 | ||||||||||||||||||||||||||||||
4842 | case Qt::OffsetFromUTC: executed 1 time by 1 test: case Qt::OffsetFromUTC: Executed by:
| 1 | ||||||||||||||||||||||||||||||
4843 | out << (qint8)QDateTimePrivate::OffsetFromUTC; | - | ||||||||||||||||||||||||||||||
4844 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||||||||||||||
4845 | case Qt::TimeZone: never executed: case Qt::TimeZone: | 0 | ||||||||||||||||||||||||||||||
4846 | out << (qint8)QDateTimePrivate::TimeZone; | - | ||||||||||||||||||||||||||||||
4847 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4848 | case Qt::LocalTime: executed 30 times by 3 tests: case Qt::LocalTime: Executed by:
| 30 | ||||||||||||||||||||||||||||||
4849 | out << (qint8)QDateTimePrivate::LocalUnknown; | - | ||||||||||||||||||||||||||||||
4850 | break; executed 30 times by 3 tests: break; Executed by:
| 30 | ||||||||||||||||||||||||||||||
4851 | } | - | ||||||||||||||||||||||||||||||
4852 | - | |||||||||||||||||||||||||||||||
4853 | } else { // version < QDataStream::Qt_4_0 executed 87 times by 3 tests: end of block Executed by:
| 87 | ||||||||||||||||||||||||||||||
4854 | - | |||||||||||||||||||||||||||||||
4855 | // Before 4.0 there was no TimeSpec, only Qt::LocalTime was supported | - | ||||||||||||||||||||||||||||||
4856 | dateAndTime = dateTime.d->getDateTime(); | - | ||||||||||||||||||||||||||||||
4857 | out << dateAndTime; | - | ||||||||||||||||||||||||||||||
4858 | - | |||||||||||||||||||||||||||||||
4859 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||||||||||||||
4860 | - | |||||||||||||||||||||||||||||||
4861 | return out; executed 493 times by 9 tests: return out; Executed by:
| 493 | ||||||||||||||||||||||||||||||
4862 | } | - | ||||||||||||||||||||||||||||||
4863 | - | |||||||||||||||||||||||||||||||
4864 | /*! | - | ||||||||||||||||||||||||||||||
4865 | \relates QDateTime | - | ||||||||||||||||||||||||||||||
4866 | - | |||||||||||||||||||||||||||||||
4867 | Reads a datetime from the stream \a in into \a dateTime. | - | ||||||||||||||||||||||||||||||
4868 | - | |||||||||||||||||||||||||||||||
4869 | \sa {Serializing Qt Data Types} | - | ||||||||||||||||||||||||||||||
4870 | */ | - | ||||||||||||||||||||||||||||||
4871 | - | |||||||||||||||||||||||||||||||
4872 | QDataStream &operator>>(QDataStream &in, QDateTime &dateTime) | - | ||||||||||||||||||||||||||||||
4873 | { | - | ||||||||||||||||||||||||||||||
4874 | QDate dt; | - | ||||||||||||||||||||||||||||||
4875 | QTime tm; | - | ||||||||||||||||||||||||||||||
4876 | qint8 ts = 0; | - | ||||||||||||||||||||||||||||||
4877 | Qt::TimeSpec spec = Qt::LocalTime; | - | ||||||||||||||||||||||||||||||
4878 | qint32 offset = 0; | - | ||||||||||||||||||||||||||||||
4879 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4880 | QTimeZone tz; | - | ||||||||||||||||||||||||||||||
4881 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4882 | - | |||||||||||||||||||||||||||||||
4883 | if (in.version() >= QDataStream::Qt_5_2) {
| 116-303 | ||||||||||||||||||||||||||||||
4884 | - | |||||||||||||||||||||||||||||||
4885 | // In 5.2 we switched to using Qt::TimeSpec and added offset support | - | ||||||||||||||||||||||||||||||
4886 | in >> dt >> tm >> ts; | - | ||||||||||||||||||||||||||||||
4887 | spec = static_cast<Qt::TimeSpec>(ts); | - | ||||||||||||||||||||||||||||||
4888 | if (spec == Qt::OffsetFromUTC) {
| 11-292 | ||||||||||||||||||||||||||||||
4889 | in >> offset; | - | ||||||||||||||||||||||||||||||
4890 | dateTime = QDateTime(dt, tm, spec, offset); | - | ||||||||||||||||||||||||||||||
4891 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4892 | } else if (spec == Qt::TimeZone) { executed 11 times by 3 tests: end of block Executed by:
| 1-291 | ||||||||||||||||||||||||||||||
4893 | in >> tz; | - | ||||||||||||||||||||||||||||||
4894 | dateTime = QDateTime(dt, tm, tz); | - | ||||||||||||||||||||||||||||||
4895 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4896 | } else { executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||||||||||||||
4897 | dateTime = QDateTime(dt, tm, spec); | - | ||||||||||||||||||||||||||||||
4898 | } executed 291 times by 8 tests: end of block Executed by:
| 291 | ||||||||||||||||||||||||||||||
4899 | - | |||||||||||||||||||||||||||||||
4900 | } else if (in.version() == QDataStream::Qt_5_0) {
| 6-110 | ||||||||||||||||||||||||||||||
4901 | - | |||||||||||||||||||||||||||||||
4902 | // In Qt 5.0 we incorrectly serialised all datetimes as UTC | - | ||||||||||||||||||||||||||||||
4903 | in >> dt >> tm >> ts; | - | ||||||||||||||||||||||||||||||
4904 | spec = static_cast<Qt::TimeSpec>(ts); | - | ||||||||||||||||||||||||||||||
4905 | dateTime = QDateTime(dt, tm, Qt::UTC); | - | ||||||||||||||||||||||||||||||
4906 | dateTime = dateTime.toTimeSpec(spec); | - | ||||||||||||||||||||||||||||||
4907 | - | |||||||||||||||||||||||||||||||
4908 | } else if (in.version() >= QDataStream::Qt_4_0) { executed 6 times by 2 tests: end of block Executed by:
| 6-62 | ||||||||||||||||||||||||||||||
4909 | - | |||||||||||||||||||||||||||||||
4910 | // From 4.0 to 5.1 (except 5.0) we used QDateTimePrivate::Spec | - | ||||||||||||||||||||||||||||||
4911 | in >> dt >> tm >> ts; | - | ||||||||||||||||||||||||||||||
4912 | switch ((QDateTimePrivate::Spec)ts) { | - | ||||||||||||||||||||||||||||||
4913 | case QDateTimePrivate::UTC: executed 28 times by 1 test: case QDateTimePrivate::UTC: Executed by:
| 28 | ||||||||||||||||||||||||||||||
4914 | spec = Qt::UTC; | - | ||||||||||||||||||||||||||||||
4915 | break; executed 28 times by 1 test: break; Executed by:
| 28 | ||||||||||||||||||||||||||||||
4916 | case QDateTimePrivate::OffsetFromUTC: executed 2 times by 1 test: case QDateTimePrivate::OffsetFromUTC: Executed by:
| 2 | ||||||||||||||||||||||||||||||
4917 | spec = Qt::OffsetFromUTC; | - | ||||||||||||||||||||||||||||||
4918 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||||||||
4919 | case QDateTimePrivate::TimeZone: never executed: case QDateTimePrivate::TimeZone: | 0 | ||||||||||||||||||||||||||||||
4920 | spec = Qt::TimeZone; | - | ||||||||||||||||||||||||||||||
4921 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4922 | // FIXME: need to use a different constructor ! | - | ||||||||||||||||||||||||||||||
4923 | #endif | - | ||||||||||||||||||||||||||||||
4924 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4925 | case QDateTimePrivate::LocalUnknown: executed 32 times by 3 tests: case QDateTimePrivate::LocalUnknown: Executed by:
| 32 | ||||||||||||||||||||||||||||||
4926 | case QDateTimePrivate::LocalStandard: never executed: case QDateTimePrivate::LocalStandard: | 0 | ||||||||||||||||||||||||||||||
4927 | case QDateTimePrivate::LocalDST: never executed: case QDateTimePrivate::LocalDST: | 0 | ||||||||||||||||||||||||||||||
4928 | spec = Qt::LocalTime; | - | ||||||||||||||||||||||||||||||
4929 | break; executed 32 times by 3 tests: break; Executed by:
| 32 | ||||||||||||||||||||||||||||||
4930 | } | - | ||||||||||||||||||||||||||||||
4931 | dateTime = QDateTime(dt, tm, spec, offset); | - | ||||||||||||||||||||||||||||||
4932 | - | |||||||||||||||||||||||||||||||
4933 | } else { // version < QDataStream::Qt_4_0 executed 62 times by 3 tests: end of block Executed by:
| 62 | ||||||||||||||||||||||||||||||
4934 | - | |||||||||||||||||||||||||||||||
4935 | // Before 4.0 there was no TimeSpec, only Qt::LocalTime was supported | - | ||||||||||||||||||||||||||||||
4936 | in >> dt >> tm; | - | ||||||||||||||||||||||||||||||
4937 | dateTime = QDateTime(dt, tm, spec, offset); | - | ||||||||||||||||||||||||||||||
4938 | - | |||||||||||||||||||||||||||||||
4939 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||||||||||||||
4940 | - | |||||||||||||||||||||||||||||||
4941 | return in; executed 419 times by 9 tests: return in; Executed by:
| 419 | ||||||||||||||||||||||||||||||
4942 | } | - | ||||||||||||||||||||||||||||||
4943 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||
4944 | - | |||||||||||||||||||||||||||||||
4945 | /***************************************************************************** | - | ||||||||||||||||||||||||||||||
4946 | Date / Time Debug Streams | - | ||||||||||||||||||||||||||||||
4947 | *****************************************************************************/ | - | ||||||||||||||||||||||||||||||
4948 | - | |||||||||||||||||||||||||||||||
4949 | #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_NO_DATESTRING) | - | ||||||||||||||||||||||||||||||
4950 | QDebug operator<<(QDebug dbg, const QDate &date) | - | ||||||||||||||||||||||||||||||
4951 | { | - | ||||||||||||||||||||||||||||||
4952 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||||||||
4953 | dbg.nospace() << "QDate(" << date.toString(Qt::ISODate) << ')'; | - | ||||||||||||||||||||||||||||||
4954 | return dbg; executed 3 times by 2 tests: return dbg; Executed by:
| 3 | ||||||||||||||||||||||||||||||
4955 | } | - | ||||||||||||||||||||||||||||||
4956 | - | |||||||||||||||||||||||||||||||
4957 | QDebug operator<<(QDebug dbg, const QTime &time) | - | ||||||||||||||||||||||||||||||
4958 | { | - | ||||||||||||||||||||||||||||||
4959 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||||||||
4960 | dbg.nospace() << "QTime(" << time.toString(QStringLiteral("HH:mm:ss.zzz")) << ')'; executed 1 time by 1 test: return qstring_literal_temp; Executed by:
| 1 | ||||||||||||||||||||||||||||||
4961 | return dbg; executed 1 time by 1 test: return dbg; Executed by:
| 1 | ||||||||||||||||||||||||||||||
4962 | } | - | ||||||||||||||||||||||||||||||
4963 | - | |||||||||||||||||||||||||||||||
4964 | QDebug operator<<(QDebug dbg, const QDateTime &date) | - | ||||||||||||||||||||||||||||||
4965 | { | - | ||||||||||||||||||||||||||||||
4966 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||||||||
4967 | const Qt::TimeSpec ts = date.timeSpec(); | - | ||||||||||||||||||||||||||||||
4968 | dbg.nospace() << "QDateTime("; | - | ||||||||||||||||||||||||||||||
4969 | dbg.noquote() << date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) executed 2 times by 2 tests: return qstring_literal_temp; Executed by:
| 2 | ||||||||||||||||||||||||||||||
4970 | << ' ' << ts; | - | ||||||||||||||||||||||||||||||
4971 | switch (ts) { | - | ||||||||||||||||||||||||||||||
4972 | case Qt::UTC: never executed: case Qt::UTC: | 0 | ||||||||||||||||||||||||||||||
4973 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4974 | case Qt::OffsetFromUTC: never executed: case Qt::OffsetFromUTC: | 0 | ||||||||||||||||||||||||||||||
4975 | dbg << ' ' << date.offsetFromUtc() << 's'; | - | ||||||||||||||||||||||||||||||
4976 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4977 | case Qt::TimeZone: never executed: case Qt::TimeZone: | 0 | ||||||||||||||||||||||||||||||
4978 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4979 | dbg << ' ' << date.timeZone().id(); | - | ||||||||||||||||||||||||||||||
4980 | #endif // QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||
4981 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
4982 | case Qt::LocalTime: executed 2 times by 2 tests: case Qt::LocalTime: Executed by:
| 2 | ||||||||||||||||||||||||||||||
4983 | break; executed 2 times by 2 tests: break; Executed by:
| 2 | ||||||||||||||||||||||||||||||
4984 | } | - | ||||||||||||||||||||||||||||||
4985 | return dbg << ')'; executed 2 times by 2 tests: return dbg << ')'; Executed by:
| 2 | ||||||||||||||||||||||||||||||
4986 | } | - | ||||||||||||||||||||||||||||||
4987 | #endif | - | ||||||||||||||||||||||||||||||
4988 | - | |||||||||||||||||||||||||||||||
4989 | /*! \fn uint qHash(const QDateTime &key, uint seed = 0) | - | ||||||||||||||||||||||||||||||
4990 | \relates QHash | - | ||||||||||||||||||||||||||||||
4991 | \since 5.0 | - | ||||||||||||||||||||||||||||||
4992 | - | |||||||||||||||||||||||||||||||
4993 | Returns the hash value for the \a key, using \a seed to seed the calculation. | - | ||||||||||||||||||||||||||||||
4994 | */ | - | ||||||||||||||||||||||||||||||
4995 | uint qHash(const QDateTime &key, uint seed) | - | ||||||||||||||||||||||||||||||
4996 | { | - | ||||||||||||||||||||||||||||||
4997 | // Use to toMSecsSinceEpoch instead of individual qHash functions for | - | ||||||||||||||||||||||||||||||
4998 | // QDate/QTime/spec/offset because QDateTime::operator== converts both arguments | - | ||||||||||||||||||||||||||||||
4999 | // to the same timezone. If we don't, qHash would return different hashes for | - | ||||||||||||||||||||||||||||||
5000 | // two QDateTimes that are equivalent once converted to the same timezone. | - | ||||||||||||||||||||||||||||||
5001 | return qHash(key.toMSecsSinceEpoch(), seed); executed 16 times by 1 test: return qHash(key.toMSecsSinceEpoch(), seed); Executed by:
| 16 | ||||||||||||||||||||||||||||||
5002 | } | - | ||||||||||||||||||||||||||||||
5003 | - | |||||||||||||||||||||||||||||||
5004 | /*! \fn uint qHash(const QDate &key, uint seed = 0) | - | ||||||||||||||||||||||||||||||
5005 | \relates QHash | - | ||||||||||||||||||||||||||||||
5006 | \since 5.0 | - | ||||||||||||||||||||||||||||||
5007 | - | |||||||||||||||||||||||||||||||
5008 | Returns the hash value for the \a key, using \a seed to seed the calculation. | - | ||||||||||||||||||||||||||||||
5009 | */ | - | ||||||||||||||||||||||||||||||
5010 | uint qHash(const QDate &key, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||||||||||||||
5011 | { | - | ||||||||||||||||||||||||||||||
5012 | return qHash(key.toJulianDay(), seed); executed 6 times by 1 test: return qHash(key.toJulianDay(), seed); Executed by:
| 6 | ||||||||||||||||||||||||||||||
5013 | } | - | ||||||||||||||||||||||||||||||
5014 | - | |||||||||||||||||||||||||||||||
5015 | /*! \fn uint qHash(const QTime &key, uint seed = 0) | - | ||||||||||||||||||||||||||||||
5016 | \relates QHash | - | ||||||||||||||||||||||||||||||
5017 | \since 5.0 | - | ||||||||||||||||||||||||||||||
5018 | - | |||||||||||||||||||||||||||||||
5019 | Returns the hash value for the \a key, using \a seed to seed the calculation. | - | ||||||||||||||||||||||||||||||
5020 | */ | - | ||||||||||||||||||||||||||||||
5021 | uint qHash(const QTime &key, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||||||||||||||
5022 | { | - | ||||||||||||||||||||||||||||||
5023 | return qHash(key.msecsSinceStartOfDay(), seed); executed 4 times by 1 test: return qHash(key.msecsSinceStartOfDay(), seed); Executed by:
| 4 | ||||||||||||||||||||||||||||||
5024 | } | - | ||||||||||||||||||||||||||||||
5025 | - | |||||||||||||||||||||||||||||||
5026 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |