OpenCoverage

qdatetime.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qdatetime.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Copyright (C) 2016 Intel Corporation.-
5** Contact: https://www.qt.io/licensing/-
6**-
7** This file is part of the QtCore module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL$-
10** Commercial License Usage-
11** Licensees holding valid commercial Qt licenses may use this file in-
12** accordance with the commercial license agreement provided with the-
13** Software or, alternatively, in accordance with the terms contained in-
14** a written agreement between you and The Qt Company. For licensing terms-
15** and conditions see https://www.qt.io/terms-conditions. For further-
16** information use the contact form at https://www.qt.io/contact-us.-
17**-
18** GNU Lesser General Public License Usage-
19** Alternatively, this file may be used under the terms of the GNU Lesser-
20** General Public License version 3 as published by the Free Software-
21** Foundation and appearing in the file LICENSE.LGPL3 included in the-
22** packaging of this file. Please review the following information to-
23** ensure the GNU Lesser General Public License version 3 requirements-
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
25**-
26** GNU General Public License Usage-
27** Alternatively, this file may be used under the terms of the GNU-
28** General Public License version 2.0 or (at your option) the GNU General-
29** Public license version 3 or any later version approved by the KDE Free-
30** Qt Foundation. The licenses are as published by the Free Software-
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
32** included in the packaging of this file. Please review the following-
33** information to ensure the GNU General Public License requirements will-
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
35** https://www.gnu.org/licenses/gpl-3.0.html.-
36**-
37** $QT_END_LICENSE$-
38**-
39****************************************************************************/-
40-
41#include "qplatformdefs.h"-
42#include "private/qdatetime_p.h"-
43#include "private/qdatetimeparser_p.h"-
44-
45#include "qdatastream.h"-
46#include "qset.h"-
47#include "qlocale.h"-
48#include "qdatetime.h"-
49#include "qtimezoneprivate_p.h"-
50#include "qregexp.h"-
51#include "qdebug.h"-
52#ifndef Q_OS_WIN-
53#include <locale.h>-
54#endif-
55-
56#include <cmath>-
57#include <time.h>-
58#ifdef Q_OS_WIN-
59# include <qt_windows.h>-
60# ifdef Q_OS_WINCE-
61# include "qfunctions_wince.h"-
62# endif-
63# ifdef Q_OS_WINRT-
64# include "qfunctions_winrt.h"-
65# endif-
66#endif-
67-
68#if defined(Q_OS_MAC)-
69#include <private/qcore_mac_p.h>-
70#endif-
71-
72QT_BEGIN_NAMESPACE-
73-
74Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QDateTimePrivate>, defaultDateTimePrivate, (new QDateTimePrivate()))
executed 326 times by 128 tests: end of block
Executed by:
  • tst_languagechange - unknown status
  • tst_networkselftest - unknown status
  • tst_platformsocketengine - unknown status
  • tst_qabstractfileengine - unknown status
  • tst_qabstractitemview - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qabstractslider - unknown status
  • tst_qaccessibility - unknown status
  • tst_qasn1element - unknown status
  • tst_qatomicint - unknown status
  • tst_qauthenticator - unknown status
  • tst_qbuttongroup - unknown status
  • tst_qcalendarwidget - unknown status
  • tst_qcolordialog - unknown status
  • tst_qcombobox - unknown status
  • tst_qcommandlinkbutton - unknown status
  • tst_qcompleter - unknown status
  • tst_qcoreapplication - unknown status
  • tst_qdatastream - unknown status
  • tst_qdate - unknown status
  • tst_qdatetime - unknown status
  • tst_qdatetimeedit - unknown status
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusmarshall - unknown status
  • ...
executed 326 times by 128 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_languagechange - unknown status
  • tst_networkselftest - unknown status
  • tst_platformsocketengine - unknown status
  • tst_qabstractfileengine - unknown status
  • tst_qabstractitemview - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qabstractslider - unknown status
  • tst_qaccessibility - unknown status
  • tst_qasn1element - unknown status
  • tst_qatomicint - unknown status
  • tst_qauthenticator - unknown status
  • tst_qbuttongroup - unknown status
  • tst_qcalendarwidget - unknown status
  • tst_qcolordialog - unknown status
  • tst_qcombobox - unknown status
  • tst_qcommandlinkbutton - unknown status
  • tst_qcompleter - unknown status
  • tst_qcoreapplication - unknown status
  • tst_qdatastream - unknown status
  • tst_qdate - unknown status
  • tst_qdatetime - unknown status
  • tst_qdatetimeedit - unknown status
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusmarshall - unknown status
  • ...
executed 7100330 times by 127 tests: return &holder.value;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDBusMetaType
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • ...
guard.load() =...c::InitializedDescription
TRUEevaluated 326 times by 128 tests
Evaluated by:
  • tst_languagechange - unknown status
  • tst_networkselftest - unknown status
  • tst_platformsocketengine - unknown status
  • tst_qabstractfileengine - unknown status
  • tst_qabstractitemview - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qabstractslider - unknown status
  • tst_qaccessibility - unknown status
  • tst_qasn1element - unknown status
  • tst_qatomicint - unknown status
  • tst_qauthenticator - unknown status
  • tst_qbuttongroup - unknown status
  • tst_qcalendarwidget - unknown status
  • tst_qcolordialog - unknown status
  • tst_qcombobox - unknown status
  • tst_qcommandlinkbutton - unknown status
  • tst_qcompleter - unknown status
  • tst_qcoreapplication - unknown status
  • tst_qdatastream - unknown status
  • tst_qdate - unknown status
  • tst_qdatetime - unknown status
  • tst_qdatetimeedit - unknown status
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusmarshall - unknown status
  • ...
FALSEnever evaluated
0-7100330
75-
76/*****************************************************************************-
77 Date/Time Constants-
78 *****************************************************************************/-
79-
80enum {-
81 SECS_PER_DAY = 86400,-
82 MSECS_PER_DAY = 86400000,-
83 SECS_PER_HOUR = 3600,-
84 MSECS_PER_HOUR = 3600000,-
85 SECS_PER_MIN = 60,-
86 MSECS_PER_MIN = 60000,-
87 TIME_T_MAX = 2145916799, // int maximum 2037-12-31T23:59:59 UTC-
88 JULIAN_DAY_FOR_EPOCH = 2440588 // result of julianDayFromDate(1970, 1, 1)-
89};-
90-
91/*****************************************************************************-
92 QDate static helper functions-
93 *****************************************************************************/-
94-
95static inline QDate fixedDate(int y, int m, int d)-
96{-
97 QDate result(y, m, 1);-
98 result.setDate(y, m, qMin(d, result.daysInMonth()));-
99 return result;
executed 288 times by 4 tests: return result;
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
288
100}-
101-
102/*-
103 Division, rounding down (rather than towards zero).-
104-
105 From C++11 onwards, integer division is defined to round towards zero, so we-
106 can rely on that when implementing this. This is only used with denominator b-
107 > 0, so we only have to treat negative numerator, a, specially.-
108 */-
109static inline qint64 floordiv(qint64 a, int b)-
110{-
111 return (a - (a < 0 ? b - 1 : 0)) / b;
executed 96372952 times by 106 tests: return (a - (a < 0 ? b - 1 : 0)) / b;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
96372952
112}-
113-
114static inline int floordiv(int a, int b)-
115{-
116 return (a - (a < 0 ? b - 1 : 0)) / b;
executed 138065546 times by 106 tests: return (a - (a < 0 ? b - 1 : 0)) / b;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
138065546
117}-
118-
119static inline qint64 julianDayFromDate(int year, int month, int day)-
120{-
121 // Adjust for no year 0-
122 if (year < 0)
year < 0Description
TRUEevaluated 239374 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 21340606 times by 106 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
239374-21340606
123 ++year;
executed 239374 times by 2 tests: ++year;
Executed by:
  • tst_QDate
  • tst_QDateTime
239374
124-
125/*-
126 * Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php-
127 * This formula is correct for all julian days, when using mathematical integer-
128 * division (round to negative infinity), not c++11 integer division (round to zero)-
129 */-
130 int a = floordiv(14 - month, 12);-
131 qint64 y = (qint64)year + 4800 - a;-
132 int m = month + 12 * a - 3;-
133 return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045;
executed 21563880 times by 106 tests: return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
21563880
134}-
135-
136struct ParsedDate-
137{-
138 int year, month, day;-
139};-
140-
141// prevent this function from being inlined into all 10 users-
142Q_NEVER_INLINE-
143static ParsedDate getDateFromJulianDay(qint64 julianDay)-
144{-
145/*-
146 * Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php-
147 * This formula is correct for all julian days, when using mathematical integer-
148 * division (round to negative infinity), not c++11 integer division (round to zero)-
149 */-
150 qint64 a = julianDay + 32044;-
151 qint64 b = floordiv(4 * a + 3, 146097);-
152 int c = a - floordiv(146097 * b, 4);-
153-
154 int d = floordiv(4 * c + 3, 1461);-
155 int e = c - floordiv(1461 * d, 4);-
156 int m = floordiv(5 * e + 2, 153);-
157-
158 int day = e - floordiv(153 * m + 2, 5) + 1;-
159 int month = m + 3 - 12 * floordiv(m, 10);-
160 int year = 100 * b + d - 4800 + floordiv(m, 10);-
161-
162 // Adjust for no year 0-
163 if (year <= 0)
year <= 0Description
TRUEevaluated 715840 times by 5 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 15118575 times by 103 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
715840-15118575
164 --year ;
executed 715840 times by 5 tests: --year ;
Executed by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
715840
165-
166 const ParsedDate result = { year, month, day };-
167 return result;
executed 15841708 times by 103 tests: return result;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
15841708
168}-
169-
170/*****************************************************************************-
171 Date/Time formatting helper functions-
172 *****************************************************************************/-
173-
174static const char monthDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };-
175-
176#ifndef QT_NO_TEXTDATE-
177static const char qt_shortMonthNames[][4] = {-
178 "Jan", "Feb", "Mar", "Apr", "May", "Jun",-
179 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };-
180-
181static int qt_monthNumberFromShortName(QStringRef shortName)-
182{-
183 for (unsigned int i = 0; i < sizeof(qt_shortMonthNames) / sizeof(qt_shortMonthNames[0]); ++i) {
i < sizeof(qt_...MonthNames[0])Description
TRUEevaluated 579 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QTime
FALSEevaluated 25 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
25-579
184 if (shortName == QLatin1String(qt_shortMonthNames[i], 3))
shortName == Q...thNames[i], 3)Description
TRUEevaluated 90 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QTime
FALSEevaluated 489 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QTime
90-489
185 return i + 1;
executed 90 times by 4 tests: return i + 1;
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QTime
90
186 }
executed 489 times by 4 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QTime
489
187 return -1;
executed 25 times by 3 tests: return -1;
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
25
188}-
189static int qt_monthNumberFromShortName(const QString &shortName)-
190{
executed 48 times by 3 tests: return qt_monthNumberFromShortName(QStringRef(&shortName));
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
return qt_monthNumberFromShortName(QStringRef(&shortName)); }
executed 48 times by 3 tests: return qt_monthNumberFromShortName(QStringRef(&shortName));
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
48
191-
192static int fromShortMonthName(const QStringRef &monthName)-
193{-
194 // Assume that English monthnames are the default-
195 int month = qt_monthNumberFromShortName(monthName);-
196 if (month != -1)
month != -1Description
TRUEevaluated 51 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
16-51
197 return month;
executed 51 times by 3 tests: return month;
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
51
198 // If English names can't be found, search the localized ones-
199 for (int i = 1; i <= 12; ++i) {
i <= 12Description
TRUEevaluated 192 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
16-192
200 if (monthName == QDate::shortMonthName(i))
monthName == Q...rtMonthName(i)Description
TRUEnever evaluated
FALSEevaluated 192 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
0-192
201 return i;
never executed: return i;
0
202 }
executed 192 times by 2 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
192
203 return -1;
executed 16 times by 2 tests: return -1;
Executed by:
  • tst_QDate
  • tst_QDateTime
16
204}-
205#endif // QT_NO_TEXTDATE-
206-
207#ifndef QT_NO_DATESTRING-
208struct ParsedRfcDateTime {-
209 QDate date;-
210 QTime time;-
211 int utcOffset;-
212};-
213-
214static ParsedRfcDateTime rfcDateImpl(const QString &s)-
215{-
216 ParsedRfcDateTime result;-
217-
218 // Matches "Wdy, DD Mon YYYY HH:mm:ss ±hhmm" (Wdy, being optional)-
219 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:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
71
220 if (s.indexOf(rex) == 0) {
s.indexOf(rex) == 0Description
TRUEevaluated 33 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 38 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
33-38
221 const QStringList cap = rex.capturedTexts();-
222 result.date = QDate(cap[3].toInt(), qt_monthNumberFromShortName(cap[2]), cap[1].toInt());-
223 if (!cap[4].isEmpty())
!cap[4].isEmpty()Description
TRUEevaluated 27 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 6 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
6-27
224 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:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
27
225 const bool positiveOffset = (cap[7] == QLatin1String("+"));-
226 const int hourOffset = cap[8].toInt();-
227 const int minOffset = cap[9].toInt();-
228 result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));-
229 } else {
executed 33 times by 3 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
33
230 // Matches "Wdy Mon DD HH:mm:ss YYYY"-
231 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:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
38
232 if (s.indexOf(rex) == 0) {
s.indexOf(rex) == 0Description
TRUEevaluated 15 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 23 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
15-23
233 const QStringList cap = rex.capturedTexts();-
234 result.date = QDate(cap[6].toInt(), qt_monthNumberFromShortName(cap[1]), cap[2].toInt());-
235 if (!cap[3].isEmpty())
!cap[3].isEmpty()Description
TRUEevaluated 12 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 3 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
3-12
236 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:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
12
237 const bool positiveOffset = (cap[7] == QLatin1String("+"));-
238 const int hourOffset = cap[8].toInt();-
239 const int minOffset = cap[9].toInt();-
240 result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));-
241 }
executed 15 times by 3 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
15
242 }
executed 38 times by 3 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
38
243-
244 return result;
executed 71 times by 3 tests: return result;
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QTime
71
245}-
246#endif // QT_NO_DATESTRING-
247-
248// Return offset in [+-]HH:mm format-
249static QString toOffsetString(Qt::DateFormat format, int offset)-
250{-
251 return QString::asprintf("%c%02d%s%02d",
executed 98 times by 2 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60);
Executed by:
  • tst_QDateTime
  • tst_selftests - unknown status
98
252 offset >= 0 ? '+' : '-',
executed 98 times by 2 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60);
Executed by:
  • tst_QDateTime
  • tst_selftests - unknown status
98
253 qAbs(offset) / SECS_PER_HOUR,
executed 98 times by 2 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60);
Executed by:
  • tst_QDateTime
  • tst_selftests - unknown status
98
254 // Qt::ISODate puts : between the hours and minutes, but Qt:TextDate does not:
executed 98 times by 2 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60);
Executed by:
  • tst_QDateTime
  • tst_selftests - unknown status
