13#include "private/qcalendarmath_p.h"
14#include "private/qdatetime_p.h"
15#if QT_CONFIG(datetimeparser)
16#include "private/qdatetimeparser_p.h"
19#include "private/qcore_mac_p.h"
21#include "private/qgregoriancalendar_p.h"
22#include "private/qlocale_tools_p.h"
23#include "private/qlocaltime_p.h"
24#include "private/qnumeric_p.h"
25#include "private/qstringconverter_p.h"
26#include "private/qstringiterator_p.h"
27#if QT_CONFIG(timezone)
28#include "private/qtimezoneprivate_p.h"
33# include <qt_windows.h>
36#include <private/qtools_p.h>
40using namespace Qt::StringLiterals;
41using namespace QtPrivate::DateTimeConstants;
42using namespace QtMiscUtils;
45
46
49
50
51static_assert(std::is_trivially_copyable_v<QCalendar::YearMonthDay>);
53static inline QDate
fixedDate(QCalendar::YearMonthDay parts, QCalendar cal)
55 if ((parts.year < 0 && !cal.isProleptic()) || (parts.year == 0 && !cal.hasYearZero()))
58 parts.day = qMin(parts.day, cal.daysInMonth(parts.month, parts.year));
59 return cal.dateFromParts(parts);
62static inline QDate
fixedDate(QCalendar::YearMonthDay parts)
65 parts.day = qMin(parts.day, QGregorianCalendar::monthLength(parts.month, parts.year));
66 const auto jd = QGregorianCalendar::julianFromParts(parts.year, parts.month, parts.day);
68 return QDate::fromJulianDay(*jd);
74
75
77#if QT_CONFIG(textdate)
78static const char qt_shortMonthNames[][4] = {
79 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
80 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
83static int fromShortMonthName(QStringView monthName)
85 for (
unsigned int i = 0; i <
sizeof(qt_shortMonthNames) /
sizeof(qt_shortMonthNames[0]); ++i) {
86 if (monthName == QLatin1StringView(qt_shortMonthNames[i], 3))
93#if QT_CONFIG(datestring)
95using ParsedInt = QSimpleParsedNumber<qulonglong>;
98
99
100ParsedInt readInt(QLatin1StringView text)
106 if (text.isEmpty() || !isAsciiDigit(text.front().toLatin1()))
109 QSimpleParsedNumber res = qstrntoull(text.data(), text.size(), 10);
110 return res.used == text.size() ? res : ParsedInt{};
113ParsedInt readInt(QStringView text)
123 QVarLengthArray<
char> latin1(text.size());
124 QLatin1::convertFromUnicode(latin1.data(), text);
125 return readInt(QLatin1StringView{latin1.data(), latin1.size()});
130struct ParsedRfcDateTime {
136static int shortDayFromName(QStringView name)
138 const char16_t shortDayNames[] = u"MonTueWedThuFriSatSun";
139 for (
int i = 0; i < 7; i++) {
140 if (name == QStringView(shortDayNames + 3 * i, 3))
146static ParsedRfcDateTime rfcDateImpl(QStringView s)
150 ParsedRfcDateTime result;
152 QVarLengthArray<QStringView, 6> words;
154 auto tokens = s.tokenize(u' ', Qt::SkipEmptyParts);
155 auto it = tokens.begin();
156 for (
int i = 0; i < 6 && it != tokens.end(); ++i, ++it)
157 words.emplace_back(*it);
159 if (words.size() < 3 || it != tokens.end())
161 const QChar colon(u':');
165 const auto isShortName = [](QStringView name) {
166 return (name.size() == 3 && name[0].isUpper()
167 && name[1].isLower() && name[2].isLower());
171
172
177 const QStringView maybeDayName = words.front();
178 if (maybeDayName.endsWith(u',')) {
179 dayName = maybeDayName.chopped(1);
180 words.erase(words.begin());
181 }
else if (!maybeDayName.front().isDigit()) {
182 dayName = maybeDayName;
183 words.erase(words.begin());
186 if (words.size() < 3 || words.size() > 5)
190 int dayIndex, monthIndex;
200 yearIndex = words.size() > 3 && words.at(2).contains(colon) ? 3 : 2;
204 if (!dayName.isEmpty()) {
205 if (!isShortName(dayName))
207 dayOfWeek = shortDayFromName(dayName);
212 const int day = words.at(dayIndex).toInt(&ok);
215 const int year = words.at(yearIndex).toInt(&ok);
218 const QStringView monthName = words.at(monthIndex);
219 if (!isShortName(monthName))
221 int month = fromShortMonthName(monthName);
225 date = QDate(year, month, day);
226 if (dayOfWeek && date.dayOfWeek() != dayOfWeek)
229 words.remove(yearIndex);
234 if (words.size() && words.at(0).contains(colon)) {
235 const QStringView when = words.front();
236 words.erase(words.begin());
237 if (when.size() < 5 || when[2] != colon
238 || (when.size() == 8 ? when[5] != colon : when.size() > 5)) {
241 const int hour = when.first(2).toInt(&ok);
244 const int minute = when.sliced(3, 2).toInt(&ok);
247 const auto secs = when.size() == 8 ? when.last(2).toInt(&ok) : 0;
250 time = QTime(hour, minute, secs);
256 const QStringView zone = words.front();
257 words.erase(words.begin());
258 if (words.size() || !(zone.size() == 3 || zone.size() == 5))
263 else if (zone[0] != u'+')
265 const int hour = zone.sliced(1, 2).toInt(&ok);
268 const auto minute = zone.size() == 5 ? zone.last(2).toInt(&ok) : 0;
271 offset = (hour * 60 + minute) * 60;
278 result.utcOffset = offset;
286 return QString::asprintf(
"%c%02d%s%02d",
287 offset >= 0 ?
'+' :
'-',
288 qAbs(offset) /
int(SECS_PER_HOUR),
290 format == Qt::TextDate ?
"" :
":",
291 (qAbs(offset) / 60) % 60);
294#if QT_CONFIG(datestring)
296static int fromOffsetString(QStringView offsetString,
bool *valid)
noexcept
300 const qsizetype size = offsetString.size();
301 if (size < 2 || size > 6)
308 const QChar signChar = offsetString[0];
309 if (signChar == u'+')
311 else if (signChar == u'-')
317 const QStringView time = offsetString.sliced(1);
318 qsizetype hhLen = time.indexOf(u':');
325 const QStringView hhRef = time.first(qMin(hhLen, time.size()));
327 const int hour = hhRef.toInt(&ok);
328 if (!ok || hour > 23)
331 const QStringView mmRef = time.sliced(qMin(mmIndex, time.size()));
332 const int minute = mmRef.isEmpty() ? 0 : mmRef.toInt(&ok);
333 if (!ok || minute < 0 || minute > 59)
337 return sign * ((hour * 60) + minute) * 60;
342
343
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
424
425
426
427
428
429
432
433
434
435
436
437
438
439
440
442QDate::QDate(
int y,
int m,
int d)
444 static_assert(maxJd() == JulianDayMax);
445 static_assert(minJd() == JulianDayMin);
446 jd = QGregorianCalendar::julianFromParts(y, m, d).value_or(nullJd());
449QDate::QDate(
int y,
int m,
int d, QCalendar cal)
451 *
this = cal.dateFromParts(y, m, d);
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
479
480
481
482
483
484
485
486
487
488
491
492
493
494
495
496
497
498
499
500
503
504
505
506
507
508
509
510
511
514
515
516
517
518
519
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
543int QDate::year(QCalendar cal)
const
546 const auto parts = cal.partsFromDate(*
this);
554
555
557int QDate::year()
const
560 const auto parts = QGregorianCalendar::partsFromJulian(jd);
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
595int QDate::month(QCalendar cal)
const
598 const auto parts = cal.partsFromDate(*
this);
606
607
609int QDate::month()
const
612 const auto parts = QGregorianCalendar::partsFromJulian(jd);
620
621
622
623
624
625
626
628int QDate::day(QCalendar cal)
const
631 const auto parts = cal.partsFromDate(*
this);
639
640
642int QDate::day()
const
645 const auto parts = QGregorianCalendar::partsFromJulian(jd);
653
654
655
656
657
658
659
660
662int QDate::dayOfWeek(QCalendar cal)
const
667 return cal.dayOfWeek(*
this);
671
672
674int QDate::dayOfWeek()
const
676 return isValid() ? QGregorianCalendar::weekDayOfJulian(jd) : 0;
680
681
682
683
684
685
686
688int QDate::dayOfYear(QCalendar cal)
const
691 QDate firstDay = cal.dateFromParts(year(cal), 1, 1);
692 if (firstDay.isValid())
693 return firstDay.daysTo(*
this) + 1;
699
700
702int QDate::dayOfYear()
const
705 if (
const auto first = QGregorianCalendar::julianFromParts(year(), 1, 1))
706 return jd - *first + 1;
712
713
714
715
716
717
718
719
721int QDate::daysInMonth(QCalendar cal)
const
724 const auto parts = cal.partsFromDate(*
this);
726 return cal.daysInMonth(parts.month, parts.year);
732
733
735int QDate::daysInMonth()
const
738 const auto parts = QGregorianCalendar::partsFromJulian(jd);
740 return QGregorianCalendar::monthLength(parts.month, parts.year);
746
747
748
749
750
751
752
754int QDate::daysInYear(QCalendar cal)
const
759 return cal.daysInYear(year(cal));
763
764
766int QDate::daysInYear()
const
768 return isValid() ? QGregorianCalendar::leapTest(year()) ? 366 : 365 : 0;
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
790int QDate::weekNumber(
int *yearNumber)
const
797 const QDate thursday(addDays(4 - dayOfWeek()));
799 *yearNumber = thursday.year();
802 return (thursday.dayOfYear() + 6) / 7;
805#if QT_DEPRECATED_SINCE(6
, 9
)
807static QTimeZone asTimeZone(Qt::TimeSpec spec,
int offset,
const char *warner)
812 qWarning(
"%s: Pass a QTimeZone instead of Qt::TimeZone.", warner);
816 qWarning(
"%s: Ignoring offset (%d seconds) passed with Qt::LocalTime",
822 qWarning(
"%s: Ignoring offset (%d seconds) passed with Qt::UTC",
827 case Qt::OffsetFromUTC:
831 return QTimeZone::isUtcOrFixedOffset(spec)
832 ? QTimeZone::fromSecondsAheadOfUtc(offset)
833 : QTimeZone(QTimeZone::LocalTime);
841 using Bounds = std::numeric_limits<qint64>;
842 if (jd < Bounds::min() + JULIAN_DAY_FOR_EPOCH)
844 jd -= JULIAN_DAY_FOR_EPOCH;
845 const qint64 maxDay = Bounds::max() / MSECS_PER_DAY;
846 const qint64 minDay = Bounds::min() / MSECS_PER_DAY - 1;
852 return jd > minDay && jd <= maxDay;
854 return jd >= minDay && jd < maxDay;
856 Q_UNREACHABLE_RETURN(
false);
861 Q_ASSERT(!zone.isUtcOrFixedOffset());
863 const auto moment = [=](QTime time) {
864 return QDateTime(day, time, zone, QDateTime::TransitionResolution::Reject);
867 QDateTime when = moment(QTime(2, 0));
868 if (!when.isValid()) {
870 when = moment(QTime(12, 0));
871 if (!when.isValid()) {
873 when = moment(QTime(23, 59, 59, 999));
878 int high = when.time().msecsSinceStartOfDay() / 60000;
881 while (high > low + 1) {
882 const int mid = (high + low) / 2;
883 const QDateTime probe = QDateTime(day, QTime(mid / 60, mid % 60), zone,
884 QDateTime::TransitionResolution::PreferBefore);
885 if (probe.isValid() && probe.date() == day) {
895 if (QDateTime p = moment(when.time().addSecs(-1)); Q_UNLIKELY(p.isValid() && p.date() == day)) {
898 while (high > low + 1) {
899 const int mid = (high + low) / 2;
900 const int min = mid / 60;
901 const QDateTime probe = moment(QTime(min / 60, min % 60, mid % 60));
902 if (probe.isValid() && probe.date() == day) {
910 return when.isValid() ? when : QDateTime();
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941QDateTime QDate::startOfDay(
const QTimeZone &zone)
const
943 if (!inDateTimeRange(jd, DaySide::Start) || !zone.isValid())
946 QDateTime when(*
this, QTime(0, 0), zone,
947 QDateTime::TransitionResolution::RelativeToBefore);
948 if (Q_UNLIKELY(!when.isValid() || when.date() != *
this)) {
949#if QT_CONFIG(timezone)
951 if (zone.timeSpec() == Qt::TimeZone && zone.hasTransitions()) {
952 QTimeZone::OffsetData tran
955 = zone.previousTransition(QDateTime(addDays(1), QTime(12, 0), zone));
956 const QDateTime &at = tran.atUtc.toTimeZone(zone);
957 if (at.isValid() && at.date() == *
this)
962 when = toEarliest(*
this, zone);
969
970
971
972QDateTime QDate::startOfDay()
const
974 return startOfDay(QTimeZone::LocalTime);
977#if QT_DEPRECATED_SINCE(6
, 9
)
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006QDateTime QDate::startOfDay(Qt::TimeSpec spec,
int offsetSeconds)
const
1008 QTimeZone zone = asTimeZone(spec, offsetSeconds,
"QDate::startOfDay");
1010 return zone.timeSpec() == spec ? startOfDay(zone) : QDateTime();
1014static QDateTime
toLatest(QDate day,
const QTimeZone &zone)
1016 Q_ASSERT(!zone.isUtcOrFixedOffset());
1018 const auto moment = [=](QTime time) {
1019 return QDateTime(day, time, zone, QDateTime::TransitionResolution::Reject);
1022 QDateTime when = moment(QTime(21, 59, 59, 999));
1023 if (!when.isValid()) {
1025 when = moment(QTime(12, 0));
1026 if (!when.isValid()) {
1028 when = moment(QTime(0, 0));
1029 if (!when.isValid())
1034 int low = when.time().msecsSinceStartOfDay() / 60000;
1036 while (high > low + 1) {
1037 const int mid = (high + low) / 2;
1038 const QDateTime probe = QDateTime(day, QTime(mid / 60, mid % 60, 59, 999), zone,
1039 QDateTime::TransitionResolution::PreferAfter);
1040 if (probe.isValid() && probe.date() == day) {
1050 if (QDateTime p = moment(when.time().addSecs(1)); Q_UNLIKELY(p.isValid() && p.date() == day)) {
1053 while (high > low + 1) {
1054 const int mid = (high + low) / 2;
1055 const int min = mid / 60;
1056 const QDateTime probe = moment(QTime(min / 60, min % 60, mid % 60, 999));
1057 if (probe.isValid() && probe.date() == day) {
1065 return when.isValid() ? when : QDateTime();
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097QDateTime QDate::endOfDay(
const QTimeZone &zone)
const
1099 if (!inDateTimeRange(jd, DaySide::End) || !zone.isValid())
1102 QDateTime when(*
this, QTime(23, 59, 59, 999), zone,
1103 QDateTime::TransitionResolution::RelativeToAfter);
1104 if (Q_UNLIKELY(!when.isValid() || when.date() != *
this)) {
1105#if QT_CONFIG(timezone)
1107 if (zone.timeSpec() == Qt::TimeZone && zone.hasTransitions()) {
1108 QTimeZone::OffsetData tran
1111 = zone.nextTransition(QDateTime(addDays(-1), QTime(12, 0), zone));
1112 const QDateTime &at = tran.atUtc.toTimeZone(zone);
1113 if (at.isValid() && at.date() == *
this)
1118 when = toLatest(*
this, zone);
1124
1125
1126
1127QDateTime QDate::endOfDay()
const
1129 return endOfDay(QTimeZone::LocalTime);
1132#if QT_DEPRECATED_SINCE(6
, 9
)
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161QDateTime QDate::endOfDay(Qt::TimeSpec spec,
int offsetSeconds)
const
1163 QTimeZone zone = asTimeZone(spec, offsetSeconds,
"QDate::endOfDay");
1165 return endOfDay(zone);
1169#if QT_CONFIG(datestring)
1171static QString toStringTextDate(QDate date)
1173 if (date.isValid()) {
1175 const auto parts = cal.partsFromDate(date);
1176 if (parts.isValid()) {
1177 const QLatin1Char sp(
' ');
1178 return QLocale::c().dayName(cal.dayOfWeek(date), QLocale::ShortFormat) + sp
1179 + cal.monthName(QLocale::c(), parts.month, parts.year, QLocale::ShortFormat)
1181 + sp + QString::asprintf(
"%d %04d", parts.day, parts.year);
1187static QString toStringIsoDate(QDate date)
1189 const auto parts = QCalendar().partsFromDate(date);
1190 if (parts.isValid() && parts.year >= 0 && parts.year <= 9999)
1191 return QString::asprintf(
"%04d-%02d-%02d", parts.year, parts.month, parts.day);
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223QString QDate::toString(Qt::DateFormat format)
const
1229 case Qt::RFC2822Date:
1230 return QLocale::c().toString(*
this, u"dd MMM yyyy");
1233 return toStringTextDate(*
this);
1235 case Qt::ISODateWithMs:
1237 return toStringIsoDate(*
this);
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303QString QDate::toString(QStringView format, QCalendar cal)
const
1305 return QLocale::c().toString(*
this, format, cal);
1310
1311
1312
1313QString QDate::toString(QStringView format)
const
1315 return QLocale::c().toString(*
this, format, QCalendar());
1319
1320
1321
1322QString QDate::toString(
const QString &format)
const
1324 return QLocale::c().toString(*
this, qToStringViewIgnoringNull(format), QCalendar());
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338bool QDate::setDate(
int year,
int month,
int day)
1340 const auto maybe = QGregorianCalendar::julianFromParts(year, month, day);
1341 jd = maybe.value_or(nullJd());
1346
1347
1348
1349
1350
1351
1352
1353
1354
1356bool QDate::setDate(
int year,
int month,
int day, QCalendar cal)
1358 *
this = QDate(year, month, day, cal);
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374void QDate::getDate(
int *year,
int *month,
int *day)
const
1376 QCalendar::YearMonthDay parts;
1378 parts = QGregorianCalendar::partsFromJulian(jd);
1380 const bool ok = parts.isValid();
1382 *year = ok ? parts.year : 0;
1384 *month = ok ? parts.month : 0;
1386 *day = ok ? parts.day : 0;
1390
1391
1392
1393
1394
1395
1396
1397
1399QDate QDate::addDays(qint64 ndays)
const
1404 if (qint64 r; Q_UNLIKELY(qAddOverflow(jd, ndays, &r)))
1407 return fromJulianDay(r);
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1445QDate QDate::addMonths(
int nmonths, QCalendar cal)
const
1453 auto parts = cal.partsFromDate(*
this);
1455 if (!parts.isValid())
1457 Q_ASSERT(parts.year || cal.hasYearZero());
1459 parts.month += nmonths;
1460 while (parts.month <= 0) {
1461 if (--parts.year || cal.hasYearZero())
1462 parts.month += cal.monthsInYear(parts.year);
1464 int count = cal.monthsInYear(parts.year);
1465 while (parts.month > count) {
1466 parts.month -= count;
1467 count = (++parts.year || cal.hasYearZero()) ? cal.monthsInYear(parts.year) : 0;
1470 return fixedDate(parts, cal);
1474
1475
1477QDate QDate::addMonths(
int nmonths)
const
1485 auto parts = QGregorianCalendar::partsFromJulian(jd);
1487 if (!parts.isValid())
1489 Q_ASSERT(parts.year);
1491 parts.month += nmonths;
1492 while (parts.month <= 0) {
1496 while (parts.month > 12) {
1502 return fixedDate(parts);
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1519QDate QDate::addYears(
int nyears, QCalendar cal)
const
1524 auto parts = cal.partsFromDate(*
this);
1525 if (!parts.isValid())
1528 int old_y = parts.year;
1529 parts.year += nyears;
1532 if (!cal.hasYearZero() && ((old_y > 0) != (parts.year > 0) || !parts.year))
1533 parts.year += nyears > 0 ? +1 : -1;
1535 return fixedDate(parts, cal);
1539
1540
1542QDate QDate::addYears(
int nyears)
const
1547 auto parts = QGregorianCalendar::partsFromJulian(jd);
1548 if (!parts.isValid())
1551 int old_y = parts.year;
1552 parts.year += nyears;
1555 if ((old_y > 0) != (parts.year > 0) || !parts.year)
1556 parts.year += nyears > 0 ? +1 : -1;
1558 return fixedDate(parts);
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1573qint64 QDate::daysTo(QDate d)
const
1575 if (isNull() || d.isNull())
1584
1585
1586
1587
1588
1591
1592
1593
1594
1595
1596
1597
1600
1601
1602
1603
1606
1607
1608
1609
1610
1613
1614
1615
1616
1619
1620
1621
1622
1623
1626
1627
1628
1629
1630
1632#if QT_CONFIG(datestring)
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1648
1649
1650
1651QDate QDate::fromString(QStringView string, Qt::DateFormat format)
1653 if (string.isEmpty())
1657 case Qt::RFC2822Date:
1658 return rfcDateImpl(string).date;
1660 case Qt::TextDate: {
1662 QVarLengthArray<QStringView, 4> parts;
1663 auto tokens = string.tokenize(u' ', Qt::SkipEmptyParts);
1664 auto it = tokens.begin();
1665 for (
int i = 0; i < 4 && it != tokens.end(); ++i, ++it)
1666 parts.emplace_back(*it);
1668 if (parts.size() != 4 || it != tokens.end())
1672 int year = parts.at(3).toInt(&ok);
1673 int day = ok ? parts.at(2).toInt(&ok) : 0;
1677 const int month = fromShortMonthName(parts.at(1));
1681 return QDate(year, month, day);
1685 if (string.size() >= 10 && string[4].isPunct() && string[7].isPunct()
1686 && (string.size() == 10 || !string[10].isDigit())) {
1687 const ParsedInt year = readInt(string.first(4));
1688 const ParsedInt month = readInt(string.sliced(5, 2));
1689 const ParsedInt day = readInt(string.sliced(8, 2));
1690 if (year.ok() && year.result > 0 && year.result <= 9999 && month.ok() && day.ok())
1691 return QDate(year.result, month.result, day.result);
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1830
1831
1832
1833
1836
1837
1838
1839QDate QDate::fromString(
const QString &string, QStringView format,
int baseYear, QCalendar cal)
1842#if QT_CONFIG(datetimeparser)
1843 QDateTimeParser dt(QMetaType::QDate, QDateTimeParser::FromString, cal);
1844 dt.setDefaultLocale(QLocale::c());
1845 if (dt.parseFormat(format))
1846 dt.fromString(string, &date,
nullptr, baseYear);
1857
1858
1859
1860
1863
1864
1865
1866
1869
1870
1871
1872
1875
1876
1877
1878
1879
1880
1883
1884
1885
1886
1887
1888QDate QDate::fromString(
const QString &string, QStringView format,
int baseYear)
1890 return fromString(string, format, baseYear, QCalendar());
1894
1895
1896
1897
1898
1899
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1914bool QDate::isValid(
int year,
int month,
int day)
1916 return QGregorianCalendar::validParts(year, month, day);
1920
1921
1922
1923
1924
1925
1926
1928bool QDate::isLeapYear(
int y)
1930 return QGregorianCalendar::leapTest(y);
1934
1935
1936
1937
1938
1941
1942
1943
1944
1945
1948
1949
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1998
1999
2000
2001
2002
2003
2004
2005
2008
2009
2010
2011
2012
2013
2014
2015
2017QTime::QTime(
int h,
int m,
int s,
int ms)
2019 setHMS(h, m, s, ms);
2024
2025
2026
2027
2028
2029
2030
2031
2034
2035
2036
2037
2038
2040bool QTime::isValid()
const
2042 return mds > NullTime && mds < MSECS_PER_DAY;
2047
2048
2049
2050
2051
2052
2054int QTime::hour()
const
2059 return ds() / MSECS_PER_HOUR;
2063
2064
2065
2066
2067
2068
2070int QTime::minute()
const
2075 return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN;
2079
2080
2081
2082
2083
2084
2086int QTime::second()
const
2091 return (ds() / MSECS_PER_SEC) % SECS_PER_MIN;
2095
2096
2097
2098
2099
2100
2102int QTime::msec()
const
2107 return ds() % MSECS_PER_SEC;
2110#if QT_CONFIG(datestring)
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2135QString QTime::toString(Qt::DateFormat format)
const
2141 case Qt::ISODateWithMs:
2142 return QString::asprintf(
"%02d:%02d:%02d.%03d", hour(), minute(), second(), msec());
2143 case Qt::RFC2822Date:
2147 return QString::asprintf(
"%02d:%02d:%02d", hour(), minute(), second());
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2259QString QTime::toString(QStringView format)
const
2261 return QLocale::c().toString(*
this, format);
2266
2267
2268
2269
2270
2271
2272
2273
2274
2276bool QTime::setHMS(
int h,
int m,
int s,
int ms)
2278 if (!isValid(h,m,s,ms)) {
2282 mds = ((h * MINS_PER_HOUR + m) * SECS_PER_MIN + s) * MSECS_PER_SEC + ms;
2283 Q_ASSERT(mds >= 0 && mds < MSECS_PER_DAY);
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2302QTime QTime::addSecs(
int s)
const
2305 return addMSecs(s * MSECS_PER_SEC);
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2323int QTime::secsTo(QTime t)
const
2325 if (!isValid() || !t.isValid())
2329 int ourSeconds = ds() / MSECS_PER_SEC;
2330 int theirSeconds = t.ds() / MSECS_PER_SEC;
2331 return theirSeconds - ourSeconds;
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2346QTime QTime::addMSecs(
int ms)
const
2350 t.mds = QRoundingDown::qMod<MSECS_PER_DAY>(ds() + ms);
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2368int QTime::msecsTo(QTime t)
const
2370 if (!isValid() || !t.isValid())
2372 return t.ds() - ds();
2377
2378
2379
2380
2383
2384
2385
2386
2389
2390
2391
2392
2395
2396
2397
2398
2399
2402
2403
2404
2405
2408
2409
2410
2411
2412
2415
2416
2417
2418
2419
2420
2421
2422
2423
2426
2427
2428
2429
2430
2431
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2448#if QT_CONFIG(datestring)
2450static QTime fromIsoTimeString(QStringView string, Qt::DateFormat format,
bool *isMidnight24)
2452 Q_ASSERT(format == Qt::TextDate || format == Qt::ISODate || format == Qt::ISODateWithMs);
2454 *isMidnight24 =
false;
2460 const qsizetype dot = string.indexOf(u'.'), comma = string.indexOf(u',');
2462 tail = string.sliced(dot + 1);
2463 if (tail.indexOf(u'.') != -1)
2465 string = string.first(dot);
2466 }
else if (comma != -1) {
2467 tail = string.sliced(comma + 1);
2468 string = string.first(comma);
2470 if (tail.indexOf(u',') != -1)
2473 const ParsedInt frac = readInt(tail);
2475 if (tail.isEmpty() ? dot != -1 || comma != -1 : !frac.ok())
2477 Q_ASSERT(frac.ok() ^ tail.isEmpty());
2478 double fraction = frac.ok() ? frac.result * std::pow(0.1, tail.size()) : 0.0;
2480 const qsizetype size = string.size();
2481 if (size < 2 || size > 8)
2484 ParsedInt hour = readInt(string.first(2));
2485 if (!hour.ok() || hour.result > (format == Qt::TextDate ? 23 : 24))
2489 if (string.size() > 2) {
2490 if (string[2] == u':' && string.size() > 4)
2491 minute = readInt(string.sliced(3, 2));
2492 if (!minute.ok() || minute.result >= MINS_PER_HOUR)
2494 }
else if (format == Qt::TextDate) {
2496 }
else if (frac.ok()) {
2497 Q_ASSERT(!(fraction < 0.0) && fraction < 1.0);
2498 fraction *= MINS_PER_HOUR;
2499 minute.result = qulonglong(fraction);
2500 fraction -= minute.result;
2504 if (string.size() > 5) {
2505 if (string[5] == u':' && string.size() == 8)
2506 second = readInt(string.sliced(6, 2));
2507 if (!second.ok() || second.result >= SECS_PER_MIN)
2509 }
else if (frac.ok()) {
2510 if (format == Qt::TextDate)
2512 Q_ASSERT(!(fraction < 0.0) && fraction < 1.0);
2513 fraction *= SECS_PER_MIN;
2514 second.result = qulonglong(fraction);
2515 fraction -= second.result;
2518 Q_ASSERT(!(fraction < 0.0) && fraction < 1.0);
2520 int msec = frac.ok() ? qRound(MSECS_PER_SEC * fraction) : 0;
2522 if (msec == MSECS_PER_SEC) {
2525 if (isMidnight24 || hour.result < 23 || minute.result < 59 || second.result < 59) {
2527 if (++second.result == SECS_PER_MIN) {
2529 if (++minute.result == MINS_PER_HOUR) {
2538 msec = MSECS_PER_SEC - 1;
2543 if (hour.result == 24 && minute.result == 0 && second.result == 0 && msec == 0) {
2544 Q_ASSERT(format != Qt::TextDate);
2546 *isMidnight24 =
true;
2550 return QTime(hour.result, minute.result, second.result, msec);
2554
2555
2556
2557
2558
2559
2560
2563
2564
2565
2566QTime QTime::fromString(QStringView string, Qt::DateFormat format)
2568 if (string.isEmpty())
2572 case Qt::RFC2822Date:
2573 return rfcDateImpl(string).time;
2575 case Qt::ISODateWithMs:
2578 return fromIsoTimeString(string, format,
nullptr);
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2661
2662
2663
2664
2667
2668
2669
2670QTime QTime::fromString(
const QString &string, QStringView format)
2673#if QT_CONFIG(datetimeparser)
2674 QDateTimeParser dt(QMetaType::QTime, QDateTimeParser::FromString, QCalendar());
2675 dt.setDefaultLocale(QLocale::c());
2676 if (dt.parseFormat(format))
2677 dt.fromString(string,
nullptr, &time);
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2701bool QTime::isValid(
int h,
int m,
int s,
int ms)
2703 return (uint(h) < 24 && uint(m) < MINS_PER_HOUR && uint(s) < SECS_PER_MIN
2704 && uint(ms) < MSECS_PER_SEC);
2708
2709
2718 return JULIAN_DAY_FOR_EPOCH + QRoundingDown::qDiv<MSECS_PER_DAY>(msecs);
2723 return QDate::fromJulianDay(msecsToJulianDay(msecs));
2728 return QTime::fromMSecsSinceStartOfDay(QRoundingDown::qMod<MSECS_PER_DAY>(msecs));
2735 return qMulOverflow(days, std::integral_constant<qint64, MSECS_PER_DAY>(), sumMillis)
2736 || qAddOverflow(*sumMillis, millisInDay, sumMillis);
2742 qint64 days = date.toJulianDay() - JULIAN_DAY_FOR_EPOCH;
2743 qint64 msecs, dayms = time.msecsSinceStartOfDay();
2744 if (days < 0 && dayms > 0) {
2746 dayms -= MSECS_PER_DAY;
2748 if (daysAndMillisOverflow(days, dayms, &msecs)) {
2749 using Bound = std::numeric_limits<qint64>;
2750 return days < 0 ? Bound::min() : Bound::max();
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2774 static const auto bounds = QLocalTime::computeSystemMillisRange();
2775 return (bounds.minClip || millis >= bounds.min - slack)
2776 && (bounds.maxClip || millis <= bounds.max + slack);
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2797#if defined(Q_OS_WIN) || defined(Q_OS_WASM)
2798 static constexpr int forLeapEarly[] = { 1984, 1996, 1980, 1992, 1976, 1988, 1972 };
2799 static constexpr int regularEarly[] = { 1978, 1973, 1974, 1975, 1970, 1971, 1977 };
2801 static constexpr int forLeapEarly[] = { 1928, 1912, 1924, 1908, 1920, 1904, 1916 };
2802 static constexpr int regularEarly[] = { 1905, 1906, 1907, 1902, 1903, 1909, 1910 };
2804 static constexpr int forLeapLate[] = { 2012, 2024, 2036, 2020, 2032, 2016, 2028 };
2805 static constexpr int regularLate[] = { 2034, 2035, 2030, 2031, 2037, 2027, 2033 };
2806 const int dow = QGregorianCalendar::yearStartWeekDay(year);
2807 Q_ASSERT(dow == QDate(year, 1, 1).dayOfWeek());
2808 const int res = (QGregorianCalendar::leapTest(year)
2809 ? (year < 1970 ? forLeapEarly : forLeapLate)
2810 : (year < 1970 ? regularEarly : regularLate))[dow == 7 ? 0 : dow];
2811 Q_ASSERT(QDate(res, 1, 1).dayOfWeek() == dow);
2812 Q_ASSERT(QDate(res, 12, 31).dayOfWeek() == QDate(year, 12, 31).dayOfWeek());
2817QDateTimePrivate::ZoneState QDateTimePrivate::expressUtcAsLocal(qint64 utcMSecs)
2819 ZoneState result{utcMSecs};
2821 if (millisInSystemRange(utcMSecs)) {
2822 result = QLocalTime::utcToLocal(utcMSecs);
2829#if QT_CONFIG(timezone)
2830 if (
const auto sys = QTimeZone::systemTimeZone(); sys.isValid()) {
2831 result.offset = sys.d->offsetFromUtc(utcMSecs);
2832 if (result.offset != QTimeZonePrivate::invalidSeconds()) {
2833 if (qAddOverflow(utcMSecs, result.offset * MSECS_PER_SEC, &result.when))
2835 result.dst = sys.d->isDaylightTime(utcMSecs) ? DaylightTime : StandardTime;
2836 result.valid =
true;
2845 const qint64 jd = msecsToJulianDay(utcMSecs);
2846 const auto ymd = QGregorianCalendar::partsFromJulian(jd);
2847 qint64 diffMillis, fakeUtc;
2848 const auto fakeJd = QGregorianCalendar::julianFromParts(systemTimeYearMatching(ymd.year),
2849 ymd.month, ymd.day);
2850 if (Q_UNLIKELY(!fakeJd
2851 || qMulOverflow(jd - *fakeJd, std::integral_constant<qint64, MSECS_PER_DAY>(),
2853 || qSubOverflow(utcMSecs, diffMillis, &fakeUtc))) {
2857 result = QLocalTime::utcToLocal(fakeUtc);
2859 if (!result.valid || qAddOverflow(result.when, diffMillis, &result.when)) {
2862 result.when = utcMSecs;
2863 result.valid =
false;
2874 qint64 jd = msecsToJulianDay(millis);
2875 auto ymd = QGregorianCalendar::partsFromJulian(jd);
2876 const auto fakeJd = QGregorianCalendar::julianFromParts(systemTimeYearMatching(ymd.year),
2877 ymd.month, ymd.day);
2878 result.good = fakeJd && !daysAndMillisOverflow(*fakeJd - jd, millis, &result.shifted);
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2940 case QDateTime::TransitionResolution::RelativeToBefore:
2941 return QDateTimePrivate::GapUseAfter | QDateTimePrivate::FoldUseBefore;
2942 case QDateTime::TransitionResolution::RelativeToAfter:
2943 return QDateTimePrivate::GapUseBefore | QDateTimePrivate::FoldUseAfter;
2944 case QDateTime::TransitionResolution::PreferBefore:
2945 return QDateTimePrivate::GapUseBefore | QDateTimePrivate::FoldUseBefore;
2946 case QDateTime::TransitionResolution::PreferAfter:
2947 return QDateTimePrivate::GapUseAfter | QDateTimePrivate::FoldUseAfter;
2948 case QDateTime::TransitionResolution::PreferStandard:
2949 return QDateTimePrivate::GapUseBefore
2950 | QDateTimePrivate::FoldUseAfter
2951 | QDateTimePrivate::FlipForReverseDst;
2952 case QDateTime::TransitionResolution::PreferDaylightSaving:
2953 return QDateTimePrivate::GapUseAfter
2954 | QDateTimePrivate::FoldUseBefore
2955 | QDateTimePrivate::FlipForReverseDst;
2956 case QDateTime::TransitionResolution::Reject:
break;
2964 return toTransitionOptions(dst == QDateTimePrivate::DaylightTime
2965 ? QDateTime::TransitionResolution::PreferDaylightSaving
2966 : QDateTime::TransitionResolution::PreferStandard);
2969QString QDateTimePrivate::localNameAtMillis(qint64 millis, DaylightStatus dst)
2971 const QDateTimePrivate::TransitionOptions resolve = toTransitionOptions(dst);
2972 QString abbreviation;
2973 if (millisInSystemRange(millis, MSECS_PER_DAY)) {
2974 abbreviation = QLocalTime::localTimeAbbbreviationAt(millis, resolve);
2975 if (!abbreviation.isEmpty())
2976 return abbreviation;
2980#if QT_CONFIG(timezone)
2982 const auto sys = QTimeZone::systemTimeZone();
2983 if (sys.isValid()) {
2984 ZoneState state = zoneStateAtMillis(sys, millis, resolve);
2986 return sys.d->abbreviation(state.when - state.offset * MSECS_PER_SEC);
2992 auto fake = millisToWithinRange(millis);
2993 if (Q_LIKELY(fake.good))
2994 return QLocalTime::localTimeAbbbreviationAt(fake.shifted, resolve);
3001QDateTimePrivate::ZoneState QDateTimePrivate::localStateAtMillis(
3002 qint64 millis, QDateTimePrivate::TransitionOptions resolve)
3006 if (millisInSystemRange(millis, MSECS_PER_DAY)) {
3007 auto result = QLocalTime::mapLocalTime(millis, resolve);
3013#if QT_CONFIG(timezone)
3015 const auto sys = QTimeZone::systemTimeZone();
3017 return zoneStateAtMillis(sys, millis, resolve);
3022 auto fake = millisToWithinRange(millis);
3023 if (Q_LIKELY(fake.good)) {
3024 auto result = QLocalTime::mapLocalTime(fake.shifted, resolve);
3027 if (Q_UNLIKELY(qAddOverflow(result.when, millis - fake.shifted, &adjusted))) {
3028 using Bound = std::numeric_limits<qint64>;
3029 adjusted = millis < fake.shifted ? Bound::min() : Bound::max();
3031 result.when = adjusted;
3033 result.when = millis;
3041#if QT_CONFIG(timezone)
3045QDateTimePrivate::ZoneState QDateTimePrivate::zoneStateAtMillis(
3046 const QTimeZone &zone, qint64 millis, QDateTimePrivate::TransitionOptions resolve)
3048 Q_ASSERT(zone.isValid());
3049 Q_ASSERT(zone.timeSpec() == Qt::TimeZone);
3050 return zone.d->stateAtZoneTime(millis, resolve);
3055 QDateTimePrivate::TransitionOptions resolve)
3057 if (zone.timeSpec() == Qt::LocalTime)
3058 return QDateTimePrivate::localStateAtMillis(millis, resolve);
3059#if QT_CONFIG(timezone)
3060 if (zone.timeSpec() == Qt::TimeZone && zone.isValid())
3061 return QDateTimePrivate::zoneStateAtMillis(zone, millis, resolve);
3068 return spec == Qt::LocalTime || spec == Qt::UTC;
3073 if constexpr (!QDateTimeData::CanBeSmall)
3077 sd.msecs = qintptr(msecs);
3078 return sd.msecs == msecs;
3081static constexpr inline
3084 status &= ~QDateTimePrivate::TimeSpecMask;
3085 status |= QDateTimePrivate::StatusFlags::fromInt(
int(spec) << QDateTimePrivate::TimeSpecShift);
3091 return Qt::TimeSpec((status & QDateTimePrivate::TimeSpecMask).toInt() >> QDateTimePrivate::TimeSpecShift);
3098 sf &= ~QDateTimePrivate::DaylightMask;
3099 if (status == QDateTimePrivate::DaylightTime) {
3100 sf |= QDateTimePrivate::SetToDaylightTime;
3101 }
else if (status == QDateTimePrivate::StandardTime) {
3102 sf |= QDateTimePrivate::SetToStandardTime;
3108static constexpr inline
3111 if (status.testFlag(QDateTimePrivate::SetToDaylightTime))
3112 return QDateTimePrivate::DaylightTime;
3113 if (status.testFlag(QDateTimePrivate::SetToStandardTime))
3114 return QDateTimePrivate::StandardTime;
3115 return QDateTimePrivate::UnknownDaylightTime;
3123 return qintptr(d.d) >> 8;
3133 return QDateTimePrivate::StatusFlag(qintptr(d.d) & 0xFF);
3140 return extractSpec(getStatus(d));
3144
3145
3146
3147
3150 const auto status = getStatus(a);
3151 if (status != getStatus(b))
3155 switch (extractSpec(status)) {
3162
3163
3164
3165
3166 case Qt::OffsetFromUTC:
3167 Q_ASSERT(!a.isShort() && !b.isShort());
3168 return a->m_offsetFromUtc == b->m_offsetFromUtc;
3170 Q_UNREACHABLE_RETURN(
false);
3175 QDateTimePrivate::TransitionOptions resolve)
3177 Q_ASSERT(zone.timeSpec() == Qt::TimeZone || zone.timeSpec() == Qt::LocalTime);
3178 auto status = getStatus(d);
3179 Q_ASSERT(extractSpec(status) == zone.timeSpec());
3180 int offsetFromUtc = 0;
3182
3183
3184
3185
3186
3187
3188
3189
3192 if (!status.testFlags(QDateTimePrivate::ValidDate | QDateTimePrivate::ValidTime)) {
3193 status.setFlag(QDateTimePrivate::ValidDateTime,
false);
3197 qint64 msecs = getMSecs(d);
3198 QDateTimePrivate::ZoneState state = stateAtMillis(zone, msecs, resolve);
3199 Q_ASSERT(!state.valid || (state.offset >= -SECS_PER_DAY && state.offset <= SECS_PER_DAY));
3200 if (state.dst == QDateTimePrivate::UnknownDaylightTime) {
3201 status.setFlag(QDateTimePrivate::ValidDateTime,
false);
3202 }
else if (state.valid) {
3203 status = mergeDaylightStatus(status, state.dst);
3204 offsetFromUtc = state.offset;
3205 status.setFlag(QDateTimePrivate::ValidDateTime,
true);
3206 if (Q_UNLIKELY(msecs != state.when)) {
3208 if (status.testFlag(QDateTimePrivate::ShortData)) {
3209 if (msecsCanBeSmall(state.when)) {
3210 d.data.msecs = qintptr(state.when);
3213 status.setFlag(QDateTimePrivate::ShortData,
false);
3217 if (!status.testFlag(QDateTimePrivate::ShortData))
3218 d->m_msecs = state.when;
3221 status.setFlag(QDateTimePrivate::ValidDateTime,
false);
3225 if (status.testFlag(QDateTimePrivate::ShortData)) {
3226 d.data.status = status.toInt();
3228 d->m_status = status;
3229 d->m_offsetFromUtc = offsetFromUtc;
3236 auto status = getStatus(d);
3237 Q_ASSERT(QTimeZone::isUtcOrFixedOffset(extractSpec(status)));
3238 status.setFlag(QDateTimePrivate::ValidDateTime,
3239 status.testFlags(QDateTimePrivate::ValidDate | QDateTimePrivate::ValidTime));
3241 if (status.testFlag(QDateTimePrivate::ShortData))
3242 d.data.status = status.toInt();
3244 d->m_status = status;
3250 auto spec = extractSpec(getStatus(d));
3252 case Qt::OffsetFromUTC:
3261 refreshZonedDateTime(d, d.timeZone(), toTransitionOptions(resolve));
3267 QDateTime::TransitionResolution resolve)
3269 Qt::TimeSpec spec = zone.timeSpec();
3270 auto status = mergeSpec(getStatus(d), spec);
3271 bool reuse = d.isShort();
3276 Q_ASSERT(zone.fixedSecondsAheadOfUtc() == 0);
3278 case Qt::OffsetFromUTC:
3280 offset = zone.fixedSecondsAheadOfUtc();
3290 status &= ~(QDateTimePrivate::ValidDateTime | QDateTimePrivate::DaylightMask);
3292 d.data.status = status.toInt();
3295 d->m_status = status & ~QDateTimePrivate::ShortData;
3296 d->m_offsetFromUtc = offset;
3297#if QT_CONFIG(timezone)
3298 if (spec == Qt::TimeZone)
3299 d->m_timeZone = zone;
3303 if (QTimeZone::isUtcOrFixedOffset(spec))
3306 refreshZonedDateTime(d, zone, toTransitionOptions(resolve));
3312 if (!time.isValid() && date.isValid())
3313 time = QTime::fromMSecsSinceStartOfDay(0);
3315 QDateTimePrivate::StatusFlags newStatus = { };
3319 if (date.isValid()) {
3320 days = date.toJulianDay() - JULIAN_DAY_FOR_EPOCH;
3321 newStatus = QDateTimePrivate::ValidDate;
3326 if (time.isValid()) {
3327 ds = time.msecsSinceStartOfDay();
3328 newStatus |= QDateTimePrivate::ValidTime;
3330 Q_ASSERT(ds < MSECS_PER_DAY);
3333 if (days < 0 && ds > 0) {
3335 ds -= MSECS_PER_DAY;
3340 if (daysAndMillisOverflow(days, qint64(ds), &msecs)) {
3341 newStatus = QDateTimePrivate::StatusFlags{};
3346 if (msecsCanBeSmall(msecs)) {
3348 d.data.msecs = qintptr(msecs);
3349 d.data.status &= ~(QDateTimePrivate::ValidityMask | QDateTimePrivate::DaylightMask).toInt();
3350 d.data.status |= newStatus.toInt();
3359 d->m_status &= ~(QDateTimePrivate::ValidityMask | QDateTimePrivate::DaylightMask);
3360 d->m_status |= newStatus;
3366 auto status = getStatus(d);
3367 const qint64 msecs = getMSecs(d);
3368 const auto dayMilli = QRoundingDown::qDivMod<MSECS_PER_DAY>(msecs);
3369 return { status.testFlag(QDateTimePrivate::ValidDate)
3370 ? QDate::fromJulianDay(JULIAN_DAY_FOR_EPOCH + dayMilli.quotient)
3372 status.testFlag(QDateTimePrivate::ValidTime)
3373 ? QTime::fromMSecsSinceStartOfDay(dayMilli.remainder)
3378
3379
3381inline QDateTime::Data::Data()
noexcept
3386 quintptr value = mergeSpec(QDateTimePrivate::ShortData, Qt::LocalTime).toInt();
3387 d =
reinterpret_cast<QDateTimePrivate *>(value);
3390inline QDateTime::Data::Data(
const QTimeZone &zone)
3392 Qt::TimeSpec spec = zone.timeSpec();
3393 if (CanBeSmall && Q_LIKELY(specCanBeSmall(spec))) {
3394 quintptr value = mergeSpec(QDateTimePrivate::ShortData, spec).toInt();
3395 d =
reinterpret_cast<QDateTimePrivate *>(value);
3396 Q_ASSERT(isShort());
3399 d =
new QDateTimePrivate;
3401 d->m_status = mergeSpec({}, spec);
3402 if (spec == Qt::OffsetFromUTC)
3403 d->m_offsetFromUtc = zone.fixedSecondsAheadOfUtc();
3404 else if (spec == Qt::TimeZone)
3405 d->m_timeZone = zone;
3406 Q_ASSERT(!isShort());
3410inline QDateTime::Data::Data(
const Data &other)
noexcept
3415 if (specCanBeSmall(extractSpec(d->m_status)) && msecsCanBeSmall(d->m_msecs)) {
3417 sd.msecs = qintptr(d->m_msecs);
3418 sd.status = (d->m_status | QDateTimePrivate::ShortData).toInt();
3427inline QDateTime::Data::Data(Data &&other)
noexcept
3432 Q_ASSERT(dummy.isShort());
3433 other.data = dummy.data;
3436inline QDateTime::Data &QDateTime::Data::operator=(
const Data &other)
noexcept
3438 if (isShort() ? data == other.data : d == other.d)
3443 if (!other.isShort()) {
3445 if (specCanBeSmall(extractSpec(other.d->m_status)) && msecsCanBeSmall(other.d->m_msecs)) {
3447 sd.msecs = qintptr(other.d->m_msecs);
3448 sd.status = (other.d->m_status | QDateTimePrivate::ShortData).toInt();
3456 if (!(quintptr(x) & QDateTimePrivate::ShortData) && !x->ref.deref())
3461inline QDateTime::Data::~Data()
3463 if (!isShort() && !d->ref.deref())
3467inline bool QDateTime::Data::isShort()
const
3469 bool b = quintptr(d) & QDateTimePrivate::ShortData;
3472 Q_ASSERT(b || !d->m_status.testFlag(QDateTimePrivate::ShortData));
3476 if constexpr (CanBeSmall)
3478 return Q_UNLIKELY(b);
3481inline void QDateTime::Data::detach()
3483 QDateTimePrivate *x;
3484 bool wasShort = isShort();
3487 x =
new QDateTimePrivate;
3488 x->m_status = QDateTimePrivate::StatusFlags::fromInt(data.status) & ~QDateTimePrivate::ShortData;
3489 x->m_msecs = data.msecs;
3491 if (d->ref.loadRelaxed() == 1)
3494 x =
new QDateTimePrivate(*d);
3497 x->ref.storeRelaxed(1);
3498 if (!wasShort && !d->ref.deref())
3503void QDateTime::Data::invalidate()
3506 data.status &= ~
int(QDateTimePrivate::ValidityMask);
3509 d->m_status &= ~QDateTimePrivate::ValidityMask;
3513QTimeZone QDateTime::Data::timeZone()
const
3515 switch (getSpec(*
this)) {
3517 return QTimeZone::UTC;
3518 case Qt::OffsetFromUTC:
3519 return QTimeZone::fromSecondsAheadOfUtc(d->m_offsetFromUtc);
3521#if QT_CONFIG(timezone)
3522 if (d->m_timeZone.isValid())
3523 return d->m_timeZone;
3527 return QTimeZone::LocalTime;
3532inline const QDateTimePrivate *QDateTime::Data::operator->()
const
3534 Q_ASSERT(!isShort());
3538inline QDateTimePrivate *QDateTime::Data::operator->()
3541 Q_ASSERT(!isShort());
3542 Q_ASSERT(d->ref.loadRelaxed() == 1);
3547
3548
3551QDateTime::Data QDateTimePrivate::create(QDate toDate, QTime toTime,
const QTimeZone &zone,
3552 QDateTime::TransitionResolution resolve)
3554 QDateTime::Data result(zone);
3555 setDateTime(result, toDate, toTime);
3556 if (zone.isUtcOrFixedOffset())
3557 refreshSimpleDateTime(result);
3559 refreshZonedDateTime(result, zone, toTransitionOptions(resolve));
3564
3565
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3944
3945
3946
3947
3948
3949
3950QDateTime::QDateTime()
noexcept
3952#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED) || QT_POINTER_SIZE == 8
3953 static_assert(
sizeof(ShortData) ==
sizeof(qint64));
3954 static_assert(
sizeof(Data) ==
sizeof(qint64));
3956 static_assert(
sizeof(ShortData) >=
sizeof(
void*),
"oops, Data::swap() is broken!");
3959#if QT_DEPRECATED_SINCE(6
, 9
)
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980QDateTime::QDateTime(QDate date, QTime time, Qt::TimeSpec spec,
int offsetSeconds)
3981 : d(QDateTimePrivate::create(date, time, asTimeZone(spec, offsetSeconds,
"QDateTime"),
3982 TransitionResolution::LegacyBehavior))
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4004QDateTime::QDateTime(QDate date, QTime time,
const QTimeZone &timeZone, TransitionResolution resolve)
4005 : d(QDateTimePrivate::create(date, time, timeZone, resolve))
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4022QDateTime::QDateTime(QDate date, QTime time, TransitionResolution resolve)
4023 : d(QDateTimePrivate::create(date, time, QTimeZone::LocalTime, resolve))
4028
4029
4030QDateTime::QDateTime(
const QDateTime &other)
noexcept
4036
4037
4038
4039
4040QDateTime::QDateTime(QDateTime &&other)
noexcept
4041 : d(std::move(other.d))
4046
4047
4048QDateTime::~QDateTime()
4053
4054
4056QDateTime &QDateTime::operator=(
const QDateTime &other)
noexcept
4062
4063
4064
4065
4068
4069
4070
4071
4072
4074bool QDateTime::isNull()
const
4077 return !getStatus(d).testAnyFlag(QDateTimePrivate::ValidityMask);
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4094bool QDateTime::isValid()
const
4096 return getStatus(d).testFlag(QDateTimePrivate::ValidDateTime);
4100
4101
4102
4103
4105QDate QDateTime::date()
const
4107 return getStatus(d).testFlag(QDateTimePrivate::ValidDate) ? msecsToDate(getMSecs(d)) : QDate();
4111
4112
4113
4114
4116QTime QDateTime::time()
const
4118 return getStatus(d).testFlag(QDateTimePrivate::ValidTime) ? msecsToTime(getMSecs(d)) : QTime();
4122
4123
4124
4125
4126
4127
4128
4129
4130
4132Qt::TimeSpec QDateTime::timeSpec()
const
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4151QTimeZone QDateTime::timeRepresentation()
const
4153 return d.timeZone();
4156#if QT_CONFIG(timezone)
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4172QTimeZone QDateTime::timeZone()
const
4174 return d.timeZone().asBackendZone();
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4200int QDateTime::offsetFromUtc()
const
4202 const auto status = getStatus(d);
4203 if (!status.testFlags(QDateTimePrivate::ValidDate | QDateTimePrivate::ValidTime))
4207 return d->m_offsetFromUtc;
4209 auto spec = extractSpec(status);
4210 if (spec == Qt::LocalTime) {
4212 const auto resolve = toTransitionOptions(extractDaylightStatus(status));
4213 return QDateTimePrivate::localStateAtMillis(getMSecs(d), resolve).offset;
4216 Q_ASSERT(spec == Qt::UTC);
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4241QString QDateTime::timeZoneAbbreviation()
const
4246 switch (getSpec(d)) {
4249 case Qt::OffsetFromUTC:
4250 return "UTC"_L1 + toOffsetString(Qt::ISODate, d->m_offsetFromUtc);
4252#if !QT_CONFIG(timezone)
4255 Q_ASSERT(d->m_timeZone.isValid());
4256 return d->m_timeZone.abbreviation(*
this);
4259#if defined(Q_OS_WIN) && QT_CONFIG(timezone)
4261 if (QString sys = QTimeZone::systemTimeZone().abbreviation(*
this); !sys.isEmpty())
4265 return QDateTimePrivate::localNameAtMillis(getMSecs(d),
4266 extractDaylightStatus(getStatus(d)));
4272
4273
4274
4275
4276
4277
4278
4279
4280
4282bool QDateTime::isDaylightTime()
const
4287 switch (getSpec(d)) {
4289 case Qt::OffsetFromUTC:
4292#if !QT_CONFIG(timezone)
4295 Q_ASSERT(d->m_timeZone.isValid());
4296 if (
auto dst = extractDaylightStatus(getStatus(d));
4297 dst != QDateTimePrivate::UnknownDaylightTime) {
4298 return dst == QDateTimePrivate::DaylightTime;
4300 return d->m_timeZone.d->isDaylightTime(toMSecsSinceEpoch());
4302 case Qt::LocalTime: {
4303 auto dst = extractDaylightStatus(getStatus(d));
4304 if (dst == QDateTimePrivate::UnknownDaylightTime) {
4305 dst = QDateTimePrivate::localStateAtMillis(
4306 getMSecs(d), toTransitionOptions(TransitionResolution::LegacyBehavior)).dst;
4308 return dst == QDateTimePrivate::DaylightTime;
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4329void QDateTime::setDate(QDate date, TransitionResolution resolve)
4331 setDateTime(d, date, time());
4332 checkValidDateTime(d, resolve);
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4354void QDateTime::setTime(QTime time, TransitionResolution resolve)
4356 setDateTime(d, date(), time);
4357 checkValidDateTime(d, resolve);
4360#if QT_DEPRECATED_SINCE(6
, 9
)
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4379void QDateTime::setTimeSpec(Qt::TimeSpec spec)
4381 reviseTimeZone(d, asTimeZone(spec, 0,
"QDateTime::setTimeSpec"),
4382 TransitionResolution::LegacyBehavior);
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4401void QDateTime::setOffsetFromUtc(
int offsetSeconds)
4403 reviseTimeZone(d, QTimeZone::fromSecondsAheadOfUtc(offsetSeconds),
4404 TransitionResolution::Reject);
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4428void QDateTime::setTimeZone(
const QTimeZone &toZone, TransitionResolution resolve)
4430 reviseTimeZone(d, toZone, resolve);
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448qint64 QDateTime::toMSecsSinceEpoch()
const
4455 const auto status = getStatus(d);
4456 if (!status.testFlags(QDateTimePrivate::ValidDate | QDateTimePrivate::ValidTime))
4459 switch (extractSpec(status)) {
4463 case Qt::OffsetFromUTC:
4464 Q_ASSERT(!d.isShort());
4465 return d->m_msecs - d->m_offsetFromUtc * MSECS_PER_SEC;
4468 if (status.testFlag(QDateTimePrivate::ShortData)) {
4470 const auto resolve = toTransitionOptions(extractDaylightStatus(getStatus(d)));
4471 const auto state = QDateTimePrivate::localStateAtMillis(getMSecs(d), resolve);
4472 return state.when - state.offset * MSECS_PER_SEC;
4475 return d->m_msecs - d->m_offsetFromUtc * MSECS_PER_SEC;
4478 Q_ASSERT(!d.isShort());
4479#if QT_CONFIG(timezone)
4481 if (d->m_timeZone.isValid())
4482 return d->m_msecs - d->m_offsetFromUtc * MSECS_PER_SEC;
4486 Q_UNREACHABLE_RETURN(0);
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504qint64 QDateTime::toSecsSinceEpoch()
const
4506 return toMSecsSinceEpoch() / MSECS_PER_SEC;
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524void QDateTime::setMSecsSinceEpoch(qint64 msecs)
4526 auto status = getStatus(d);
4527 const auto spec = extractSpec(status);
4528 Q_ASSERT(specCanBeSmall(spec) || !d.isShort());
4529 QDateTimePrivate::ZoneState state(msecs);
4531 status &= ~QDateTimePrivate::ValidityMask;
4532 if (QTimeZone::isUtcOrFixedOffset(spec)) {
4533 if (spec == Qt::OffsetFromUTC)
4534 state.offset = d->m_offsetFromUtc;
4535 if (!state.offset || !qAddOverflow(msecs, state.offset * MSECS_PER_SEC, &state.when))
4536 status |= QDateTimePrivate::ValidityMask;
4537 }
else if (spec == Qt::LocalTime) {
4538 state = QDateTimePrivate::expressUtcAsLocal(msecs);
4540 status = mergeDaylightStatus(status | QDateTimePrivate::ValidityMask, state.dst);
4541#if QT_CONFIG(timezone)
4542 }
else if (spec == Qt::TimeZone && (d.detach(), d->m_timeZone.isValid())) {
4543 const auto data = d->m_timeZone.d->data(msecs);
4544 if (Q_LIKELY(data.offsetFromUtc != QTimeZonePrivate::invalidSeconds())) {
4545 state.offset = data.offsetFromUtc;
4546 Q_ASSERT(state.offset >= -SECS_PER_DAY && state.offset <= SECS_PER_DAY);
4548 || !Q_UNLIKELY(qAddOverflow(msecs, state.offset * MSECS_PER_SEC, &state.when))) {
4549 d->m_status = mergeDaylightStatus(status | QDateTimePrivate::ValidityMask,
4550 data.daylightTimeOffset
4551 ? QDateTimePrivate::DaylightTime
4552 : QDateTimePrivate::StandardTime);
4553 d->m_msecs = state.when;
4554 d->m_offsetFromUtc = state.offset;
4560 Q_ASSERT(!status.testFlag(QDateTimePrivate::ValidDateTime)
4561 || (state.offset >= -SECS_PER_DAY && state.offset <= SECS_PER_DAY));
4563 if (msecsCanBeSmall(state.when) && d.isShort()) {
4565 d.data.msecs = qintptr(state.when);
4566 d.data.status = status.toInt();
4569 d->m_status = status & ~QDateTimePrivate::ShortData;
4570 d->m_msecs = state.when;
4571 d->m_offsetFromUtc = state.offset;
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586void QDateTime::setSecsSinceEpoch(qint64 secs)
4589 if (!qMulOverflow(secs, std::integral_constant<qint64, MSECS_PER_SEC>(), &msecs))
4590 setMSecsSinceEpoch(msecs);
4595#if QT_CONFIG(datestring)
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626QString QDateTime::toString(Qt::DateFormat format)
const
4633 case Qt::RFC2822Date:
4634 buf = QLocale::c().toString(*
this, u"dd MMM yyyy hh:mm:ss ");
4635 buf += toOffsetString(Qt::TextDate, offsetFromUtc());
4638 case Qt::TextDate: {
4639 const std::pair<QDate, QTime> p = getDateTime(d);
4640 buf = toStringTextDate(p.first);
4642 buf.insert(buf.lastIndexOf(u' '),
4643 u' ' + p.second.toString(Qt::TextDate));
4645 switch (timeSpec()) {
4648#if QT_CONFIG(timezone)
4650 buf += u' ' + d->m_timeZone.displayName(
4651 *
this, QTimeZone::OffsetName, QLocale::c());
4660 if (getSpec(d) == Qt::OffsetFromUTC)
4661 buf += toOffsetString(Qt::TextDate, offsetFromUtc());
4666 case Qt::ISODateWithMs: {
4667 const std::pair<QDate, QTime> p = getDateTime(d);
4668 buf = toStringIsoDate(p.first);
4671 buf += u'T' + p.second.toString(format);
4672 switch (getSpec(d)) {
4676 case Qt::OffsetFromUTC:
4678 buf += toOffsetString(Qt::ISODate, offsetFromUtc());
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731QString QDateTime::toString(QStringView format, QCalendar cal)
const
4733 return QLocale::c().toString(*
this, format, cal);
4738
4739
4740
4741QString QDateTime::toString(QStringView format)
const
4743 return QLocale::c().toString(*
this, format, QCalendar());
4747
4748
4749
4750QString QDateTime::toString(
const QString &format)
const
4752 return QLocale::c().toString(*
this, qToStringViewIgnoringNull(format), QCalendar());
4758 const QDateTimePrivate::TransitionOptions resolve = toTransitionOptions(
4759 forward ? QDateTime::TransitionResolution::RelativeToBefore
4760 : QDateTime::TransitionResolution::RelativeToAfter);
4761 auto status = getStatus(d);
4762 Q_ASSERT(status.testFlags(QDateTimePrivate::ValidDate | QDateTimePrivate::ValidTime
4763 | QDateTimePrivate::ValidDateTime));
4764 auto spec = extractSpec(status);
4765 if (QTimeZone::isUtcOrFixedOffset(spec)) {
4766 setDateTime(d, date, time);
4770 qint64 local = timeToMSecs(date, time);
4771 const QDateTimePrivate::ZoneState state = stateAtMillis(d.timeZone(), local, resolve);
4772 Q_ASSERT(state.valid || state.dst == QDateTimePrivate::UnknownDaylightTime);
4773 if (state.dst == QDateTimePrivate::UnknownDaylightTime)
4774 status.setFlag(QDateTimePrivate::ValidDateTime,
false);
4776 status = mergeDaylightStatus(status | QDateTimePrivate::ValidDateTime, state.dst);
4778 if (status & QDateTimePrivate::ShortData) {
4779 d.data.msecs = state.when;
4780 d.data.status = status.toInt();
4783 d->m_status = status;
4785 d->m_msecs = state.when;
4786 d->m_offsetFromUtc = state.offset;
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4806QDateTime QDateTime::addDays(qint64 ndays)
const
4811 QDateTime dt(*
this);
4812 std::pair<QDate, QTime> p = getDateTime(d);
4813 massageAdjustedDateTime(dt.d, p.first.addDays(ndays), p.second, ndays >= 0);
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4832QDateTime QDateTime::addMonths(
int nmonths)
const
4837 QDateTime dt(*
this);
4838 std::pair<QDate, QTime> p = getDateTime(d);
4839 massageAdjustedDateTime(dt.d, p.first.addMonths(nmonths), p.second, nmonths >= 0);
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4858QDateTime QDateTime::addYears(
int nyears)
const
4863 QDateTime dt(*
this);
4864 std::pair<QDate, QTime> p = getDateTime(d);
4865 massageAdjustedDateTime(dt.d, p.first.addYears(nyears), p.second, nyears >= 0);
4870
4871
4872
4873
4874
4875
4876
4877
4879QDateTime QDateTime::addSecs(qint64 s)
const
4882 if (qMulOverflow(s, std::integral_constant<qint64, MSECS_PER_SEC>(), &msecs))
4884 return addMSecs(msecs);
4888
4889
4890
4891
4892
4893
4894
4895
4896QDateTime QDateTime::addMSecs(qint64 msecs)
const
4901 QDateTime dt(*
this);
4902 switch (getSpec(d)) {
4906 if (!qAddOverflow(toMSecsSinceEpoch(), msecs, &msecs))
4907 dt.setMSecsSinceEpoch(msecs);
4912 case Qt::OffsetFromUTC:
4914 if (qAddOverflow(getMSecs(d), msecs, &msecs)) {
4916 }
else if (d.isShort() && msecsCanBeSmall(msecs)) {
4917 dt.d.data.msecs = qintptr(msecs);
4920 dt.d->m_msecs = msecs;
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4963qint64 QDateTime::daysTo(
const QDateTime &other)
const
4965 return date().daysTo(other.date());
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4985qint64 QDateTime::secsTo(
const QDateTime &other)
const
4987 return msecsTo(other) / MSECS_PER_SEC;
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5004qint64 QDateTime::msecsTo(
const QDateTime &other)
const
5006 if (!isValid() || !other.isValid())
5009 return other.toMSecsSinceEpoch() - toMSecsSinceEpoch();
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5081#if QT_DEPRECATED_SINCE(6
, 9
)
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5101QDateTime QDateTime::toTimeSpec(Qt::TimeSpec spec)
const
5103 return toTimeZone(asTimeZone(spec, 0,
"toTimeSpec"));
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5121QDateTime QDateTime::toOffsetFromUtc(
int offsetSeconds)
const
5123 return toTimeZone(QTimeZone::fromSecondsAheadOfUtc(offsetSeconds));
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137QDateTime QDateTime::toLocalTime()
const
5139 return toTimeZone(QTimeZone::LocalTime);
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153QDateTime QDateTime::toUTC()
const
5155 return toTimeZone(QTimeZone::UTC);
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5176QDateTime QDateTime::toTimeZone(
const QTimeZone &timeZone)
const
5178 if (timeRepresentation() == timeZone)
5182 QDateTime ret = *
this;
5183 ret.setTimeZone(timeZone);
5187 return fromMSecsSinceEpoch(toMSecsSinceEpoch(), timeZone);
5191
5192
5193
5194
5195
5196
5198bool QDateTime::equals(
const QDateTime &other)
const
5201 return !other.isValid();
5202 if (!other.isValid())
5205 if (usesSameOffset(d, other.d))
5206 return getMSecs(d) == getMSecs(other.d);
5209 return toMSecsSinceEpoch() == other.toMSecsSinceEpoch();
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5234
5235
5236
5237
5238
5239
5240
5241
5242
5247 return rhs.isValid() ? Qt::weak_ordering::less : Qt::weak_ordering::equivalent;
5250 return Qt::weak_ordering::greater;
5252 if (usesSameOffset(lhs.d, rhs.d))
5253 return Qt::compareThreeWay(getMSecs(lhs.d), getMSecs(rhs.d));
5256 return Qt::compareThreeWay(lhs.toMSecsSinceEpoch(), rhs.toMSecsSinceEpoch());
5260
5261
5262
5263
5264
5265
5266
5267
5268
5271
5272
5273
5274
5275
5276
5277
5278
5279
5282
5283
5284
5285
5286
5287
5288
5289
5292
5293
5294
5295
5296
5297
5298
5299
5300
5303
5304
5305
5306
5307
5308
5309
5310
5313
5314
5315
5316QDateTime QDateTime::currentDateTime()
5318 return currentDateTime(QTimeZone::LocalTime);
5322
5323
5324
5325
5326
5327
5328
5329
5331QDateTime QDateTime::currentDateTimeUtc()
5333 return currentDateTime(QTimeZone::UTC);
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5349
5350
5351
5352
5353
5354
5355
5356
5357
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5384
5385
5386
5387
5388
5389
5390QDateTime QDateTime::fromStdTimePoint(
5391 std::chrono::time_point<
5392 std::chrono::system_clock,
5393 std::chrono::milliseconds
5396 return fromMSecsSinceEpoch(time.time_since_epoch().count(), QTimeZone::UTC);
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5463#if defined(Q_OS_WIN)
5464static inline uint msecsFromDecomposed(
int hour,
int minute,
int sec,
int msec = 0)
5466 return MSECS_PER_HOUR * hour + MSECS_PER_MIN * minute + MSECS_PER_SEC * sec + msec;
5469QDate QDate::currentDate()
5473 return QDate(st.wYear, st.wMonth, st.wDay);
5476QTime QTime::currentTime()
5481 ct.setHMS(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
5485QDateTime QDateTime::currentDateTime(
const QTimeZone &zone)
5489 const Qt::TimeSpec spec = zone.timeSpec();
5493 (spec == Qt::LocalTime ? GetLocalTime : GetSystemTime)(&st);
5494 QDate d(st.wYear, st.wMonth, st.wDay);
5495 QTime t(msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds));
5496 if (spec == Qt::LocalTime)
5497 return QDateTime(d, t);
5498 QDateTime utc(d, t, QTimeZone::UTC);
5499 return spec == Qt::UTC ? utc : utc.toTimeZone(zone);
5502qint64 QDateTime::currentMSecsSinceEpoch()
noexcept
5506 const qint64 daysAfterEpoch = QDate(1970, 1, 1).daysTo(QDate(st.wYear, st.wMonth, st.wDay));
5508 return msecsFromDecomposed(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds) +
5509 daysAfterEpoch * MSECS_PER_DAY;
5512qint64 QDateTime::currentSecsSinceEpoch()
noexcept
5516 const qint64 daysAfterEpoch = QDate(1970, 1, 1).daysTo(QDate(st.wYear, st.wMonth, st.wDay));
5518 return st.wHour * SECS_PER_HOUR + st.wMinute * SECS_PER_MIN + st.wSecond +
5519 daysAfterEpoch * SECS_PER_DAY;
5522#elif defined(Q_OS_UNIX)
5523QDate QDate::currentDate()
5525 return QDateTime::currentDateTime().date();
5528QTime QTime::currentTime()
5530 return QDateTime::currentDateTime().time();
5533QDateTime QDateTime::currentDateTime(
const QTimeZone &zone)
5535 return fromMSecsSinceEpoch(currentMSecsSinceEpoch(), zone);
5538qint64 QDateTime::currentMSecsSinceEpoch()
noexcept
5540 struct timespec when;
5541 if (clock_gettime(CLOCK_REALTIME, &when) == 0)
5542 return when.tv_sec * MSECS_PER_SEC + (when.tv_nsec + 500'000) / 1'000'000;
5543 Q_UNREACHABLE_RETURN(0);
5546qint64 QDateTime::currentSecsSinceEpoch()
noexcept
5548 struct timespec when;
5549 if (clock_gettime(CLOCK_REALTIME, &when) == 0)
5551 Q_UNREACHABLE_RETURN(0);
5554#error "What system is this?"
5557#if QT_DEPRECATED_SINCE(6
, 9
)
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec,
int offsetSeconds)
5583 return fromMSecsSinceEpoch(msecs,
5584 asTimeZone(spec, offsetSeconds,
"QDateTime::fromMSecsSinceEpoch"));
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610QDateTime QDateTime::fromSecsSinceEpoch(qint64 secs, Qt::TimeSpec spec,
int offsetSeconds)
5612 return fromSecsSinceEpoch(secs,
5613 asTimeZone(spec, offsetSeconds,
"QDateTime::fromSecsSinceEpoch"));
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs,
const QTimeZone &timeZone)
5633 reviseTimeZone(dt.d, timeZone, TransitionResolution::Reject);
5634 if (timeZone.isValid())
5635 dt.setMSecsSinceEpoch(msecs);
5640
5641
5642QDateTime QDateTime::fromMSecsSinceEpoch(qint64 msecs)
5644 return fromMSecsSinceEpoch(msecs, QTimeZone::LocalTime);
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660QDateTime QDateTime::fromSecsSinceEpoch(qint64 secs,
const QTimeZone &timeZone)
5663 reviseTimeZone(dt.d, timeZone, TransitionResolution::Reject);
5664 if (timeZone.isValid())
5665 dt.setSecsSinceEpoch(secs);
5670
5671
5672QDateTime QDateTime::fromSecsSinceEpoch(qint64 secs)
5674 return fromSecsSinceEpoch(secs, QTimeZone::LocalTime);
5677#if QT_CONFIG(datestring)
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5692
5693
5694
5695QDateTime QDateTime::fromString(QStringView string, Qt::DateFormat format)
5697 if (string.isEmpty())
5701 case Qt::RFC2822Date: {
5702 const ParsedRfcDateTime rfc = rfcDateImpl(string);
5704 if (!rfc.date.isValid() || !rfc.time.isValid())
5707 QDateTime dateTime(rfc.date, rfc.time, QTimeZone::UTC);
5708 dateTime.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(rfc.utcOffset));
5712 case Qt::ISODateWithMs: {
5713 const int size = string.size();
5717 QDate date = QDate::fromString(string.first(10), Qt::ISODate);
5718 if (!date.isValid())
5721 return date.startOfDay();
5723 QTimeZone zone = QTimeZone::LocalTime;
5724 QStringView isoString = string.sliced(10);
5727 if (isoString.size() < 2
5728 || !(isoString.startsWith(u'T', Qt::CaseInsensitive)
5732 || isoString.startsWith(u' '))) {
5735 isoString = isoString.sliced(1);
5738 if (isoString.endsWith(u'Z', Qt::CaseInsensitive)) {
5739 zone = QTimeZone::UTC;
5744 int signIndex = isoString.size() - 1;
5745 Q_ASSERT(signIndex >= 0);
5748 QChar character(isoString[signIndex]);
5749 found = character == u'+' || character == u'-';
5750 }
while (!found && --signIndex >= 0);
5754 int offset = fromOffsetString(isoString.sliced(signIndex), &ok);
5757 isoString = isoString.first(signIndex);
5758 zone = QTimeZone::fromSecondsAheadOfUtc(offset);
5764 bool isMidnight24 =
false;
5765 QTime time = fromIsoTimeString(isoString, format, &isMidnight24);
5766 if (!time.isValid())
5769 return date.addDays(1).startOfDay(zone);
5770 return QDateTime(date, time, zone);
5772 case Qt::TextDate: {
5773 QVarLengthArray<QStringView, 6> parts;
5775 auto tokens = string.tokenize(u' ', Qt::SkipEmptyParts);
5776 auto it = tokens.begin();
5777 for (
int i = 0; i < 6 && it != tokens.end(); ++i, ++it)
5778 parts.emplace_back(*it);
5782 if (parts.size() < 5 || it != tokens.end())
5789 if (parts.at(3).contains(u':'))
5791 else if (parts.at(4).contains(u':'))
5797 int day = parts.at(2).toInt(&ok);
5798 int year = ok ? parts.at(yearPart).toInt(&ok) : 0;
5799 int month = fromShortMonthName(parts.at(1));
5800 if (!ok || year == 0 || day == 0 || month < 1)
5803 const QDate date(year, month, day);
5804 if (!date.isValid())
5807 const QTime time = fromIsoTimeString(parts.at(timePart), format,
nullptr);
5808 if (!time.isValid())
5811 if (parts.size() == 5)
5812 return QDateTime(date, time);
5814 QStringView tz = parts.at(5);
5815 if (tz.startsWith(
"UTC"_L1)
5817 || tz.startsWith(
"GMT"_L1, Qt::CaseInsensitive)) {
5820 return QDateTime(date, time, QTimeZone::UTC);
5822 int offset = fromOffsetString(tz, &ok);
5823 return ok ? QDateTime(date, time, QTimeZone::fromSecondsAheadOfUtc(offset))
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5916
5917
5918
5919
5922
5923
5924
5925QDateTime QDateTime::fromString(
const QString &string, QStringView format,
int baseYear,
5928#if QT_CONFIG(datetimeparser)
5931 QDateTimeParser dt(QMetaType::QDateTime, QDateTimeParser::FromString, cal);
5932 dt.setDefaultLocale(QLocale::c());
5933 if (dt.parseFormat(format) && (dt.fromString(string, &datetime, baseYear)
5934 || !datetime.isValid())) {
5947
5948
5949
5950
5953
5954
5955
5956
5959
5960
5961
5962
5965
5966
5967
5968
5969
5970
5973
5974
5975
5976
5977
5978QDateTime QDateTime::fromString(
const QString &string, QStringView format,
int baseYear)
5980 return fromString(string, format, baseYear, QCalendar());
5984
5985
5986
5987
5988
5989
5993
5994
5996#ifndef QT_NO_DATASTREAM
5998
5999
6000
6001
6002
6003
6005QDataStream &operator<<(QDataStream &out, QDate date)
6007 if (out.version() < QDataStream::Qt_5_0)
6008 return out << quint32(date.jd);
6010 return out << date.jd;
6014
6015
6016
6017
6018
6019
6021QDataStream &operator>>(QDataStream &in, QDate &date)
6023 if (in.version() < QDataStream::Qt_5_0) {
6027 date.jd = (jd != 0 ? jd : QDate::nullJd());
6036
6037
6038
6039
6040
6041
6043QDataStream &operator<<(QDataStream &out, QTime time)
6045 if (out.version() >= QDataStream::Qt_4_0) {
6046 return out << quint32(time.mds);
6049 return out << quint32(time.isNull() ? 0 : time.mds);
6054
6055
6056
6057
6058
6059
6061QDataStream &operator>>(QDataStream &in, QTime &time)
6065 if (in.version() >= QDataStream::Qt_4_0) {
6069 time.mds = (ds == 0) ? QTime::NullTime :
int(ds);
6075
6076
6077
6078
6079
6080
6081QDataStream &operator<<(QDataStream &out,
const QDateTime &dateTime)
6083 std::pair<QDate, QTime> dateAndTime;
6086 if (out.version() >= QDataStream::Qt_5_2) {
6089 dateAndTime = getDateTime(dateTime.d);
6090 out << dateAndTime << qint8(dateTime.timeSpec());
6091 if (dateTime.timeSpec() == Qt::OffsetFromUTC)
6092 out << qint32(dateTime.offsetFromUtc());
6093#if QT_CONFIG(timezone)
6094 else if (dateTime.timeSpec() == Qt::TimeZone)
6095 out << dateTime.timeZone();
6098 }
else if (out.version() == QDataStream::Qt_5_0) {
6104 dateAndTime = getDateTime((dateTime.isValid() ? dateTime.toUTC() : dateTime).d);
6105 out << dateAndTime << qint8(dateTime.timeSpec());
6107 }
else if (out.version() >= QDataStream::Qt_4_0) {
6110 dateAndTime = getDateTime(dateTime.d);
6112 switch (dateTime.timeSpec()) {
6114 out << (qint8)QDateTimePrivate::UTC;
6116 case Qt::OffsetFromUTC:
6117 out << (qint8)QDateTimePrivate::OffsetFromUTC;
6120 out << (qint8)QDateTimePrivate::TimeZone;
6123 out << (qint8)QDateTimePrivate::LocalUnknown;
6130 dateAndTime = getDateTime(dateTime.d);
6139
6140
6141
6142
6143
6144
6146QDataStream &operator>>(QDataStream &in, QDateTime &dateTime)
6151 QTimeZone zone(QTimeZone::LocalTime);
6153 if (in.version() >= QDataStream::Qt_5_2) {
6156 in >> dt >> tm >> ts;
6157 switch (
static_cast<Qt::TimeSpec>(ts)) {
6159 zone = QTimeZone::UTC;
6161 case Qt::OffsetFromUTC: {
6164 zone = QTimeZone::fromSecondsAheadOfUtc(offset);
6174 dateTime = QDateTime(dt, tm, zone);
6176 }
else if (in.version() == QDataStream::Qt_5_0) {
6179 in >> dt >> tm >> ts;
6180 dateTime = QDateTime(dt, tm, QTimeZone::UTC);
6181 if (
static_cast<Qt::TimeSpec>(ts) == Qt::LocalTime)
6182 dateTime = dateTime.toTimeZone(zone);
6184 }
else if (in.version() >= QDataStream::Qt_4_0) {
6187 in >> dt >> tm >> ts;
6188 switch (
static_cast<QDateTimePrivate::Spec>(ts)) {
6189 case QDateTimePrivate::OffsetFromUTC:
6190 case QDateTimePrivate::UTC:
6191 zone = QTimeZone::UTC;
6193 case QDateTimePrivate::TimeZone:
6194 case QDateTimePrivate::LocalUnknown:
6195 case QDateTimePrivate::LocalStandard:
6196 case QDateTimePrivate::LocalDST:
6199 dateTime = QDateTime(dt, tm, zone);
6205 dateTime = QDateTime(dt, tm);
6214
6215
6217#if !defined(QT_NO_DEBUG_STREAM) && QT_CONFIG(datestring)
6218QDebug operator<<(QDebug dbg, QDate date)
6220 QDebugStateSaver saver(dbg);
6221 dbg.nospace() <<
"QDate(";
6224 if (
int y = date.year(); y > 0 && y <= 9999)
6225 dbg.nospace() << date.toString(Qt::ISODate);
6227 dbg.nospace() << date.toString(Qt::TextDate);
6229 dbg.nospace() <<
"Invalid";
6230 dbg.nospace() <<
')';
6234QDebug operator<<(QDebug dbg, QTime time)
6236 QDebugStateSaver saver(dbg);
6237 dbg.nospace() <<
"QTime(";
6239 dbg.nospace() << time.toString(u"HH:mm:ss.zzz");
6241 dbg.nospace() <<
"Invalid";
6242 dbg.nospace() <<
')';
6246QDebug operator<<(QDebug dbg,
const QDateTime &date)
6248 QDebugStateSaver saver(dbg);
6249 dbg.nospace() <<
"QDateTime(";
6250 if (date.isValid()) {
6251 const Qt::TimeSpec ts = date.timeSpec();
6252 dbg.noquote() << date.toString(u"yyyy-MM-dd HH:mm:ss.zzz t")
6257 case Qt::OffsetFromUTC:
6258 dbg.space() << date.offsetFromUtc() <<
's';
6261#if QT_CONFIG(timezone)
6262 dbg.space() << date.timeZone().id();
6269 dbg.nospace() <<
"Invalid";
6271 return dbg.nospace() <<
')';
6276
6277
6278
6279
6280
6287 return key.isValid() ? qHash(key.toMSecsSinceEpoch(), seed) : seed;
6291
6292
6293
6294
6295
6298 return qHash(key.toJulianDay(), seed);
6302
6303
6304
6305
6306
6309 return qHash(key.msecsSinceStartOfDay(), seed);
size_t qHash(QTime key, size_t seed) noexcept
static QTime msecsToTime(qint64 msecs)
static auto millisToWithinRange(qint64 millis)
static QDateTime toLatest(QDate day, const QTimeZone &zone)
static constexpr QDateTimePrivate::StatusFlags mergeDaylightStatus(QDateTimePrivate::StatusFlags sf, QDateTimePrivate::DaylightStatus status)
static QDate fixedDate(QCalendar::YearMonthDay parts)
static qint64 timeToMSecs(QDate date, QTime time)
static std::pair< QDate, QTime > getDateTime(const QDateTimeData &d)
static constexpr QDateTimePrivate::DaylightStatus extractDaylightStatus(QDateTimePrivate::StatusFlags status)
size_t qHash(const QDateTime &key, size_t seed)
static Qt::TimeSpec getSpec(const QDateTimeData &d)
QDateTimePrivate::QDateTimeShortData ShortData
static void reviseTimeZone(QDateTimeData &d, const QTimeZone &zone, QDateTime::TransitionResolution resolve)
static QDateTimePrivate::StatusFlags getStatus(const QDateTimeData &d)
static qint64 getMSecs(const QDateTimeData &d)
static void massageAdjustedDateTime(QDateTimeData &d, QDate date, QTime time, bool forward)
static bool inDateTimeRange(qint64 jd, DaySide side)
QDateTimePrivate::QDateTimeData QDateTimeData
static bool specCanBeSmall(Qt::TimeSpec spec)
static int systemTimeYearMatching(int year)
static constexpr QDateTimePrivate::StatusFlags mergeSpec(QDateTimePrivate::StatusFlags status, Qt::TimeSpec spec)
static QDate msecsToDate(qint64 msecs)
static QString toOffsetString(Qt::DateFormat format, int offset)
size_t qHash(QDate key, size_t seed) noexcept
static bool daysAndMillisOverflow(qint64 days, qint64 millisInDay, qint64 *sumMillis)
static QDate fixedDate(QCalendar::YearMonthDay parts, QCalendar cal)
static constexpr QDateTimePrivate::TransitionOptions toTransitionOptions(QDateTime::TransitionResolution res)
static void refreshSimpleDateTime(QDateTimeData &d)
static void setDateTime(QDateTimeData &d, QDate date, QTime time)
static void refreshZonedDateTime(QDateTimeData &d, const QTimeZone &zone, QDateTimePrivate::TransitionOptions resolve)
static bool msecsCanBeSmall(qint64 msecs)
static constexpr Qt::TimeSpec extractSpec(QDateTimePrivate::StatusFlags status)
static bool usesSameOffset(const QDateTimeData &a, const QDateTimeData &b)
static void checkValidDateTime(QDateTimeData &d, QDateTime::TransitionResolution resolve)
Qt::weak_ordering compareThreeWay(const QDateTime &lhs, const QDateTime &rhs)
static QDateTime toEarliest(QDate day, const QTimeZone &zone)
static QDateTimePrivate::ZoneState stateAtMillis(const QTimeZone &zone, qint64 millis, QDateTimePrivate::TransitionOptions resolve)
static bool millisInSystemRange(qint64 millis, qint64 slack=0)
static qint64 msecsToJulianDay(qint64 msecs)