MCPcopy Create free account
hub / github.com/KDE/kdevelop / main

Function main

plugins/debuggercommon/tests/debuggees/qdatetime.cpp:5–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <QTimeZone>
4
5int main()
6{
7 QDateTime local(QDate(2010, 1, 20), QTime(15, 31, 13));
8 qDebug() << "local:" << local;
9
10 QDateTime utc = QDateTime::fromString("2024-02-01T16:28:07.123Z", Qt::ISODateWithMs);
11 qDebug() << "utc:" << utc;
12#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
13 QTimeZone localTZ(QTimeZone::LocalTime);
14 qDebug() << "localTZ:" << localTZ;
15 QTimeZone utcTZ(QTimeZone::UTC);
16 qDebug() << "utcTZ:" << utcTZ;
17
18 QTimeZone newYork = QTimeZone::fromSecondsAheadOfUtc(-5*3600);
19 qDebug() << "newYork:" << newYork;
20 QDateTime lunchInNewYork(QDate(2025, 1, 2), QTime(12, 0, 0, 1), newYork);
21 qDebug() << "lunchInNewYork:" << lunchInNewYork;
22
23 QTimeZone utc0 = QTimeZone::fromSecondsAheadOfUtc(0);
24 qDebug() << "utc0:" << utc0;
25 QDateTime lunchInUtc0(QDate(2025, 1, 2), QTime(12, 0, 0, 999), utc0);
26 qDebug() << "lunchInUtc0:" << lunchInUtc0;
27
28 QTimeZone utc20 = QTimeZone::fromSecondsAheadOfUtc(20*3600);
29 // From the documentation: "The offset from UTC must be in the range
30 // -16 hours to +16 hours otherwise an invalid time zone will be returned."
31 Q_ASSERT(!utc20.isValid());
32 qDebug() << "utc20:" << utc20;
33 QDateTime lunchInUtc20(QDate(2025, 1, 2), QTime(12, 0, 0, 505), utc20);
34 qDebug() << "lunchInUtc20:" << lunchInUtc20;
35#endif
36 QTimeZone hawaii("US/Hawaii");
37 qDebug() << "hawaii:" << hawaii;
38 QDateTime lunchInHawaii(QDate(2025, 1, 2), QTime(12, 0, 0), hawaii);
39 qDebug() << "lunchInHawaii:" << lunchInHawaii;
40
41 QTimeZone defaultConstructedTZ;
42 Q_ASSERT(!defaultConstructedTZ.isValid());
43 qDebug() << "defaultConstructedTZ:" << defaultConstructedTZ;
44 QDateTime dateTimeDefaultConstructedTZ(QDate(1010, 11, 23), QTime(5, 6, 7, 89), defaultConstructedTZ);
45 qDebug() << dateTimeDefaultConstructedTZ;
46
47 QTimeZone emptyStringTZ;
48 Q_ASSERT(!emptyStringTZ.isValid());
49 qDebug() << "emptyStringTZ:" << emptyStringTZ;
50 QDateTime dateTimeEmptyStringTZ(QDate(1510, 11, 23), QTime(5, 6, 7, 89), emptyStringTZ);
51 qDebug() << dateTimeEmptyStringTZ;
52
53 QTimeZone invalidTZ("invalid");
54 Q_ASSERT(!invalidTZ.isValid());
55 qDebug() << "invalidTZ:" << invalidTZ;
56 QDateTime dateTimeInvalidTZ(QDate(2025, 1, 2), QTime(12, 0, 0, 1), invalidTZ);
57 qDebug() << dateTimeInvalidTZ;
58
59 return 0;
60}
61// clazy:skip

Callers

nothing calls this directly

Calls 1

isValidMethod · 0.45

Tested by

no test coverage detected