98
255 format == Qt::TextDate ? "" : ":",
executed 98 times by 2 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60);
Executed by:
  • tst_QDateTime
  • tst_selftests - unknown status
98
256 (qAbs(offset) / 60) % 60);
executed 98 times by 2 tests: return QString::asprintf("%c%02d%s%02d", offset >= 0 ? '+' : '-', qAbs(offset) / SECS_PER_HOUR, format == Qt::TextDate ? "" : ":", (qAbs(offset) / 60) % 60);
Executed by:
  • tst_QDateTime
  • tst_selftests - unknown status
98
257}-
258-
259// Parse offset in [+-]HH[[:]mm] format-
260static int fromOffsetString(const QStringRef &offsetString, bool *valid) Q_DECL_NOTHROW-
261{-
262 *valid = false;-
263-
264 const int size = offsetString.size();-
265 if (size < 2 || size > 6)
size < 2Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_QDateTime
size > 6Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_QDateTime
0-22
266 return 0;
never executed: return 0;
0
267-
268 // sign will be +1 for a positive and -1 for a negative offset-
269 int sign;-
270-
271 // First char must be + or --
272 const QChar signChar = offsetString.at(0);-
273 if (signChar == QLatin1Char('+'))
signChar == QLatin1Char('+')Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 11 times by 1 test
Evaluated by:
  • tst_QDateTime
11
274 sign = 1;
executed 11 times by 1 test: sign = 1;
Executed by:
  • tst_QDateTime
11
275 else if (signChar == QLatin1Char('-'))
signChar == QLatin1Char('-')Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDateTime
1-10
276 sign = -1;
executed 10 times by 1 test: sign = -1;
Executed by:
  • tst_QDateTime
10
277 else-
278 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • tst_QDateTime
1
279-
280 // Split the hour and minute parts-
281 const QStringRef time = offsetString.mid(1);-
282 int hhLen = time.indexOf(QLatin1Char(':'));-
283 int mmIndex;-
284 if (hhLen == -1)
hhLen == -1Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QDateTime
8-13
285 mmIndex = hhLen = 2; // [+-]HHmm or [+-]HH format
executed 13 times by 1 test: mmIndex = hhLen = 2;
Executed by:
  • tst_QDateTime
13
286 else-
287 mmIndex = hhLen + 1;
executed 8 times by 1 test: mmIndex = hhLen + 1;
Executed by:
  • tst_QDateTime
8
288-
289 const QStringRef hhRef = time.left(hhLen);-
290 bool ok = false;-
291 const int hour = hhRef.toInt(&ok);-
292 if (!ok)
!okDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QDateTime
2-19
293 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QDateTime
2
294-
295 const QStringRef mmRef = time.mid(mmIndex);-
296 const int minute = mmRef.isEmpty() ? 0 : mmRef.toInt(&ok);
mmRef.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 15 times by 1 test
Evaluated by:
  • tst_QDateTime
4-15
297 if (!ok || minute < 0 || minute > 59)
!okDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QDateTime
minute < 0Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QDateTime
minute > 59Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QDateTime
0-18
298 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • tst_QDateTime
1
299-
300 *valid = true;-
301 return sign * ((hour * 60) + minute) * 60;
executed 18 times by 1 test: return sign * ((hour * 60) + minute) * 60;
Executed by:
  • tst_QDateTime
18
302}-
303-
304/*****************************************************************************-
305 QDate member functions-
306 *****************************************************************************/-
307-
308/*!-
309 \since 4.5-
310-
311 \enum QDate::MonthNameType-
312-
313 This enum describes the types of the string representation used-
314 for the month name.-
315-
316 \value DateFormat This type of name can be used for date-to-string formatting.-
317 \value StandaloneFormat This type is used when you need to enumerate months or weekdays.-
318 Usually standalone names are represented in singular forms with-
319 capitalized first letter.-
320*/-
321-
322/*!-
323 \class QDate-
324 \inmodule QtCore-
325 \reentrant-
326 \brief The QDate class provides date functions.-
327-
328-
329 A QDate object contains a calendar date, i.e. year, month, and day-
330 numbers, in the Gregorian calendar. It can read the current date-
331 from the system clock. It provides functions for comparing dates,-
332 and for manipulating dates. For example, it is possible to add-
333 and subtract days, months, and years to dates.-
334-
335 A QDate object is typically created by giving the year,-
336 month, and day numbers explicitly. Note that QDate interprets two-
337 digit years as is, i.e., years 0 - 99. A QDate can also be-
338 constructed with the static function currentDate(), which creates-
339 a QDate object containing the system clock's date. An explicit-
340 date can also be set using setDate(). The fromString() function-
341 returns a QDate given a string and a date format which is used to-
342 interpret the date within the string.-
343-
344 The year(), month(), and day() functions provide access to the-
345 year, month, and day numbers. Also, dayOfWeek() and dayOfYear()-
346 functions are provided. The same information is provided in-
347 textual format by the toString(), shortDayName(), longDayName(),-
348 shortMonthName(), and longMonthName() functions.-
349-
350 QDate provides a full set of operators to compare two QDate-
351 objects where smaller means earlier, and larger means later.-
352-
353 You can increment (or decrement) a date by a given number of days-
354 using addDays(). Similarly you can use addMonths() and addYears().-
355 The daysTo() function returns the number of days between two-
356 dates.-
357-
358 The daysInMonth() and daysInYear() functions return how many days-
359 there are in this date's month and year, respectively. The-
360 isLeapYear() function indicates whether a date is in a leap year.-
361-
362 \section1-
363-
364 \section2 No Year 0-
365-
366 There is no year 0. Dates in that year are considered invalid. The-
367 year -1 is the year "1 before Christ" or "1 before current era."-
368 The day before 1 January 1 CE is 31 December 1 BCE.-
369-
370 \section2 Range of Valid Dates-
371-
372 Dates are stored internally as a Julian Day number, an integer count of-
373 every day in a contiguous range, with 24 November 4714 BCE in the Gregorian-
374 calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar).-
375 As well as being an efficient and accurate way of storing an absolute date,-
376 it is suitable for converting a Date into other calendar systems such as-
377 Hebrew, Islamic or Chinese. The Julian Day number can be obtained using-
378 QDate::toJulianDay() and can be set using QDate::fromJulianDay().-
379-
380 The range of dates able to be stored by QDate as a Julian Day number is-
381 for technical reasons limited to between -784350574879 and 784354017364,-
382 which means from before 2 billion BCE to after 2 billion CE.-
383-
384 \sa QTime, QDateTime, QDateEdit, QDateTimeEdit, QCalendarWidget-
385*/-
386-
387/*!-
388 \fn QDate::QDate()-
389-
390 Constructs a null date. Null dates are invalid.-
391-
392 \sa isNull(), isValid()-
393*/-
394-
395/*!-
396 Constructs a date with year \a y, month \a m and day \a d.-
397-
398 If the specified date is invalid, the date is not set and-
399 isValid() returns \c false.-
400-
401 \warning Years 1 to 99 are interpreted as is. Year 0 is invalid.-
402-
403 \sa isValid()-
404*/-
405-
406QDate::QDate(int y, int m, int d)-
407{-
408 setDate(y, m, d);-
409}
executed 21012299 times by 106 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
21012299
410-
411-
412/*!-
413 \fn bool QDate::isNull() const-
414-
415 Returns \c true if the date is null; otherwise returns \c false. A null-
416 date is invalid.-
417-
418 \note The behavior of this function is equivalent to isValid().-
419-
420 \sa isValid()-
421*/-
422-
423-
424/*!-
425 \fn bool QDate::isValid() const-
426-
427 Returns \c true if this date is valid; otherwise returns \c false.-
428-
429 \sa isNull()-
430*/-
431-
432-
433/*!-
434 Returns the year of this date. Negative numbers indicate years-
435 before 1 CE, such that year -44 is 44 BCE.-
436-
437 Returns 0 if the date is invalid.-
438-
439 \sa month(), day()-
440*/-
441-
442int QDate::year() const-
443{-
444 if (isNull())
isNull()Description
TRUEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 621887 times by 42 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QCalendarWidget
  • tst_QCompleter
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QItemDelegate
  • tst_QItemModel
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • ...
24-621887
445 return 0;
executed 24 times by 2 tests: return 0;
Executed by:
  • tst_QDate
  • tst_QDateTime
24
446-
447 return getDateFromJulianDay(jd).year;
executed 621887 times by 42 tests: return getDateFromJulianDay(jd).year;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QCalendarWidget
  • tst_QCompleter
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QItemDelegate
  • tst_QItemModel
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • ...
621887
448}-
449-
450/*!-
451 Returns the number corresponding to the month of this date, using-
452 the following convention:-
453-
454 \list-
455 \li 1 = "January"-
456 \li 2 = "February"-
457 \li 3 = "March"-
458 \li 4 = "April"-
459 \li 5 = "May"-
460 \li 6 = "June"-
461 \li 7 = "July"-
462 \li 8 = "August"-
463 \li 9 = "September"-
464 \li 10 = "October"-
465 \li 11 = "November"-
466 \li 12 = "December"-
467 \endlist-
468-
469 Returns 0 if the date is invalid.-
470-
471 \sa year(), day()-
472*/-
473-
474int QDate::month() const-
475{-
476 if (isNull())
isNull()Description
TRUEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 611545 times by 41 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QCalendarWidget
  • tst_QCompleter
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QItemDelegate
  • tst_QItemModel
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QNoDebug
  • ...
24-611545
477 return 0;
executed 24 times by 2 tests: return 0;
Executed by:
  • tst_QDate
  • tst_QDateTime
24
478-
479 return getDateFromJulianDay(jd).month;
executed 611545 times by 41 tests: return getDateFromJulianDay(jd).month;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QCalendarWidget
  • tst_QCompleter
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QItemDelegate
  • tst_QItemModel
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QNoDebug
  • ...
611545
480}-
481-
482/*!-
483 Returns the day of the month (1 to 31) of this date.-
484-
485 Returns 0 if the date is invalid.-
486-
487 \sa year(), month(), dayOfWeek()-
488*/-
489-
490int QDate::day() const-
491{-
492 if (isNull())
isNull()Description
TRUEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 647403 times by 40 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QCalendarWidget
  • tst_QCompleter
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QItemDelegate
  • tst_QItemModel
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QNoDebug
  • ...
24-647403
493 return 0;
executed 24 times by 2 tests: return 0;
Executed by:
  • tst_QDate
  • tst_QDateTime
24
494-
495 return getDateFromJulianDay(jd).day;
executed 647403 times by 40 tests: return getDateFromJulianDay(jd).day;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QCalendarWidget
  • tst_QCompleter
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QItemDelegate
  • tst_QItemModel
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QNoDebug
  • ...
647403
496}-
497-
498/*!-
499 Returns the weekday (1 = Monday to 7 = Sunday) for this date.-
500-
501 Returns 0 if the date is invalid.-
502-
503 \sa day(), dayOfYear(), Qt::DayOfWeek-
504*/-
505-
506int QDate::dayOfWeek() const-
507{-
508 if (isNull())
isNull()Description
TRUEevaluated 77 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 39478 times by 17 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
  • tst_QTimeZone
  • tst_QXmlStream
  • tst_qmakelib
77-39478
509 return 0;
executed 77 times by 3 tests: return 0;
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
77
510-
511 if (jd >= 0)
jd >= 0Description
TRUEevaluated 39470 times by 17 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
  • tst_QTimeZone
  • tst_QXmlStream
  • tst_qmakelib
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QDate
8-39470
512 return (jd % 7) + 1;
executed 39470 times by 17 tests: return (jd % 7) + 1;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
  • tst_QTimeZone
  • tst_QXmlStream
  • tst_qmakelib
39470
513 else-
514 return ((jd + 1) % 7) + 7;
executed 8 times by 1 test: return ((jd + 1) % 7) + 7;
Executed by:
  • tst_QDate
8
515}-
516-
517/*!-
518 Returns the day of the year (1 to 365 or 366 on leap years) for-
519 this date.-
520-
521 Returns 0 if the date is invalid.-
522-
523 \sa day(), dayOfWeek()-
524*/-
525-
526int QDate::dayOfYear() const-
527{-
528 if (isNull())
isNull()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 1907 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
1-1907
529 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • tst_QDate
1
530-
531 return jd - julianDayFromDate(year(), 1, 1) + 1;
executed 1907 times by 3 tests: return jd - julianDayFromDate(year(), 1, 1) + 1;
Executed by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
1907
532}-
533-
534/*!-
535 Returns the number of days in the month (28 to 31) for this date.-
536-
537 Returns 0 if the date is invalid.-
538-
539 \sa day(), daysInYear()-
540*/-
541-
542int QDate::daysInMonth() const-
543{-
544 if (isNull())
isNull()Description
TRUEevaluated 41 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTimeEdit
FALSEevaluated 4510 times by 8 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QStyleSheetStyle
  • tst_QTime
41-4510
545 return 0;
executed 41 times by 2 tests: return 0;
Executed by:
  • tst_QDate
  • tst_QDateTimeEdit
41
546-
547 const ParsedDate pd = getDateFromJulianDay(jd);-
548 if (pd.month == 2 && isLeapYear(pd.year))
pd.month == 2Description
TRUEevaluated 223 times by 7 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QStyleSheetStyle
FALSEevaluated 4287 times by 8 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QStyleSheetStyle
  • tst_QTime
isLeapYear(pd.year)Description
TRUEevaluated 159 times by 7 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QStyleSheetStyle
FALSEevaluated 64 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
64-4287
549 return 29;
executed 159 times by 7 tests: return 29;
Executed by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QStyleSheetStyle
159
550 else-
551 return monthDays[pd.month];
executed 4351 times by 8 tests: return monthDays[pd.month];
Executed by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QStyleSheetStyle
  • tst_QTime
4351
552}-
553-
554/*!-
555 Returns the number of days in the year (365 or 366) for this date.-
556-
557 Returns 0 if the date is invalid.-
558-
559 \sa day(), daysInMonth()-
560*/-
561-
562int QDate::daysInYear() const-
563{-
564 if (isNull())
isNull()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QDate
1-4
565 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • tst_QDate
1
566-
567 return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365;
executed 4 times by 1 test: return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365;
Executed by:
  • tst_QDate
4
568}-
569-
570/*!-
571 Returns the week number (1 to 53), and stores the year in-
572 *\a{yearNumber} unless \a yearNumber is null (the default).-
573-
574 Returns 0 if the date is invalid.-
575-
576 In accordance with ISO 8601, weeks start on Monday and the first-
577 Thursday of a year is always in week 1 of that year. Most years-
578 have 52 weeks, but some have 53.-
579-
580 *\a{yearNumber} is not always the same as year(). For example, 1-
581 January 2000 has week number 52 in the year 1999, and 31 December-
582 2002 has week number 1 in the year 2003.-
583-
584 \sa isValid()-
585*/-
586-
587int QDate::weekNumber(int *yearNumber) const-
588{-
589 if (!isValid())
!isValid()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 1894 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
3-1894
590 return 0;
executed 3 times by 1 test: return 0;
Executed by:
  • tst_QDate
3
591-
592 int year = QDate::year();-
593 int yday = dayOfYear();-
594 int wday = dayOfWeek();-
595-
596 int week = (yday - wday + 10) / 7;-
597-
598 if (week == 0) {
week == 0Description
TRUEevaluated 172 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 1722 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
172-1722
599 // last week of previous year-
600 --year;-
601 week = (yday + 365 + (QDate::isLeapYear(year) ? 1 : 0) - wday + 10) / 7;
QDate::isLeapYear(year)Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 130 times by 1 test
Evaluated by:
  • tst_QDate
42-130
602 Q_ASSERT(week == 52 || week == 53);-
603 } else if (week == 53) {
executed 172 times by 1 test: end of block
Executed by:
  • tst_QDate
week == 53Description
TRUEevaluated 315 times by 2 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
FALSEevaluated 1407 times by 3 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
172-1407
604 // maybe first week of next year-
605 int w = (yday - 365 - (QDate::isLeapYear(year) ? 1 : 0) - wday + 10) / 7;
QDate::isLeapYear(year)Description
TRUEevaluated 96 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 219 times by 2 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
96-219
606 if (w > 0) {
w > 0Description
TRUEevaluated 173 times by 2 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
FALSEevaluated 142 times by 1 test
Evaluated by:
  • tst_QDate
142-173
607 ++year;-
608 week = w;-
609 }
executed 173 times by 2 tests: end of block
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
173
610 Q_ASSERT(week == 53 || week == 1);-
611 }
executed 315 times by 2 tests: end of block
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
315
612-
613 if (yearNumber != 0)
yearNumber != 0Description
TRUEevaluated 1600 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 294 times by 2 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
294-1600
614 *yearNumber = year;
executed 1600 times by 1 test: *yearNumber = year;
Executed by:
  • tst_QDate
1600
615 return week;
executed 1894 times by 3 tests: return week;
Executed by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
1894
616}-
617-
618#ifndef QT_NO_TEXTDATE-
619/*!-
620 \since 4.5-
621-
622 Returns the short name of the \a month for the representation specified-
623 by \a type.-
624-
625 The months are enumerated using the following convention:-
626-
627 \list-
628 \li 1 = "Jan"-
629 \li 2 = "Feb"-
630 \li 3 = "Mar"-
631 \li 4 = "Apr"-
632 \li 5 = "May"-
633 \li 6 = "Jun"-
634 \li 7 = "Jul"-
635 \li 8 = "Aug"-
636 \li 9 = "Sep"-
637 \li 10 = "Oct"-
638 \li 11 = "Nov"-
639 \li 12 = "Dec"-
640 \endlist-
641-
642 The month names will be localized according to the system's-
643 locale settings, i.e. using QLocale::system().-
644-
645 Returns an empty string if the date is invalid.-
646-
647 \sa toString(), longMonthName(), shortDayName(), longDayName()-
648*/-
649-
650QString QDate::shortMonthName(int month, QDate::MonthNameType type)-
651{-
652 if (month >= 1 || month <= 12) {
month >= 1Description
TRUEevaluated 624 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
month <= 12Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
FALSEnever evaluated
0-624
653 switch (type) {-
654 case QDate::DateFormat:
executed 612 times by 4 tests: case QDate::DateFormat:
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
612
655 return QLocale::system().monthName(month, QLocale::ShortFormat);
executed 612 times by 4 tests: return QLocale::system().monthName(month, QLocale::ShortFormat);
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
612
656 case QDate::StandaloneFormat:
executed 14 times by 1 test: case QDate::StandaloneFormat:
Executed by:
  • tst_QDate
14
657 return QLocale::system().standaloneMonthName(month, QLocale::ShortFormat);
executed 14 times by 1 test: return QLocale::system().standaloneMonthName(month, QLocale::ShortFormat);
Executed by:
  • tst_QDate
14
658 }-
659 }
never executed: end of block
0
660 return QString();
never executed: return QString();
0
661}-
662-
663/*!-
664 \since 4.5-
665-
666 Returns the long name of the \a month for the representation specified-
667 by \a type.-
668-
669 The months are enumerated using the following convention:-
670-
671 \list-
672 \li 1 = "January"-
673 \li 2 = "February"-
674 \li 3 = "March"-
675 \li 4 = "April"-
676 \li 5 = "May"-
677 \li 6 = "June"-
678 \li 7 = "July"-
679 \li 8 = "August"-
680 \li 9 = "September"-
681 \li 10 = "October"-
682 \li 11 = "November"-
683 \li 12 = "December"-
684 \endlist-
685-
686 The month names will be localized according to the system's-
687 locale settings, i.e. using QLocale::system().-
688-
689 Returns an empty string if the date is invalid.-
690-
691 \sa toString(), shortMonthName(), shortDayName(), longDayName()-
692*/-
693-
694QString QDate::longMonthName(int month, MonthNameType type)-
695{-
696 if (month >= 1 && month <= 12) {
month >= 1Description
TRUEevaluated 38 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
month <= 12Description
TRUEevaluated 36 times by 3 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
2-38
697 switch (type) {-
698 case QDate::DateFormat:
executed 24 times by 3 tests: case QDate::DateFormat:
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
24
699 return QLocale::system().monthName(month, QLocale::LongFormat);
executed 24 times by 3 tests: return QLocale::system().monthName(month, QLocale::LongFormat);
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
24
700 case QDate::StandaloneFormat:
executed 12 times by 1 test: case QDate::StandaloneFormat:
Executed by:
  • tst_QDate
12
701 return QLocale::system().standaloneMonthName(month, QLocale::LongFormat);
executed 12 times by 1 test: return QLocale::system().standaloneMonthName(month, QLocale::LongFormat);
Executed by:
  • tst_QDate
12
702 }-
703 }
never executed: end of block
0
704 return QString();
executed 4 times by 1 test: return QString();
Executed by:
  • tst_QDate
4
705}-
706-
707/*!-
708 \since 4.5-
709-
710 Returns the short name of the \a weekday for the representation specified-
711 by \a type.-
712-
713 The days are enumerated using the following convention:-
714-
715 \list-
716 \li 1 = "Mon"-
717 \li 2 = "Tue"-
718 \li 3 = "Wed"-
719 \li 4 = "Thu"-
720 \li 5 = "Fri"-
721 \li 6 = "Sat"-
722 \li 7 = "Sun"-
723 \endlist-
724-
725 The day names will be localized according to the system's-
726 locale settings, i.e. using QLocale::system().-
727-
728 Returns an empty string if the date is invalid.-
729-
730 \sa toString(), shortMonthName(), longMonthName(), longDayName()-
731*/-
732-
733QString QDate::shortDayName(int weekday, MonthNameType type)-
734{-
735 if (weekday >= 1 && weekday <= 7) {
weekday >= 1Description
TRUEevaluated 422 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
weekday <= 7Description
TRUEevaluated 420 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
2-422
736 switch (type) {-
737 case QDate::DateFormat:
executed 413 times by 4 tests: case QDate::DateFormat:
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
413
738 return QLocale::system().dayName(weekday, QLocale::ShortFormat);
executed 413 times by 4 tests: return QLocale::system().dayName(weekday, QLocale::ShortFormat);
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_qmakelib
413
739 case QDate::StandaloneFormat:
executed 7 times by 1 test: case QDate::StandaloneFormat:
Executed by:
  • tst_QDate
7
740 return QLocale::system().standaloneDayName(weekday, QLocale::ShortFormat);
executed 7 times by 1 test: return QLocale::system().standaloneDayName(weekday, QLocale::ShortFormat);
Executed by:
  • tst_QDate
7
741 }-
742 }
never executed: end of block
0
743 return QString();
executed 4 times by 1 test: return QString();
Executed by:
  • tst_QDate
4
744}-
745-
746/*!-
747 \since 4.5-
748-
749 Returns the long name of the \a weekday for the representation specified-
750 by \a type.-
751-
752 The days are enumerated using the following convention:-
753-
754 \list-
755 \li 1 = "Monday"-
756 \li 2 = "Tuesday"-
757 \li 3 = "Wednesday"-
758 \li 4 = "Thursday"-
759 \li 5 = "Friday"-
760 \li 6 = "Saturday"-
761 \li 7 = "Sunday"-
762 \endlist-
763-
764 The day names will be localized according to the system's-
765 locale settings, i.e. using QLocale::system().-
766-
767 Returns an empty string if the date is invalid.-
768-
769 \sa toString(), shortDayName(), shortMonthName(), longMonthName()-
770*/-
771-
772QString QDate::longDayName(int weekday, MonthNameType type)-
773{-
774 if (weekday >= 1 && weekday <= 7) {
weekday >= 1Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
weekday <= 7Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
2-23
775 switch (type) {-
776 case QDate::DateFormat:
executed 14 times by 1 test: case QDate::DateFormat:
Executed by:
  • tst_QDate
14
777 return QLocale::system().dayName(weekday, QLocale::LongFormat);
executed 14 times by 1 test: return QLocale::system().dayName(weekday, QLocale::LongFormat);
Executed by:
  • tst_QDate
14
778 case QDate::StandaloneFormat:
executed 7 times by 1 test: case QDate::StandaloneFormat:
Executed by:
  • tst_QDate
7
779 return QLocale::system().standaloneDayName(weekday, QLocale::LongFormat);
executed 7 times by 1 test: return QLocale::system().standaloneDayName(weekday, QLocale::LongFormat);
Executed by:
  • tst_QDate
7
780 }-
781 }
never executed: end of block
0
782 return QString();
executed 4 times by 1 test: return QString();
Executed by:
  • tst_QDate
4
783}-
784#endif //QT_NO_TEXTDATE-
785-
786#ifndef QT_NO_DATESTRING-
787-
788#ifndef QT_NO_TEXTDATE-
789static QString toStringTextDate(QDate date)-
790{-
791 const ParsedDate pd = getDateFromJulianDay(date.toJulianDay());-
792 static const QLatin1Char sp(' ');-
793 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:
  • tst_QDate
2
794 + 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:
  • tst_QDate
2
795 + 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:
  • tst_QDate
2
796 + 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:
  • tst_QDate
2
797}-
798#endif // QT_NO_TEXTDATE-
799-
800static QString toStringIsoDate(qint64 jd)-
801{-
802 const ParsedDate pd = getDateFromJulianDay(jd);-
803 if (pd.year >= 0 && pd.year <= 9999)
pd.year >= 0Description
TRUEevaluated 36 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QVariant
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
pd.year <= 9999Description
TRUEevaluated 36 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QVariant
FALSEnever evaluated
0-36
804 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:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QVariant
36
805 else-
806 return QString();
executed 3 times by 2 tests: return QString();
Executed by:
  • tst_QDate
  • tst_QDateTime
3
807}-
808-
809/*!-
810 \fn QString QDate::toString(Qt::DateFormat format) const-
811-
812 \overload-
813-
814 Returns the date as a string. The \a format parameter determines-
815 the format of the string.-
816-
817 If the \a format is Qt::TextDate, the string is formatted in-
818 the default way. QDate::shortDayName() and QDate::shortMonthName()-
819 are used to generate the string, so the day and month names will-
820 be localized names using the system locale, i.e. QLocale::system(). An-
821 example of this formatting is "Sat May 20 1995".-
822-
823 If the \a format is Qt::ISODate, the string format corresponds-
824 to the ISO 8601 extended specification for representations of-
825 dates and times, taking the form YYYY-MM-DD, where YYYY is the-
826 year, MM is the month of the year (between 01 and 12), and DD is-
827 the day of the month between 01 and 31.-
828-
829 If the \a format is Qt::SystemLocaleShortDate or-
830 Qt::SystemLocaleLongDate, the string format depends on the locale-
831 settings of the system. Identical to calling-
832 QLocale::system().toString(date, QLocale::ShortFormat) or-
833 QLocale::system().toString(date, QLocale::LongFormat).-
834-
835 If the \a format is Qt::DefaultLocaleShortDate or-
836 Qt::DefaultLocaleLongDate, the string format depends on the-
837 default application locale. This is the locale set with-
838 QLocale::setDefault(), or the system locale if no default locale-
839 has been set. Identical to calling-
840 \l {QLocale::toString()}{QLocale().toString(date, QLocale::ShortFormat) } or-
841 \l {QLocale::toString()}{QLocale().toString(date, QLocale::LongFormat)}.-
842-
843 If the \a format is Qt::RFC2822Date, the string is formatted in-
844 an \l{RFC 2822} compatible way. An example of this formatting is-
845 "20 May 1995".-
846-
847 If the date is invalid, an empty string will be returned.-
848-
849 \warning The Qt::ISODate format is only valid for years in the-
850 range 0 to 9999. This restriction may apply to locale-aware-
851 formats as well, depending on the locale settings.-
852-
853 \sa fromString(), shortDayName(), shortMonthName(), QLocale::toString()-
854*/-
855QString QDate::toString(Qt::DateFormat format) const-
856{-
857 if (!isValid())
!isValid()Description
TRUEevaluated 2 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QVariant
FALSEevaluated 98 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QVariant
2-98
858 return QString();
executed 2 times by 2 tests: return QString();
Executed by:
  • tst_QDate
  • tst_QVariant
2
859-
860 switch (format) {-
861 case Qt::SystemLocaleDate:
never executed: case Qt::SystemLocaleDate:
0
862 case Qt::SystemLocaleShortDate:
executed 14 times by 1 test: case Qt::SystemLocaleShortDate:
Executed by:
  • tst_QDate
14
863 return QLocale::system().toString(*this, QLocale::ShortFormat);
executed 14 times by 1 test: return QLocale::system().toString(*this, QLocale::ShortFormat);
Executed by:
  • tst_QDate
14
864 case Qt::SystemLocaleLongDate:
executed 14 times by 1 test: case Qt::SystemLocaleLongDate:
Executed by:
  • tst_QDate
14
865 return QLocale::system().toString(*this, QLocale::LongFormat);
executed 14 times by 1 test: return QLocale::system().toString(*this, QLocale::LongFormat);
Executed by:
  • tst_QDate
14
866 case Qt::LocaleDate:
never executed: case Qt::LocaleDate:
0
867 case Qt::DefaultLocaleShortDate:
executed 14 times by 1 test: case Qt::DefaultLocaleShortDate:
Executed by:
  • tst_QDate
14
868 return QLocale().toString(*this, QLocale::ShortFormat);
executed 14 times by 1 test: return QLocale().toString(*this, QLocale::ShortFormat);
Executed by:
  • tst_QDate
14
869 case Qt::DefaultLocaleLongDate:
executed 14 times by 1 test: case Qt::DefaultLocaleLongDate:
Executed by:
  • tst_QDate
14
870 return QLocale().toString(*this, QLocale::LongFormat);
executed 14 times by 1 test: return QLocale().toString(*this, QLocale::LongFormat);
Executed by:
  • tst_QDate
14
871 case Qt::RFC2822Date:
executed 1 time by 1 test: case Qt::RFC2822Date:
Executed by:
  • tst_QDate
1
872 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:
  • tst_QDate
executed 1 time by 1 test: return qstring_literal_temp;
Executed by:
  • tst_QDate
1
873 default:
never executed: default:
0
874#ifndef QT_NO_TEXTDATE-
875 case Qt::TextDate:
executed 2 times by 1 test: case Qt::TextDate:
Executed by:
  • tst_QDate
2
876 return toStringTextDate(*this);
executed 2 times by 1 test: return toStringTextDate(*this);
Executed by:
  • tst_QDate
2
877#endif-
878 case Qt::ISODate:
executed 39 times by 5 tests: case Qt::ISODate:
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QVariant
39
879 return toStringIsoDate(jd);
executed 39 times by 5 tests: return toStringIsoDate(jd);
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QVariant
39
880 }-
881}-
882-
883/*!-
884 Returns the date as a string. The \a format parameter determines-
885 the format of the result string.-
886-
887 These expressions may be used:-
888-
889 \table-
890 \header \li Expression \li Output-
891 \row \li d \li the day as number without a leading zero (1 to 31)-
892 \row \li dd \li the day as number with a leading zero (01 to 31)-
893 \row \li ddd-
894 \li the abbreviated localized day name (e.g. 'Mon' to 'Sun').-
895 Uses the system locale to localize the name, i.e. QLocale::system().-
896 \row \li dddd-
897 \li the long localized day name (e.g. 'Monday' to 'Sunday').-
898 Uses the system locale to localize the name, i.e. QLocale::system().-
899 \row \li M \li the month as number without a leading zero (1 to 12)-
900 \row \li MM \li the month as number with a leading zero (01 to 12)-
901 \row \li MMM-
902 \li the abbreviated localized month name (e.g. 'Jan' to 'Dec').-
903 Uses the system locale to localize the name, i.e. QLocale::system().-
904 \row \li MMMM-
905 \li the long localized month name (e.g. 'January' to 'December').-
906 Uses the system locale to localize the name, i.e. QLocale::system().-
907 \row \li yy \li the year as two digit number (00 to 99)-
908 \row \li yyyy \li the year as four digit number. If the year is negative,-
909 a minus sign is prepended in addition.-
910 \endtable-
911-
912 All other input characters will be ignored. Any sequence of characters that-
913 are enclosed in single quotes will be treated as text and not be used as an-
914 expression. Two consecutive single quotes ("''") are replaced by a singlequote-
915 in the output. Formats without separators (e.g. "ddMM") are currently not supported.-
916-
917 Example format strings (assuming that the QDate is the 20 July-
918 1969):-
919-
920 \table-
921 \header \li Format \li Result-
922 \row \li dd.MM.yyyy \li 20.07.1969-
923 \row \li ddd MMMM d yy \li Sun July 20 69-
924 \row \li 'The day is' dddd \li The day is Sunday-
925 \endtable-
926-
927 If the datetime is invalid, an empty string will be returned.-
928-
929 \sa fromString(), QDateTime::toString(), QTime::toString(), QLocale::toString()-
930-
931*/-
932QString QDate::toString(const QString& format) const-
933{-
934 return QLocale::system().toString(*this, format);
executed 13977 times by 8 tests: return QLocale::system().toString(*this, format);
Executed by:
  • tst_QCalendarWidget
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QMetaType
  • tst_QVariant
13977
935}-
936#endif //QT_NO_DATESTRING-
937-
938/*!-
939 \fn bool QDate::setYMD(int y, int m, int d)-
940-
941 \deprecated in 5.0, use setDate() instead.-
942-
943 Sets the date's year \a y, month \a m, and day \a d.-
944-
945 If \a y is in the range 0 to 99, it is interpreted as 1900 to-
946 1999.-
947 Returns \c false if the date is invalid.-
948-
949 Use setDate() instead.-
950*/-
951-
952/*!-
953 \since 4.2-
954-
955 Sets the date's \a year, \a month, and \a day. Returns \c true if-
956 the date is valid; otherwise returns \c false.-
957-
958 If the specified date is invalid, the QDate object is set to be-
959 invalid.-
960-
961 \sa isValid()-
962*/-
963bool QDate::setDate(int year, int month, int day)-
964{-
965 if (isValid(year, month, day))
isValid(year, month, day)Description
TRUEevaluated 21571360 times by 106 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
FALSEevaluated 11380 times by 6 tests
Evaluated by:
  • tst_QDBusMarshall
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QNetworkCookie
  • tst_QTime
11380-21571360
966 jd = julianDayFromDate(year, month, day);
executed 21573166 times by 106 tests: jd = julianDayFromDate(year, month, day);
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
21573166
967 else-
968 jd = nullJd();
executed 11380 times by 6 tests: jd = nullJd();
Executed by:
  • tst_QDBusMarshall
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QNetworkCookie
  • tst_QTime
11380
969-
970 return isValid();
executed 21589453 times by 106 tests: return isValid();
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
21589453
971}-
972-
973/*!-
974 \since 4.5-
975-
976 Extracts the date's year, month, and day, and assigns them to-
977 *\a year, *\a month, and *\a day. The pointers may be null.-
978-
979 Returns 0 if the date is invalid.-
980-
981 \note In Qt versions prior to 5.7, this function is marked as non-\c{const}.-
982-
983 \sa year(), month(), day(), isValid()-
984*/-
985void QDate::getDate(int *year, int *month, int *day) const-
986{-
987 ParsedDate pd = { 0, 0, 0 };-
988 if (isValid())
isValid()Description
TRUEevaluated 13951235 times by 101 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
3-13951235
989 pd = getDateFromJulianDay(jd);
executed 13956030 times by 101 tests: pd = getDateFromJulianDay(jd);
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
13956030
990-
991 if (year)
yearDescription
TRUEevaluated 13956030 times by 101 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDateTime
3-13956030
992 *year = pd.year;
executed 13956030 times by 101 tests: *year = pd.year;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
13956030
993 if (month)
monthDescription
TRUEevaluated 13955044 times by 101 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDateTime
3-13955044
994 *month = pd.month;
executed 13956030 times by 101 tests: *month = pd.month;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
13956030
995 if (day)
dayDescription
TRUEevaluated 13942777 times by 101 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDateTime
3-13942777
996 *day = pd.day;
executed 13954660 times by 101 tests: *day = pd.day;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
13954660
997}
executed 13941005 times by 101 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
13941005
998-
999#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)-
1000/*!-
1001 \overload-
1002 \internal-
1003*/-
1004void QDate::getDate(int *year, int *month, int *day)-
1005{-
1006 qAsConst(*this).getDate(year, month, day);-
1007}
executed 13947892 times by 101 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • ...
13947892
1008#endif // < Qt 6-
1009-
1010/*!-
1011 Returns a QDate object containing a date \a ndays later than the-
1012 date of this object (or earlier if \a ndays is negative).-
1013-
1014 Returns a null date if the current date is invalid or the new date is-
1015 out of range.-
1016-
1017 \sa addMonths(), addYears(), daysTo()-
1018*/-
1019-
1020QDate QDate::addDays(qint64 ndays) const-
1021{-
1022 if (isNull())
isNull()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 630822 times by 13 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
  • tst_QTimeZone
1-630822
1023 return QDate();
executed 1 time by 1 test: return QDate();
Executed by:
  • tst_QDate
1
1024-
1025 // Due to limits on minJd() and maxJd() we know that any overflow-
1026 // will be invalid and caught by fromJulianDay().-
1027 return fromJulianDay(jd + ndays);
executed 630822 times by 13 tests: return fromJulianDay(jd + ndays);
Executed by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
  • tst_QTimeZone
630822
1028}-
1029-
1030/*!-
1031 Returns a QDate object containing a date \a nmonths later than the-
1032 date of this object (or earlier if \a nmonths is negative).-
1033-
1034 \note If the ending day/month combination does not exist in the-
1035 resulting month/year, this function will return a date that is the-
1036 latest valid date.-
1037-
1038 \sa addDays(), addYears()-
1039*/-
1040-
1041QDate QDate::addMonths(int nmonths) const-
1042{-
1043 if (!isValid())
!isValid()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 172 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
1-172
1044 return QDate();
executed 1 time by 1 test: return QDate();
Executed by:
  • tst_QDate
1
1045 if (!nmonths)
!nmonthsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 168 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
4-168
1046 return *this;
executed 4 times by 1 test: return *this;
Executed by:
  • tst_QDateTime
4
1047-
1048 int old_y, y, m, d;-
1049 {-
1050 const ParsedDate pd = getDateFromJulianDay(jd);-
1051 y = pd.year;-
1052 m = pd.month;-
1053 d = pd.day;-
1054 }-
1055 old_y = y;-
1056-
1057 bool increasing = nmonths > 0;-
1058-
1059 while (nmonths != 0) {
nmonths != 0Description
TRUEevaluated 188 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 168 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
168-188
1060 if (nmonths < 0 && nmonths + 12 <= 0) {
nmonths < 0Description
TRUEevaluated 97 times by 3 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 91 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
nmonths + 12 <= 0Description
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 82 times by 3 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
15-97
1061 y--;-
1062 nmonths+=12;-
1063 } else if (nmonths < 0) {
executed 15 times by 2 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
nmonths < 0Description
TRUEevaluated 82 times by 3 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 91 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
15-91
1064 m+= nmonths;-
1065 nmonths = 0;-
1066 if (m <= 0) {
m <= 0Description
TRUEevaluated 49 times by 3 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 33 times by 3 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
33-49
1067 --y;-
1068 m += 12;-
1069 }
executed 49 times by 3 tests: end of block
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
49
1070 } else if (nmonths - 12 >= 0) {
executed 82 times by 3 tests: end of block
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
nmonths - 12 >= 0Description
TRUEevaluated 16 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 75 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
16-82
1071 y++;-
1072 nmonths -= 12;-
1073 } else if (m == 12) {
executed 16 times by 2 tests: end of block
Executed by:
  • tst_QDate
  • tst_QDateTime
m == 12Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 73 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
2-73
1074 y++;-
1075 m = 0;-
1076 } else {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QDate
2
1077 m += nmonths;-
1078 nmonths = 0;-
1079 if (m > 12) {
m > 12Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 72 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
1-72
1080 ++y;-
1081 m -= 12;-
1082 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QDate
1
1083 }
executed 73 times by 4 tests: end of block
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
73
1084 }-
1085-
1086 // was there a sign change?-
1087 if ((old_y > 0 && y <= 0) ||
old_y > 0Description
TRUEevaluated 165 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDate
y <= 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 163 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
2-165
1088 (old_y < 0 && y >= 0))
old_y < 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 163 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
y >= 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
1-163
1089 // yes, adjust the date by +1 or -1 years-
1090 y += increasing ? +1 : -1;
executed 4 times by 1 test: y += increasing ? +1 : -1;
Executed by:
  • tst_QDate
increasingDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
2-4
1091-
1092 return fixedDate(y, m, d);
executed 168 times by 4 tests: return fixedDate(y, m, d);
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
168
1093}-
1094-
1095/*!-
1096 Returns a QDate object containing a date \a nyears later than the-
1097 date of this object (or earlier if \a nyears is negative).-
1098-
1099 \note If the ending day/month combination does not exist in the-
1100 resulting year (i.e., if the date was Feb 29 and the final year is-
1101 not a leap year), this function will return a date that is the-
1102 latest valid date (that is, Feb 28).-
1103-
1104 \sa addDays(), addMonths()-
1105*/-
1106-
1107QDate QDate::addYears(int nyears) const-
1108{-
1109 if (!isValid())
!isValid()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 120 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
1-120
1110 return QDate();
executed 1 time by 1 test: return QDate();
Executed by:
  • tst_QDate
1
1111-
1112 ParsedDate pd = getDateFromJulianDay(jd);-
1113-
1114 int old_y = pd.year;-
1115 pd.year += nyears;-
1116-
1117 // was there a sign change?-
1118 if ((old_y > 0 && pd.year <= 0) ||
old_y > 0Description
TRUEevaluated 99 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
FALSEevaluated 21 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
pd.year <= 0Description
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 91 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
8-99
1119 (old_y < 0 && pd.year >= 0))
old_y < 0Description
TRUEevaluated 21 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 91 times by 4 tests
Evaluated by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
pd.year >= 0Description
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 13 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
8-91
1120 // yes, adjust the date by +1 or -1 years-
1121 pd.year += nyears > 0 ? +1 : -1;
executed 16 times by 2 tests: pd.year += nyears > 0 ? +1 : -1;
Executed by:
  • tst_QDate
  • tst_QDateTime
nyears > 0Description
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
8-16
1122-
1123 return fixedDate(pd.year, pd.month, pd.day);
executed 120 times by 4 tests: return fixedDate(pd.year, pd.month, pd.day);
Executed by:
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
120
1124}-
1125-
1126/*!-
1127 Returns the number of days from this date to \a d (which is-
1128 negative if \a d is earlier than this date).-
1129-
1130 Returns 0 if either date is invalid.-
1131-
1132 Example:-
1133 \snippet code/src_corelib_tools_qdatetime.cpp 0-
1134-
1135 \sa addDays()-
1136*/-
1137-
1138qint64 QDate::daysTo(const QDate &d) const-
1139{-
1140 if (isNull() || d.isNull())
isNull()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 18592 times by 13 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
d.isNull()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 18591 times by 13 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
1-18592
1141 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QDate
2
1142-
1143 // Due to limits on minJd() and maxJd() we know this will never overflow-
1144 return d.jd - jd;
executed 18591 times by 13 tests: return d.jd - jd;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QStyleSheetStyle
  • tst_QTime
18591
1145}-
1146-
1147-
1148/*!-
1149 \fn bool QDate::operator==(const QDate &d) const-
1150-
1151 Returns \c true if this date is equal to \a d; otherwise returns-
1152 false.-
1153-
1154*/-
1155-
1156/*!-
1157 \fn bool QDate::operator!=(const QDate &d) const-
1158-
1159 Returns \c true if this date is different from \a d; otherwise-
1160 returns \c false.-
1161*/-
1162-
1163/*!-
1164 \fn bool QDate::operator<(const QDate &d) const-
1165-
1166 Returns \c true if this date is earlier than \a d; otherwise returns-
1167 false.-
1168*/-
1169-
1170/*!-
1171 \fn bool QDate::operator<=(const QDate &d) const-
1172-
1173 Returns \c true if this date is earlier than or equal to \a d;-
1174 otherwise returns \c false.-
1175*/-
1176-
1177/*!-
1178 \fn bool QDate::operator>(const QDate &d) const-
1179-
1180 Returns \c true if this date is later than \a d; otherwise returns-
1181 false.-
1182*/-
1183-
1184/*!-
1185 \fn bool QDate::operator>=(const QDate &d) const-
1186-
1187 Returns \c true if this date is later than or equal to \a d;-
1188 otherwise returns \c false.-
1189*/-
1190-
1191/*!-
1192 \fn QDate::currentDate()-
1193 Returns the current date, as reported by the system clock.-
1194-
1195 \sa QTime::currentTime(), QDateTime::currentDateTime()-
1196*/-
1197-
1198#ifndef QT_NO_DATESTRING-
1199/*!-
1200 \fn QDate QDate::fromString(const QString &string, Qt::DateFormat format)-
1201-
1202 Returns the QDate represented by the \a string, using the-
1203 \a format given, or an invalid date if the string cannot be-
1204 parsed.-
1205-
1206 Note for Qt::TextDate: It is recommended that you use the-
1207 English short month names (e.g. "Jan"). Although localized month-
1208 names can also be used, they depend on the user's locale settings.-
1209-
1210 \sa toString(), QLocale::toDate()-
1211*/-
1212QDate QDate::fromString(const QString& string, Qt::DateFormat format)-
1213{-
1214 if (string.isEmpty())
string.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 111 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
2-111
1215 return QDate();
executed 2 times by 1 test: return QDate();
Executed by:
  • tst_QDate
2
1216-
1217 switch (format) {-
1218 case Qt::SystemLocaleDate:
never executed: case Qt::SystemLocaleDate:
0
1219 case Qt::SystemLocaleShortDate:
never executed: case Qt::SystemLocaleShortDate:
0
1220 return QLocale::system().toDate(string, QLocale::ShortFormat);
never executed: return QLocale::system().toDate(string, QLocale::ShortFormat);
0
1221 case Qt::SystemLocaleLongDate:
never executed: case Qt::SystemLocaleLongDate:
0
1222 return QLocale::system().toDate(string, QLocale::LongFormat);
never executed: return QLocale::system().toDate(string, QLocale::LongFormat);
0
1223 case Qt::LocaleDate:
never executed: case Qt::LocaleDate:
0
1224 case Qt::DefaultLocaleShortDate:
never executed: case Qt::DefaultLocaleShortDate:
0
1225 return QLocale().toDate(string, QLocale::ShortFormat);
never executed: return QLocale().toDate(string, QLocale::ShortFormat);
0
1226 case Qt::DefaultLocaleLongDate:
never executed: case Qt::DefaultLocaleLongDate:
0
1227 return QLocale().toDate(string, QLocale::LongFormat);
never executed: return QLocale().toDate(string, QLocale::LongFormat);
0
1228 case Qt::RFC2822Date:
executed 21 times by 1 test: case Qt::RFC2822Date:
Executed by:
  • tst_QDate
21
1229 return rfcDateImpl(string).date;
executed 21 times by 1 test: return rfcDateImpl(string).date;
Executed by:
  • tst_QDate
21
1230 default:
never executed: default:
0
1231#ifndef QT_NO_TEXTDATE-
1232 case Qt::TextDate: {
executed 14 times by 1 test: case Qt::TextDate:
Executed by:
  • tst_QDate
14
1233 QVector<QStringRef> parts = string.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);-
1234-
1235 if (parts.count() != 4)
parts.count() != 4Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 13 times by 1 test
Evaluated by:
  • tst_QDate
1-13
1236 return QDate();
executed 1 time by 1 test: return QDate();
Executed by:
  • tst_QDate
1
1237-
1238 QStringRef monthName = parts.at(1);-
1239 const int month = fromShortMonthName(monthName);-
1240 if (month == -1) {
month == -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QDate
1-12
1241 // Month name matches neither English nor other localised name.-
1242 return QDate();
executed 1 time by 1 test: return QDate();
Executed by:
  • tst_QDate
1
1243 }-
1244-
1245 bool ok = false;-
1246 int year = parts.at(3).toInt(&ok);-
1247 if (!ok)
!okDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 11 times by 1 test
Evaluated by:
  • tst_QDate
1-11
1248 return QDate();
executed 1 time by 1 test: return QDate();
Executed by:
  • tst_QDate
1
1249-
1250 return QDate(year, month, parts.at(2).toInt());
executed 11 times by 1 test: return QDate(year, month, parts.at(2).toInt());
Executed by:
  • tst_QDate
11
1251 }-
1252#endif // QT_NO_TEXTDATE-
1253 case Qt::ISODate: {
executed 76 times by 5 tests: case Qt::ISODate:
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
76
1254 // Semi-strict parsing, must be long enough and have non-numeric separators-
1255 if (string.size() < 10 || string.at(4).isDigit() || string.at(7).isDigit()
string.size() < 10Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QVariant
FALSEevaluated 75 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
string.at(4).isDigit()Description
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
FALSEevaluated 69 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
string.at(7).isDigit()Description
TRUEnever evaluated
FALSEevaluated 69 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
0-75
1256 || (string.size() > 10 && string.at(10).isDigit())) {
string.size() > 10Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 66 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
string.at(10).isDigit()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QDate
1-66
1257 return QDate();
executed 8 times by 3 tests: return QDate();
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QVariant
8
1258 }-
1259 const int year = string.midRef(0, 4).toInt();-
1260 if (year <= 0 || year > 9999)
year <= 0Description
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QDate
  • tst_QVariant
FALSEevaluated 64 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
year > 9999Description
TRUEnever evaluated
FALSEevaluated 64 times by 5 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
0-64
1261 return QDate();
executed 4 times by 2 tests: return QDate();
Executed by:
  • tst_QDate
  • tst_QVariant
4
1262 return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt());
executed 64 times by 5 tests: return QDate(year, string.midRef(5, 2).toInt(), string.midRef(8, 2).toInt());
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
64
1263 }-
1264 }-
1265 return QDate();
never executed: return QDate();
0
1266}-
1267-
1268/*!-
1269 \fn QDate::fromString(const QString &string, const QString &format)-
1270-
1271 Returns the QDate represented by the \a string, using the \a-
1272 format given, or an invalid date if the string cannot be parsed.-
1273-
1274 These expressions may be used for the format:-
1275-
1276 \table-
1277 \header \li Expression \li Output-
1278 \row \li d \li The day as a number without a leading zero (1 to 31)-
1279 \row \li dd \li The day as a number with a leading zero (01 to 31)-
1280 \row \li ddd-
1281 \li The abbreviated localized day name (e.g. 'Mon' to 'Sun').-
1282 Uses the system locale to localize the name, i.e. QLocale::system().-
1283 \row \li dddd-
1284 \li The long localized day name (e.g. 'Monday' to 'Sunday').-
1285 Uses the system locale to localize the name, i.e. QLocale::system().-
1286 \row \li M \li The month as a number without a leading zero (1 to 12)-
1287 \row \li MM \li The month as a number with a leading zero (01 to 12)-
1288 \row \li MMM-
1289 \li The abbreviated localized month name (e.g. 'Jan' to 'Dec').-
1290 Uses the system locale to localize the name, i.e. QLocale::system().-
1291 \row \li MMMM-
1292 \li The long localized month name (e.g. 'January' to 'December').-
1293 Uses the system locale to localize the name, i.e. QLocale::system().-
1294 \row \li yy \li The year as two digit number (00 to 99)-
1295 \row \li yyyy \li The year as four digit number. If the year is negative,-
1296 a minus sign is prepended in addition.-
1297 \endtable-
1298-
1299 All other input characters will be treated as text. Any sequence-
1300 of characters that are enclosed in single quotes will also be-
1301 treated as text and will not be used as an expression. For example:-
1302-
1303 \snippet code/src_corelib_tools_qdatetime.cpp 1-
1304-
1305 If the format is not satisfied, an invalid QDate is returned. The-
1306 expressions that don't expect leading zeroes (d, M) will be-
1307 greedy. This means that they will use two digits even if this-
1308 will put them outside the accepted range of values and leaves too-
1309 few digits for other sections. For example, the following format-
1310 string could have meant January 30 but the M will grab two-
1311 digits, resulting in an invalid date:-
1312-
1313 \snippet code/src_corelib_tools_qdatetime.cpp 2-
1314-
1315 For any field that is not represented in the format the following-
1316 defaults are used:-
1317-
1318 \table-
1319 \header \li Field \li Default value-
1320 \row \li Year \li 1900-
1321 \row \li Month \li 1-
1322 \row \li Day \li 1-
1323 \endtable-
1324-
1325 The following examples demonstrate the default values:-
1326-
1327 \snippet code/src_corelib_tools_qdatetime.cpp 3-
1328-
1329 \sa toString(), QDateTime::fromString(), QTime::fromString(),-
1330 QLocale::toDate()-
1331*/-
1332-
1333QDate QDate::fromString(const QString &string, const QString &format)-
1334{-
1335 QDate date;-
1336#ifndef QT_BOOTSTRAPPED-
1337 QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString);-
1338 if (dt.parseFormat(format))
dt.parseFormat(format)Description
TRUEevaluated 44 times by 1 test
Evaluated by:
  • tst_QDate
FALSEnever evaluated
0-44
1339 dt.fromString(string, &date, 0);
executed 44 times by 1 test: dt.fromString(string, &date, 0);
Executed by:
  • tst_QDate
44
1340#else-
1341 Q_UNUSED(string);-
1342 Q_UNUSED(format);-
1343#endif-
1344 return date;
executed 44 times by 1 test: return date;
Executed by:
  • tst_QDate
44
1345}-
1346#endif // QT_NO_DATESTRING-
1347-
1348/*!-
1349 \overload-
1350-
1351 Returns \c true if the specified date (\a year, \a month, and \a-
1352 day) is valid; otherwise returns \c false.-
1353-
1354 Example:-
1355 \snippet code/src_corelib_tools_qdatetime.cpp 4-
1356-
1357 \sa isNull(), setDate()-
1358*/-
1359-
1360bool QDate::isValid(int year, int month, int day)-
1361{-
1362 // there is no year 0 in the Gregorian calendar-
1363 if (year == 0)
year == 0Description
TRUEevaluated 143 times by 4 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QTime
FALSEevaluated 21594977 times by 106 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
143-21594977
1364 return false;
executed 143 times by 4 tests: return false;
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QTime
143
1365-
1366 return (day > 0 && month > 0 && month <= 12) &&
executed 21588267 times by 106 tests: return (day > 0 && month > 0 && month <= 12) && (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year)));
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
21588267
1367 (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year)));
executed 21588267 times by 106 tests: return (day > 0 && month > 0 && month <= 12) && (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year)));
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
21588267
1368}-
1369-
1370/*!-
1371 \fn bool QDate::isLeapYear(int year)-
1372-
1373 Returns \c true if the specified \a year is a leap year; otherwise-
1374 returns \c false.-
1375*/-
1376-
1377bool QDate::isLeapYear(int y)-
1378{-
1379 // No year 0 in Gregorian calendar, so -1, -5, -9 etc are leap years-
1380 if ( y < 1)
y < 1Description
TRUEevaluated 9596 times by 1 test
Evaluated by:
  • tst_QDate
FALSEevaluated 27921 times by 9 tests
Evaluated by:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QStyleSheetStyle
  • tst_QTimeZone
9596-27921
1381 ++y;
executed 9596 times by 1 test: ++y;
Executed by:
  • tst_QDate
9596
1382-
1383 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:
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QStyleSheetStyle
  • tst_QTimeZone
37517
1384}-
1385-
1386/*! \fn static QDate QDate::fromJulianDay(qint64 jd)-
1387-
1388 Converts the Julian day \a jd to a QDate.-
1389-
1390 \sa toJulianDay()-
1391*/-
1392-
1393/*! \fn int QDate::toJulianDay() const-
1394-
1395 Converts the date to a Julian day.-
1396-
1397 \sa fromJulianDay()-
1398*/-
1399-
1400/*****************************************************************************-
1401 QTime member functions-
1402 *****************************************************************************/-
1403-
1404/*!-
1405 \class QTime-
1406 \inmodule QtCore-
1407 \reentrant-
1408-
1409 \brief The QTime class provides clock time functions.-
1410-
1411-
1412 A QTime object contains a clock time, i.e. the number of hours,-
1413 minutes, seconds, and milliseconds since midnight. It can read the-
1414 current time from the system clock and measure a span of elapsed-
1415 time. It provides functions for comparing times and for-
1416 manipulating a time by adding a number of milliseconds.-
1417-
1418 QTime uses the 24-hour clock format; it has no concept of AM/PM.-
1419 Unlike QDateTime, QTime knows nothing about time zones or-
1420 daylight-saving time (DST).-
1421-
1422 A QTime object is typically created either by giving the number-
1423 of hours, minutes, seconds, and milliseconds explicitly, or by-
1424 using the static function currentTime(), which creates a QTime-
1425 object that contains the system's local time. Note that the-
1426 accuracy depends on the accuracy of the underlying operating-
1427 system; not all systems provide 1-millisecond accuracy.-
1428-
1429 The hour(), minute(), second(), and msec() functions provide-
1430 access to the number of hours, minutes, seconds, and milliseconds-
1431 of the time. The same information is provided in textual format by-
1432 the toString() function.-
1433-
1434 QTime provides a full set of operators to compare two QTime-
1435 objects. QTime A is considered smaller than QTime B if A is-
1436 earlier than B.-
1437-
1438 The addSecs() and addMSecs() functions provide the time a given-
1439 number of seconds or milliseconds later than a given time.-
1440 Correspondingly, the number of seconds or milliseconds-
1441 between two times can be found using secsTo() or msecsTo().-
1442-
1443 QTime can be used to measure a span of elapsed time using the-
1444 start(), restart(), and elapsed() functions.-
1445-
1446 \sa QDate, QDateTime-
1447*/-
1448-
1449/*!-
1450 \fn QTime::QTime()-
1451-
1452 Constructs a null time object. A null time can be a QTime(0, 0, 0, 0)-
1453 (i.e., midnight) object, except that isNull() returns \c true and isValid()-
1454 returns \c false.-
1455-
1456 \sa isNull(), isValid()-
1457*/-
1458-
1459/*!-
1460 Constructs a time with hour \a h, minute \a m, seconds \a s and-
1461 milliseconds \a ms.-
1462-
1463 \a h must be in the range 0 to 23, \a m and \a s must be in the-
1464 range 0 to 59, and \a ms must be in the range 0 to 999.-
1465-
1466 \sa isValid()-
1467*/-
1468-
1469QTime::QTime(int h, int m, int s, int ms)-
1470{-
1471 setHMS(h, m, s, ms);-
1472}
executed 20948141 times by 107 tests: end of block
Executed by:
  • tst_Collections
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • ...
20948141
1473-
1474-
1475/*!-
1476 \fn bool QTime::isNull() const-
1477-
1478 Returns \c true if the time is null (i.e., the QTime object was-
1479 constructed using the default constructor); otherwise returns-
1480 false. A null time is also an invalid time.-
1481-
1482 \sa isValid()-
1483*/-
1484-
1485/*!-
1486 Returns \c true if the time is valid; otherwise returns \c false. For example,-
1487 the time 23:30:55.746 is valid, but 24:12:30 is invalid.-
1488-
1489 \sa isNull()-
1490*/-
1491-
1492bool QTime::isValid() const-
1493{-
1494 return mds > NullTime && mds < MSECS_PER_DAY;
executed 83770922 times by 109 tests: return mds > NullTime && mds < MSECS_PER_DAY;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDBusMetaType
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • ...
83770922
1495}-
1496-
1497-
1498/*!-
1499 Returns the hour part (0 to 23) of the time.-
1500-
1501 Returns -1 if the time is invalid.-
1502-
1503 \sa minute(), second(), msec()-
1504*/-
1505-
1506int QTime::hour() const-
1507{-
1508 if (!isValid())
!isValid()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 13963461 times by 103 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
4-13963461
1509 return -1;
executed 4 times by 1 test: return -1;
Executed by:
  • tst_QTime
4
1510-
1511 return ds() / MSECS_PER_HOUR;
executed 13972447 times by 103 tests: return ds() / MSECS_PER_HOUR;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
13972447
1512}-
1513-
1514/*!-
1515 Returns the minute part (0 to 59) of the time.-
1516-
1517 Returns -1 if the time is invalid.-
1518-
1519 \sa hour(), second(), msec()-
1520*/-
1521-
1522int QTime::minute() const-
1523{-
1524 if (!isValid())
!isValid()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 13965934 times by 103 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
4-13965934
1525 return -1;
executed 4 times by 1 test: return -1;
Executed by:
  • tst_QTime
4
1526-
1527 return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN;
executed 13966387 times by 103 tests: return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
13966387
1528}-
1529-
1530/*!-
1531 Returns the second part (0 to 59) of the time.-
1532-
1533 Returns -1 if the time is invalid.-
1534-
1535 \sa hour(), minute(), msec()-
1536*/-
1537-
1538int QTime::second() const-
1539{-
1540 if (!isValid())
!isValid()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 13964385 times by 103 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
4-13964385
1541 return -1;
executed 4 times by 1 test: return -1;
Executed by:
  • tst_QTime
4
1542-
1543 return (ds() / 1000)%SECS_PER_MIN;
executed 13948402 times by 103 tests: return (ds() / 1000)%SECS_PER_MIN;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
13948402
1544}-
1545-
1546/*!-
1547 Returns the millisecond part (0 to 999) of the time.-
1548-
1549 Returns -1 if the time is invalid.-
1550-
1551 \sa hour(), minute(), second()-
1552*/-
1553-
1554int QTime::msec() const-
1555{-
1556 if (!isValid())
!isValid()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 13962710 times by 103 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
3-13962710
1557 return -1;
executed 3 times by 1 test: return -1;
Executed by:
  • tst_QTime
3
1558-
1559 return ds() % 1000;
executed 13960494 times by 103 tests: return ds() % 1000;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • ...
13960494
1560}-
1561-
1562#ifndef QT_NO_DATESTRING-
1563/*!-
1564 \overload-
1565-
1566 Returns the time as a string. The \a format parameter determines-
1567 the format of the string.-
1568-
1569 If \a format is Qt::TextDate, the string format is HH:mm:ss;-
1570 e.g. 1 second before midnight would be "23:59:59".-
1571-
1572 If \a format is Qt::ISODate, the string format corresponds to the-
1573 ISO 8601 extended specification for representations of dates,-
1574 which is also HH:mm:ss.-
1575-
1576 If the \a format is Qt::SystemLocaleShortDate or-
1577 Qt::SystemLocaleLongDate, the string format depends on the locale-
1578 settings of the system. Identical to calling-
1579 QLocale::system().toString(time, QLocale::ShortFormat) or-
1580 QLocale::system().toString(time, QLocale::LongFormat).-
1581-
1582 If the \a format is Qt::DefaultLocaleShortDate or-
1583 Qt::DefaultLocaleLongDate, the string format depends on the-
1584 default application locale. This is the locale set with-
1585 QLocale::setDefault(), or the system locale if no default locale-
1586 has been set. Identical to calling-
1587-
1588 \l {QLocale::toString()}{QLocale().toString(time, QLocale::ShortFormat)} or-
1589 \l {QLocale::toString()}{QLocale().toString(time, QLocale::LongFormat)}.-
1590-
1591 If the \a format is Qt::RFC2822Date, the string is formatted in-
1592 an \l{RFC 2822} compatible way. An example of this formatting is-
1593 "23:59:20".-
1594-
1595 If the time is invalid, an empty string will be returned.-
1596-
1597 \sa fromString(), QDate::toString(), QDateTime::toString(), QLocale::toString()-
1598*/-
1599-
1600QString QTime::toString(Qt::DateFormat format) const-
1601{-
1602 if (!isValid())
!isValid()Description
TRUEnever evaluated
FALSEevaluated 452 times by 8 tests
Evaluated by:
  • tst_QDate
  • tst_QDateTime
  • tst_QFile
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QTime
  • tst_QVariant
  • tst_qmakelib
0-452
1603 return QString();
never executed: return QString();
0
1604-
1605 switch (format) {-
1606 case Qt::SystemLocaleDate:
never executed: case Qt::SystemLocaleDate:
0
1607 case Qt::SystemLocaleShortDate:
executed 2 times by 1 test: case Qt::SystemLocaleShortDate:
Executed by:
  • tst_QTime
2
1608 return QLocale::system().toString(*this, QLocale::ShortFormat);
executed 2 times by 1 test: return QLocale::system().toString(*this, QLocale::ShortFormat);
Executed by:
  • tst_QTime
2
1609 case Qt::SystemLocaleLongDate:
executed 2 times by 1 test: case Qt::SystemLocaleLongDate:
Executed by:
  • tst_QTime
2
1610 return QLocale::system().toString(*this, QLocale::LongFormat);
executed 2 times by 1 test: return QLocale::system().toString(*this, QLocale::LongFormat);
Executed by:
  • tst_QTime
2
1611 case Qt::LocaleDate:
never executed: case Qt::LocaleDate:
0
1612 case Qt::DefaultLocaleShortDate:
executed 2 times by 1 test: case Qt::DefaultLocaleShortDate:
Executed by:
  • tst_QTime
2
1613 return QLocale().toString(*this, QLocale::ShortFormat);
executed 2 times by 1 test: return QLocale().toString(*this, QLocale::ShortFormat);
Executed by:
  • tst_QTime
2
1614 case Qt::DefaultLocaleLongDate:
executed 2 times by 1 test: case Qt::DefaultLocaleLongDate:
Executed by:
  • tst_QTime
2
1615 return QLocale().toString(*this, QLocale::LongFormat);
executed 2 times by 1 test: return QLocale().toString(*this, QLocale::LongFormat);
Executed by:
  • tst_QTime
2
1616 case Qt::RFC2822Date:
executed 1 time by 1 test: case Qt::RFC2822Date:
Executed by:
  • tst_QTime
1
1617 case Qt::ISODate:
executed 32 times by 5 tests: case Qt::ISODate:
Executed by:
  • tst_QDateTime
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QTime
  • tst_QVariant
32
1618 case Qt::TextDate:
executed 411 times by 5 tests: case Qt::TextDate:
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QFile
  • tst_QTime
  • tst_qmakelib
411
1619 default:
never executed: default:
0
1620 return QString::asprintf("%02d:%02d:%02d", hour(), minute(), second());
executed 444 times by 8 tests: return QString::asprintf("%02d:%02d:%02d", hour(), minute(), second());
Executed by:
  • tst_QDate
  • tst_QDateTime
  • tst_QFile
  • tst_QNetworkRequest
  • tst_QSqlTableModel
  • tst_QTime
  • tst_QVariant
  • tst_qmakelib
444
1621 }-
1622}-
1623-
1624/*!-
1625 Returns the time as a string. The \a format parameter determines-
1626 the format of the result string.-
1627-
1628 These expressions may be used:-
1629-
1630 \table-
1631 \header \li Expression \li Output-
1632 \row \li h-
1633 \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)-
1634 \row \li hh-
1635 \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)-
1636 \row \li H-
1637 \li the hour without a leading zero (0 to 23, even with AM/PM display)-
1638 \row \li HH-
1639 \li the hour with a leading zero (00 to 23, even with AM/PM display)-
1640 \row \li m \li the minute without a leading zero (0 to 59)-
1641 \row \li mm \li the minute with a leading zero (00 to 59)-
1642 \row \li s \li the second without a leading zero (0 to 59)-
1643 \row \li ss \li the second with a leading zero (00 to 59)-
1644 \row \li z \li the milliseconds without leading zeroes (0 to 999)-
1645 \row \li zzz \li the milliseconds with leading zeroes (000 to 999)-
1646 \row \li AP or A-
1647 \li use AM/PM display. \e A/AP will be replaced by either-
1648 QLocale::amText() or QLocale::pmText().-
1649 \row \li ap or a-
1650 \li use am/pm display. \e a/ap will be replaced by a lower-case version of-
1651 QLocale::amText() or QLocale::pmText().-
1652 \row \li t \li the timezone (for example "CEST")-
1653 \endtable-
1654-
1655 All other input characters will be ignored. Any sequence of characters that-
1656 are enclosed in single quotes will be treated as text and not be used as an-
1657 expression. Two consecutive single quotes ("''") are replaced by a singlequote-
1658 in the output. Formats without separators (e.g. "HHmm") are currently not supported.-
1659-
1660 Example format strings (assuming that the QTime is 14:13:09.042 and the system-
1661 locale is \c{en_US})-
1662-
1663 \table-
1664 \header \li Format \li Result-
1665 \row \li hh:mm:ss.zzz \li 14:13:09.042-
1666 \row \li h:m:s ap \li 2:13:9 pm-
1667 \row \li H:m:s a \li 14:13:9 pm-
1668 \endtable-
1669-
1670 If the time is invalid, an empty string will be returned.-
1671 If \a format is empty, the default format "hh:mm:ss" is used.-
1672-
1673 \sa fromString(), QDate::toString(), QDateTime::toString(), QLocale::toString()-
1674*/-
1675QString QTime::toString(const QString& format) const-
1676{-
1677 return QLocale::system().toString(*this, format);
executed 14782 times by 7 tests: return QLocale::system().toString(*this, format);
Executed by:
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QMetaType
  • tst_QTime
  • tst_QVariant
14782
1678}-
1679#endif //QT_NO_DATESTRING-
1680/*!-
1681 Sets the time to hour \a h, minute \a m, seconds \a s and-
1682 milliseconds \a ms.-
1683-
1684 \a h must be in the range 0 to 23, \a m and \a s must be in the-
1685 range 0 to 59, and \a ms must be in the range 0 to 999.-
1686 Returns \c true if the set time is valid; otherwise returns \c false.-
1687-
1688 \sa isValid()-
1689*/-
1690-
1691bool QTime::setHMS(int h, int m, int s, int ms)-
1692{-
1693#if defined(Q_OS_WINCE)-
1694 startTick = NullTime;-
1695#endif-
1696 if (!isValid(h,m,s,ms)) {
!isValid(h,m,s,ms)Description
TRUEevaluated 238 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QNetworkCookie
  • tst_QTime
FALSEevaluated 20948610 times by 107 tests
Evaluated by:
  • tst_Collections
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • ...
238-20948610
1697 mds = NullTime; // make this invalid-
1698 return false;
executed 238 times by 5 tests: return false;
Executed by:
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QNetworkCookie
  • tst_QTime
238
1699 }-
1700 mds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms;-
1701 return true;
executed 20947141 times by 107 tests: return true;
Executed by:
  • tst_Collections
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • ...
20947141
1702}-
1703-
1704/*!-
1705 Returns a QTime object containing a time \a s seconds later-
1706 than the time of this object (or earlier if \a s is negative).-
1707-
1708 Note that the time will wrap if it passes midnight.-
1709-
1710 Returns a null time if this time is invalid.-
1711-
1712 Example:-
1713-
1714 \snippet code/src_corelib_tools_qdatetime.cpp 5-
1715-
1716 \sa addMSecs(), secsTo(), QDateTime::addSecs()-
1717*/-
1718-
1719QTime QTime::addSecs(int s) const-
1720{-
1721 s %= SECS_PER_DAY;-
1722 return addMSecs(s * 1000);
executed 8 times by 3 tests: return addMSecs(s * 1000);
Executed by:
  • tst_QDateTime
  • tst_QItemDelegate
  • tst_QTime
8
1723}-
1724-
1725/*!-
1726 Returns the number of seconds from this time to \a t.-
1727 If \a t is earlier than this time, the number of seconds returned-
1728 is negative.-
1729-
1730 Because QTime measures time within a day and there are 86400-
1731 seconds in a day, the result is always between -86400 and 86400.-
1732-
1733 secsTo() does not take into account any milliseconds.-
1734-
1735 Returns 0 if either time is invalid.-
1736-
1737 \sa addSecs(), QDateTime::secsTo()-
1738*/-
1739-
1740int QTime::secsTo(const QTime &t) const-
1741{-
1742 if (!isValid() || !t.isValid())
!isValid()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QTime
!t.isValid()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QTime
1-9
1743 return 0;
executed 3 times by 1 test: return 0;
Executed by:
  • tst_QTime
3
1744-
1745 // Truncate milliseconds as we do not want to consider them.-
1746 int ourSeconds = ds() / 1000;-
1747 int theirSeconds = t.ds() / 1000;-
1748 return theirSeconds - ourSeconds;
executed 8 times by 1 test: return theirSeconds - ourSeconds;
Executed by:
  • tst_QTime
8
1749}-
1750-
1751/*!-
1752 Returns a QTime object containing a time \a ms milliseconds later-
1753 than the time of this object (or earlier if \a ms is negative).-
1754-
1755 Note that the time will wrap if it passes midnight. See addSecs()-
1756 for an example.-
1757-
1758 Returns a null time if this time is invalid.-
1759-
1760 \sa addSecs(), msecsTo(), QDateTime::addMSecs()-
1761*/-
1762-
1763QTime QTime::addMSecs(int ms) const-
1764{-
1765 QTime t;-
1766 if (isValid()) {
isValid()Description
TRUEevaluated 214 times by 4 tests
Evaluated by:
  • tst_QDateTime
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QTime
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTime
1-214
1767 if (ms < 0) {
ms < 0Description
TRUEevaluated 40 times by 3 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkCookie
  • tst_QTime
FALSEevaluated 174 times by 4 tests
Evaluated by:
  • tst_QDateTime
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QTime
40-174
1768 // %,/ not well-defined for -ve, so always work with +ve.-
1769 int negdays = (MSECS_PER_DAY - ms) / MSECS_PER_DAY;-
1770 t.mds = (ds() + ms + negdays * MSECS_PER_DAY) % MSECS_PER_DAY;-
1771 } else {
executed 40 times by 3 tests: end of block
Executed by:
  • tst_QDateTime
  • tst_QNetworkCookie
  • tst_QTime
40
1772 t.mds = (ds() + ms) % MSECS_PER_DAY;-
1773 }
executed 174 times by 4 tests: end of block
Executed by:
  • tst_QDateTime
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QTime
174
1774 }-
1775#if defined(Q_OS_WINCE)-
1776 if (startTick > NullTime)-
1777 t.startTick = (startTick + ms) % MSECS_PER_DAY;-
1778#endif-
1779 return t;
executed 215 times by 4 tests: return t;
Executed by:
  • tst_QDateTime
  • tst_QItemDelegate
  • tst_QNetworkCookie
  • tst_QTime
215
1780}-
1781-
1782/*!-
1783 Returns the number of milliseconds from this time to \a t.-
1784 If \a t is earlier than this time, the number of milliseconds returned-
1785 is negative.-
1786-
1787 Because QTime measures time within a day and there are 86400-
1788 seconds in a day, the result is always between -86400000 and-
1789 86400000 ms.-
1790-
1791 Returns 0 if either time is invalid.-
1792-
1793 \sa secsTo(), addMSecs(), QDateTime::msecsTo()-
1794*/-
1795-
1796int QTime::msecsTo(const QTime &t) const-
1797{-
1798 if (!isValid() || !t.isValid())
!isValid()Description
TRUEevaluated 5 times by 3 tests
Evaluated by:
  • tst_QTextStream
  • tst_QThreadPool
  • tst_QTime
FALSEevaluated 6942460 times by 33 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractSlider
  • tst_QAtomicInt
  • tst_QCoreApplication
  • tst_QDateTimeEdit
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QFtp
  • tst_QFutureWatcher
  • tst_QGuiApplication
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QLabel
  • tst_QLocalSocket
  • tst_QMovie
  • tst_QMutex
  • tst_QNetworkReply
  • tst_QObjectPerformance
  • tst_QProcess
  • tst_QReadWriteLock
  • tst_QSharedMemory
  • tst_QSqlTableModel
  • tst_QTcpSocket
  • tst_QTextStream
  • ...
!t.isValid()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 6943571 times by 33 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractSlider
  • tst_QAtomicInt
  • tst_QCoreApplication
  • tst_QDateTimeEdit
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QFtp
  • tst_QFutureWatcher
  • tst_QGuiApplication
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QLabel
  • tst_QLocalSocket
  • tst_QMovie
  • tst_QMutex
  • tst_QNetworkReply
  • tst_QObjectPerformance
  • tst_QProcess
  • tst_QReadWriteLock
  • tst_QSharedMemory
  • tst_QSqlTableModel
  • tst_QTcpSocket
  • tst_QTextStream
  • ...
1-6943571
1799 return 0;
executed 6 times by 3 tests: return 0;
Executed by:
  • tst_QTextStream
  • tst_QThreadPool
  • tst_QTime
6
1800#if defined(Q_OS_WINCE)-
1801 // GetLocalTime() for Windows CE has no milliseconds resolution-
1802 if (t.startTick > NullTime && startTick > NullTime)-
1803 return t.startTick - startTick;-
1804 else-
1805#endif-
1806 return t.ds() - ds();
executed 6943182 times by 33 tests: return t.ds() - ds();
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractSlider
  • tst_QAtomicInt
  • tst_QCoreApplication
  • tst_QDateTimeEdit
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QFtp
  • tst_QFutureWatcher
  • tst_QGuiApplication
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QLabel
  • tst_QLocalSocket
  • tst_QMovie
  • tst_QMutex
  • tst_QNetworkReply
  • tst_QObjectPerformance
  • tst_QProcess
  • tst_QReadWriteLock
  • tst_QSharedMemory
  • tst_QSqlTableModel
  • tst_QTcpSocket
  • tst_QTextStream
  • ...
6943182
1807}-
1808-
1809-
1810/*!-
1811 \fn bool QTime::operator==(const QTime &t) const-
1812-
1813 Returns \c true if this time is equal to \a t; otherwise returns \c false.-
1814*/-
1815-
1816/*!-
1817 \fn bool QTime::operator!=(const QTime &t) const-
1818-
1819 Returns \c true if this time is different from \a t; otherwise returns \c false.-
1820*/-
1821-
1822/*!-
1823 \fn bool QTime::operator<(const QTime &t) const-
1824-
1825 Returns \c true if this time is earlier than \a t; otherwise returns \c false.-
1826*/-
1827-
1828/*!-
1829 \fn bool QTime::operator<=(const QTime &t) const-
1830-
1831 Returns \c true if this time is earlier than or equal to \a t;-
1832 otherwise returns \c false.-
1833*/-
1834-
1835/*!-
1836 \fn bool QTime::operator>(const QTime &t) const-
1837-
1838 Returns \c true if this time is later than \a t; otherwise returns \c false.-
1839*/-
1840-
1841/*!-
1842 \fn bool QTime::operator>=(const QTime &t) const-
1843-
1844 Returns \c true if this time is later than or equal to \a t;-
1845 otherwise returns \c false.-
1846*/-
1847-
1848/*!-
1849 \fn QTime QTime::fromMSecsSinceStartOfDay(int msecs)-
1850-
1851 Returns a new QTime instance with the time set to the number of \a msecs-
1852 since the start of the day, i.e. since 00:00:00.-
1853-
1854 If \a msecs falls outside the valid range an invalid QTime will be returned.-
1855-
1856 \sa msecsSinceStartOfDay()-
1857*/-
1858-
1859/*!-
1860 \fn int QTime::msecsSinceStartOfDay() const-
1861-
1862 Returns the number of msecs since the start of the day, i.e. since 00:00:00.-
1863-
1864 \sa fromMSecsSinceStartOfDay()-
1865*/-
1866-
1867/*!-
1868 \fn QTime::currentTime()-
1869-
1870 Returns the current time as reported by the system clock.-
1871-
1872 Note that the accuracy depends on the accuracy of the underlying-
1873 operating system; not all systems provide 1-millisecond accuracy.-
1874*/-
1875-
1876#ifndef QT_NO_DATESTRING-
1877-
1878static QTime fromIsoTimeString(const QStringRef &string, Qt::DateFormat format, bool *isMidnight24)-
1879{-
1880 if (isMidnight24)
isMidnight24Description
TRUEevaluated 54 times by 4 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
FALSEevaluated 30 times by 2 tests
Evaluated by:
  • tst_QTime
  • tst_QVariant
30-54
1881 *isMidnight24 = false;
executed 54 times by 4 tests: *isMidnight24 = false;
Executed by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QVariant
54
1882-
1883 const int size = string.size();-
1884 if (size < 5)
size < 5Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 83 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
1-83
1885 return QTime();
executed 1 time by 1 test: return QTime();
Executed by:
  • tst_QTime
1
1886-
1887 bool ok = false;-
1888 int hour = string.mid(0, 2).toInt(&ok);-
1889 if (!ok)
!okDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QVariant
FALSEevaluated 82 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
1-82
1890 return QTime();
executed 1 time by 1 test: return QTime();
Executed by:
  • tst_QVariant
1
1891 const int minute = string.mid(3, 2).toInt(&ok);-
1892 if (!ok)
!okDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 80 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
2-80
1893 return QTime();
executed 2 times by 1 test: return QTime();
Executed by:
  • tst_QTime
2
1894 int second = 0;-
1895 int msec = 0;-
1896-
1897 if (size == 5) {
size == 5Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 74 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
6-74
1898 // HH:mm format-
1899 second = 0;-
1900 msec = 0;-
1901 } else if (string.at(5) == QLatin1Char(',') || string.at(5) == QLatin1Char('.')) {
executed 6 times by 1 test: end of block
Executed by:
  • tst_QTime
string.at(5) =...atin1Char(',')Description
TRUEevaluated 5 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 69 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
string.at(5) =...atin1Char('.')Description
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 65 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
4-69
1902 if (format == Qt::TextDate)
format == Qt::TextDateDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 8 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
1-8
1903 return QTime();
executed 1 time by 1 test: return QTime();
Executed by:
  • tst_QTime
1
1904 // ISODate HH:mm.ssssss format-
1905 // We only want 5 digits worth of fraction of minute. This follows the existing-
1906 // behavior that determines how milliseconds are read; 4 millisecond digits are-
1907 // read and then rounded to 3. If we read at most 5 digits for fraction of minute,-
1908 // the maximum amount of millisecond digits it will expand to once converted to-
1909 // seconds is 4. E.g. 12:34,99999 will expand to 12:34:59.9994. The milliseconds-
1910 // will then be rounded up AND clamped to 999.-
1911-
1912 const QStringRef minuteFractionStr = string.mid(6, 5);-
1913 const long minuteFractionInt = minuteFractionStr.toLong(&ok);-
1914 if (!ok)
!okDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
1-7
1915 return QTime();
executed 1 time by 1 test: return QTime();
Executed by:
  • tst_QTime
1
1916 const float minuteFraction = double(minuteFractionInt) / (std::pow(double(10), minuteFractionStr.count()));-
1917-
1918 const float secondWithMs = minuteFraction * 60;-
1919 const float secondNoMs = std::floor(secondWithMs);-
1920 const float secondFraction = secondWithMs - secondNoMs;-
1921 second = secondNoMs;-
1922 msec = qMin(qRound(secondFraction * 1000.0), 999);-
1923 } else {
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QDateTime
  • tst_QTime
7
1924 // HH:mm:ss or HH:mm:ss.zzz-
1925 second = string.mid(6, 2).toInt(&ok);-
1926 if (!ok)
!okDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 63 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
2-63
1927 return QTime();
executed 2 times by 1 test: return QTime();
Executed by:
  • tst_QTime
2
1928 if (size > 8 && (string.at(8) == QLatin1Char(',') || string.at(8) == QLatin1Char('.'))) {
size > 8Description
TRUEevaluated 29 times by 3 tests
Evaluated by:
  • tst_QDateTime
  • tst_QSqlQuery
  • tst_QTime
FALSEevaluated 34 times by 4 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QTime
  • tst_QVariant
string.at(8) =...atin1Char(',')Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 18 times by 3 tests
Evaluated by:
  • tst_QDateTime
  • tst_QSqlQuery
  • tst_QTime
string.at(8) =...atin1Char('.')Description
TRUEevaluated 15 times by 3 tests
Evaluated by:
  • tst_QDateTime
  • tst_QSqlQuery
  • tst_QTime
FALSEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
3-34
1929 const QStringRef msecStr(string.mid(9, 4));-
1930 int msecInt = msecStr.isEmpty() ? 0 : msecStr.toInt(&ok);
msecStr.isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 25 times by 3 tests
Evaluated by:
  • tst_QDateTime
  • tst_QSqlQuery
  • tst_QTime
1-25
1931 if (!ok)
!okDescription
TRUEnever evaluated
FALSEevaluated 26 times by 3 tests
Evaluated by:
  • tst_QDateTime
  • tst_QSqlQuery
  • tst_QTime
0-26
1932 return QTime();
never executed: return QTime();
0
1933 const double secondFraction(msecInt / (std::pow(double(10), msecStr.count())));-
1934 msec = qMin(qRound(secondFraction * 1000.0), 999);-
1935 }
executed 26 times by 3 tests: end of block
Executed by:
  • tst_QDateTime
  • tst_QSqlQuery
  • tst_QTime
26
1936 }
executed 63 times by 5 tests: end of block
Executed by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
63
1937-
1938 if (format == Qt::ISODate && hour == 24 && minute == 0 && second == 0 && msec == 0) {
format == Qt::ISODateDescription
TRUEevaluated 69 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QTime
hour == 24Description
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
FALSEevaluated 62 times by 5 tests
Evaluated by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
minute == 0Description
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
FALSEnever evaluated
second == 0Description
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
FALSEnever evaluated
msec == 0Description
TRUEevaluated 7 times by 2 tests
Evaluated by:
  • tst_QDateTime
  • tst_QTime
FALSEnever evaluated
0-69
1939 if (isMidnight24)
isMidnight24Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QDateTime
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTime
2-5
1940 *isMidnight24 = true;
executed 5 times by 1 test: *isMidnight24 = true;
Executed by:
  • tst_QDateTime
5
1941 hour = 0;-
1942 }
executed 7 times by 2 tests: end of block
Executed by:
  • tst_QDateTime
  • tst_QTime
7
1943-
1944 return QTime(hour, minute, second, msec);
executed 76 times by 5 tests: return QTime(hour, minute, second, msec);
Executed by:
  • tst_QDateTime
  • tst_QNetworkReply
  • tst_QSqlQuery
  • tst_QTime
  • tst_QVariant
76
1945}-
1946-
1947/*!-
1948 \fn QTime QTime::fromString(const QString &string, Qt::DateFormat format)-
1949-
1950 Returns the time represented in the \a string as a QTime using the-
1951 \a format given, or an invalid time if this is not possible.-
1952-
1953 Note that fromString() uses a "C" locale encoded string to convert-
1954 milliseconds to a float value. If the default locale is not "C",-
1955 this may result in two conversion attempts (if the conversion-
1956 fails for the default locale). This should be considered an-
1957 implementation detail.-
1958-
1959 \sa toString(), QLocale::toTime()-
1960*/-
1961QTime QTime::fromString(const QString& string, Qt::DateFormat format)-
1962{-
1963 if (string.isEmpty())
string.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QTime
FALSEevaluated 50 times by 2 tests
Evaluated by:
  • tst_QTime
  • tst_QVariant
2-50
1964 return QTime();
executed 2 times by 1 test: return QTime();
Executed by:
  • tst_QTime
2
1965-
1966 switch (format) {-
1967 case Qt::SystemLocaleDate:
never executed: case Qt::SystemLocaleDate:
0
1968 case Qt::SystemLocaleShortDate:
never executed: case Qt::SystemLocaleShortDate:
0
1969 return QLocale::system().toTime(string, QLocale::ShortFormat);
never executed: return QLocale::system().toTime(string, QLocale::ShortFormat);
0
1970 case Qt::SystemLocaleLongDate:
never executed: case Qt::SystemLocaleLongDate:
0
1971 return QLocale::system().toTime(string, QLocale::LongFormat);
never executed: return QLocale::system().toTime(string, QLocale::LongFormat);
0
1972 case Qt::LocaleDate:
never executed: case Qt::LocaleDate:
0
1973 case Qt::DefaultLocaleShortDate:
never executed: case Qt::DefaultLocaleShortDate:
0
1974 return QLocale().toTime(string, QLocale::ShortFormat);
never executed: return QLocale().toTime(string, QLocale::ShortFormat);
0
1975 case Qt::DefaultLocaleLongDate:
never executed: case Qt::DefaultLocaleLongDate:
0
1976 return QLocale().toTime(string, QLocale::LongFormat);
never executed: return QLocale().toTime(string, QLocale::LongFormat);
0
1977 case Qt::RFC2822Date:
executed 20 times by 1 test: case Qt::RFC2822Date:
Executed by:
  • tst_QTime
20
1978 return rfcDateImpl(string).time;
executed 20 times by 1 test: return rfcDateImpl(string).time;
Executed by:
  • tst_QTime
20
1979 case Qt::ISODate:
executed 20 times by 2 tests: case Qt::ISODate:
Executed by:
  • tst_QTime
  • tst_QVariant
20
1980 case Qt::TextDate:
executed 10 times by 1 test: case Qt::TextDate:
Executed by:
  • tst_QTime
10
1981 default:
never executed: default:
0
1982 return fromIsoTimeString(&string, format, 0);
executed 30 times by 2 tests: return fromIsoTimeString(&string, format, 0);
Executed by:
  • tst_QTime
  • tst_QVariant
30
1983 }-
1984}-
1985-
1986/*!-
1987 \fn QTime::fromString(const QString &string, const QString &format)-
1988-
1989 Returns the QTime represented by the \a string, using the \a-
1990 format given, or an invalid time if the string cannot be parsed.-
1991-
1992 These expressions may be used for the format:-
1993-
1994 \table-
1995 \header \li Expression \li Output-
1996 \row \li h-
1997 \li the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)-
1998 \row \li hh-
1999 \li the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)-
2000 \row \li m \li the minute without a leading zero (0 to 59)-
2001 \row \li mm \li the minute with a leading zero (00 to 59)-
2002 \row \li s \li the second without a leading zero (0 to 59)-
2003 \row \li ss \li the second with a leading zero (00 to 59)-
2004 \row \li z \li the milliseconds without leading zeroes (0 to 999)-
2005 \row \li zzz \li the milliseconds with leading zeroes (000 to 999)-
2006 \row \li AP-
2007 \li interpret as an AM/PM time. \e AP must be either "AM" or "PM".-
2008 \row \li ap-
2009 \li Interpret as an AM/PM time. \e ap must be either "am" or "pm".-
2010 \endtable-
2011-
2012 All other input characters will be treated as text. Any sequence-
2013 of characters that are enclosed in single quotes will also be-
2014 treated as text and not be used as an expression.-
2015-
2016 \snippet code/src_corelib_tools_qdatetime.cpp 6-
2017-
2018 If the format is not satisfied, an invalid QTime is returned.-
2019 Expressions that do not expect leading zeroes to be given (h, m, s-
2020 and z) are greedy. This means that they will use two digits even if-
2021 this puts them outside the range of accepted values and leaves too-
2022 few digits for other sections. For example, the following string-
2023 could have meant 00:07:10, but the m will grab two digits, resulting-
2024 in an invalid time:-
2025-
2026 \snippet code/src_corelib_tools_qdatetime.cpp 7-
2027-
2028 Any field that is not represented in the format will be set to zero.-
2029 For example:-
2030-
2031 \snippet code/src_corelib_tools_qdatetime.cpp 8-
2032-
2033 \sa toString(), QDateTime::fromString(), QDate::fromString(),-
2034 QLocale::toTime()-
2035*/-
2036-
2037QTime QTime::fromString(const QString &string, const QString &format)-
2038{-
2039 QTime time;-
2040#ifndef QT_BOOTSTRAPPED-
2041 QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString);-
2042 if (dt.parseFormat(format))
dt.parseFormat(format)Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_QTime
FALSEnever evaluated
0-12
2043 dt.fromString(string, 0, &time);
executed 12 times by 1 test: dt.fromString(string, 0, &time);
Executed by:
  • tst_QTime
12
2044#else-
2045 Q_UNUSED(string);-
2046 Q_UNUSED(format);-
2047#endif-
2048 return time;
executed 12 times by 1 test: return time;
Executed by:
  • tst_QTime
12
2049}-
2050-
2051#endif // QT_NO_DATESTRING-
2052-
2053-
2054/*!-
2055 \overload-
2056-
2057 Returns \c true if the specified time is valid; otherwise returns-
2058 false.-
2059-
2060 The time is valid if \a h is in the range 0 to 23, \a m and-
2061 \a s are in the range 0 to 59, and \a ms is in the range 0 to 999.-
2062-
2063 Example:-
2064-
2065 \snippet code/src_corelib_tools_qdatetime.cpp 9-
2066*/-
2067-
2068bool QTime::isValid(int h, int m, int s, int ms)-
2069{-
2070 return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000;
executed 20961703 times by 107 tests: return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000;
Executed by:
  • tst_Collections
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAsn1Element
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • ...
20961703
2071}-
2072-
2073-
2074/*!-
2075 Sets this time to the current time. This is practical for timing:-
2076-
2077 \snippet code/src_corelib_tools_qdatetime.cpp 10-
2078-
2079 \sa restart(), elapsed(), currentTime()-
2080*/-
2081-
2082void QTime::start()-
2083{-
2084 *this = currentTime();-
2085}
executed 677 times by 28 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractSlider
  • tst_QAtomicInt
  • tst_QCoreApplication
  • tst_QFtp
  • tst_QFutureWatcher
  • tst_QGuiApplication
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QLabel
  • tst_QLocalSocket
  • tst_QMovie
  • tst_QMutex
  • tst_QNetworkReply
  • tst_QObjectPerformance
  • tst_QProcess
  • tst_QReadWriteLock
  • tst_QSharedMemory
  • tst_QSocks5SocketEngine
  • tst_QSqlTableModel
  • tst_QTcpSocket
  • tst_QThread
  • tst_QThreadPool
  • tst_QTimer
  • ...
677
2086-
2087/*!-
2088 Sets this time to the current time and returns the number of-
2089 milliseconds that have elapsed since the last time start() or-
2090 restart() was called.-
2091-
2092 This function is guaranteed to be atomic and is thus very handy-
2093 for repeated measurements. Call start() to start the first-
2094 measurement, and restart() for each later measurement.-
2095-
2096 Note that the counter wraps to zero 24 hours after the last call-
2097 to start() or restart().-
2098-
2099 \warning If the system's clock setting has been changed since the-
2100 last time start() or restart() was called, the result is-
2101 undefined. This can happen when daylight-saving time is turned on-
2102 or off.-
2103-
2104 \sa start(), elapsed(), currentTime()-
2105*/-
2106-
2107int QTime::restart()-
2108{-
2109 QTime t = currentTime();-
2110 int n = msecsTo(t);-
2111 if (n < 0) // passed midnight
n < 0Description
TRUEnever evaluated
FALSEevaluated 211 times by 3 tests
Evaluated by:
  • tst_QFtp
  • tst_QTextStream
  • tst_QThreadPool
0-211
2112 n += 86400*1000;
never executed: n += 86400*1000;
0
2113 *this = t;-
2114 return n;
executed 211 times by 3 tests: return n;
Executed by:
  • tst_QFtp
  • tst_QTextStream
  • tst_QThreadPool
211
2115}-
2116-
2117/*!-
2118 Returns the number of milliseconds that have elapsed since the-
2119 last time start() or restart() was called.-
2120-
2121 Note that the counter wraps to zero 24 hours after the last call-
2122 to start() or restart.-
2123-
2124 Note that the accuracy depends on the accuracy of the underlying-
2125 operating system; not all systems provide 1-millisecond accuracy.-
2126-
2127 \warning If the system's clock setting has been changed since the-
2128 last time start() or restart() was called, the result is-
2129 undefined. This can happen when daylight-saving time is turned on-
2130 or off.-
2131-
2132 \sa start(), restart()-
2133*/-
2134-
2135int QTime::elapsed() const-
2136{-
2137 int n = msecsTo(currentTime());-
2138 if (n < 0) // passed midnight
n < 0Description
TRUEnever evaluated
FALSEevaluated 6943291 times by 28 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractSlider
  • tst_QAtomicInt
  • tst_QCoreApplication
  • tst_QFtp
  • tst_QFutureWatcher
  • tst_QGuiApplication
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QLabel
  • tst_QLocalSocket
  • tst_QMovie
  • tst_QMutex
  • tst_QNetworkReply
  • tst_QObjectPerformance
  • tst_QProcess
  • tst_QReadWriteLock
  • tst_QSharedMemory
  • tst_QSqlTableModel
  • tst_QTcpSocket
  • tst_QTextStream
  • tst_QThread
  • tst_QThreadPool
  • tst_QTimer
  • ...
0-6943291
2139 n += 86400 * 1000;
never executed: n += 86400 * 1000;
0
2140 return n;
executed 6943291 times by 28 tests: return n;
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractSlider
  • tst_QAtomicInt
  • tst_QCoreApplication
  • tst_QFtp
  • tst_QFutureWatcher
  • tst_QGuiApplication
  • tst_QHttpNetworkConnection
  • tst_QHttpSocketEngine
  • tst_QLabel
  • tst_QLocalSocket
  • tst_QMovie
  • tst_QMutex
  • tst_QNetworkReply
  • tst_QObjectPerformance
  • tst_QProcess
  • tst_QReadWriteLock
  • tst_QSharedMemory
  • tst_QSqlTableModel
  • tst_QTcpSocket
  • tst_QTextStream
  • tst_QThread
  • tst_QThreadPool
  • tst_QTimer
  • ...
6943291
2141}-
2142-
2143/*****************************************************************************-
2144 QDateTime static helper functions-
2145 *****************************************************************************/-
2146-
2147// Calls the platform variant of tzset-
2148static void qt_tzset()-
2149{-
2150#if defined(Q_OS_WINCE)-
2151 // WinCE doesn't use tzset-
2152 return;-
2153#elif defined(Q_OS_WIN)-
2154 _tzset();-
2155#else-
2156 tzset();-
2157#endif // Q_OS_WIN-
2158}
executed 6954999 times by 98 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractSlider
  • tst_QAccessibility
  • tst_QAtomicInt
  • tst_QAuthenticator
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusAbstractAdaptor
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDir
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • ...
6954999
2159-
2160// Returns the platform variant of timezone, i.e. the standard time offset-
2161// The timezone external variable is documented as always holding the-
2162// Standard Time offset as seconds west of Greenwich, i.e. UTC+01:00 is -3600-
2163// Note this may not be historicaly accurate.-
2164// Relies on tzset, mktime, or localtime having been called to populate timezone-
2165static int qt_timezone()-
2166{-
2167#if defined(Q_OS_WINCE)-
2168 TIME_ZONE_INFORMATION tzi;-
2169 GetTimeZoneInformation(&tzi);-
2170 // Expressed in minutes, convert to seconds-
2171 return (tzi.Bias + tzi.StandardBias) * 60;-
2172#elif defined(_MSC_VER) && _MSC_VER >= 1400-
2173 long offset;-
2174 _get_timezone(&offset);-
2175 return offset;-
2176#elif defined(Q_OS_BSD4) && !defined(Q_OS_DARWIN)-
2177 time_t clock = time(NULL);-
2178 struct tm t;-
2179 localtime_r(&clock, &t);-
2180 // QTBUG-36080 Workaround for systems without the POSIX timezone-
2181 // variable. This solution is not very efficient but fixing it is up to-
2182 // the libc implementations.-
2183 //-
2184 // tm_gmtoff has some important differences compared to the timezone-
2185 // variable:-
2186 // - It returns the number of seconds east of UTC, and we want the-
2187 // number of seconds west of UTC.-
2188 // - It also takes DST into account, so we need to adjust it to always-
2189 // get the Standard Time offset.-
2190 return -t.tm_gmtoff + (t.tm_isdst ? (long)SECS_PER_HOUR : 0L);-
2191#elif defined(Q_OS_INTEGRITY)-
2192 return 0;-
2193#else-
2194 return timezone;
executed 7004 times by 16 tests: return timezone;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QDataStream
  • tst_QDate
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFtp
  • tst_QItemDelegate
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookieJar
  • tst_QNetworkReply
  • tst_QNetworkRequest
  • tst_QNoDebug
  • tst_QStyleSheetStyle
  • tst_QTime
7004
2195#endif // Q_OS_WIN-
2196}-
2197-
2198// Returns the tzname, assume tzset has been called already-
2199static QString qt_tzname(QDateTimePrivate::DaylightStatus daylightStatus)-
2200{-
2201#if defined(Q_OS_WINCE)-
2202 TIME_ZONE_INFORMATION tzi;-
2203 DWORD res = GetTimeZoneInformation(&tzi);-
2204 if (res == TIME_ZONE_ID_UNKNOWN)-
2205 return QString();-
2206 else if (daylightStatus == QDateTimePrivate::DaylightTime)-
2207 return QString::fromWCharArray(tzi.DaylightName);-
2208 else-
2209 return QString::fromWCharArray(tzi.StandardName);-
2210#else-
2211 int isDst = (daylightStatus == QDateTimePrivate::DaylightTime) ? 1 : 0;
(daylightStatu...:DaylightTime)Description
TRUEevaluated 250 times by 11 tests
Evaluated by:
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileInfo
  • tst_QItemDelegate
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkReply
  • tst_QSignalSpy
  • tst_QTime
  • tst_QVariant
FALSEevaluated 1021 times by 5 tests
Evaluated by:
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QItemDelegate
  • tst_QNoDebug
250-1021
2212#if defined(_MSC_VER) && _MSC_VER >= 1400-
2213 size_t s = 0;-
2214 char name[512];-
2215 if (_get_tzname(&s, name, 512, isDst))-
2216 return QString();-
2217 return QString::fromLocal8Bit(name);-
2218#else-
2219 return QString::fromLocal8Bit(tzname[isDst]);
executed 1271 times by 13 tests: return QString::fromLocal8Bit(tzname[isDst]);
Executed by:
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QFileInfo
  • tst_QItemDelegate
  • tst_QMetaType
  • tst_QNetworkCacheMetaData
  • tst_QNetworkCookie
  • tst_QNetworkReply
  • tst_QNoDebug
  • tst_QSignalSpy
  • tst_QTime
  • tst_QVariant
1271
2220#endif // Q_OS_WIN-
2221#endif // Q_OS_WINCE-
2222}-
2223-
2224// Calls the platform variant of mktime for the given date, time and daylightStatus,-
2225// and updates the date, time, daylightStatus and abbreviation with the returned values-
2226// If the date falls outside the 1970 to 2037 range supported by mktime / time_t-
2227// then null date/time will be returned, you should adjust the date first if-
2228// you need a guaranteed result.-
2229static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStatus *daylightStatus,-
2230 QString *abbreviation, bool *ok = 0)-
2231{-
2232 const qint64 msec = time->msec();-
2233 int yy, mm, dd;-
2234 date->getDate(&yy, &mm, &dd);-
2235-
2236#if defined(Q_OS_WINCE)-
2237 // WinCE doesn't provide standard C library time functions-
2238 SYSTEMTIME st;-
2239 memset(&st, 0, sizeof(SYSTEMTIME));-
2240 st.wSecond = time->second();-
2241 st.wMinute = time->minute();-
2242 st.wHour = time->hour();-
2243 st.wDay = dd;-
2244 st.wMonth = mm;-
2245 st.wYear = yy;-
2246 FILETIME lft;-
2247 bool valid = SystemTimeToFileTime(&st, &lft);-
2248 FILETIME ft;-
2249 if (valid)-
2250 valid = LocalFileTimeToFileTime(&lft, &ft);-
2251 const time_t secsSinceEpoch = ftToTime_t(ft);-
2252 const time_t localSecs = ftToTime_t(lft);-
2253 TIME_ZONE_INFORMATION tzi;-
2254 GetTimeZoneInformation(&tzi);-
2255 bool isDaylight = false;-
2256 // Check for overflow-
2257 qint64 localDiff = qAbs(localSecs - secsSinceEpoch);-
2258 int daylightOffset = qAbs(tzi.Bias + tzi.DaylightBias) * 60;-
2259 if (localDiff > daylightOffset)-
2260 valid = false;-
2261 else-
2262 isDaylight = (localDiff == daylightOffset);-
2263 if (daylightStatus) {-
2264 if (isDaylight)-
2265 *daylightStatus = QDateTimePrivate::DaylightTime;-
2266 else-
2267 *daylightStatus = QDateTimePrivate::StandardTime;-
2268 }-
2269 if (abbreviation) {-
2270 if (isDaylight)-