diff options
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 31 | ||||
-rw-r--r-- | src/corelib/time/qdatetimeparser.cpp | 5 | ||||
-rw-r--r-- | tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 12 |
3 files changed, 33 insertions, 15 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 418466033d..ca1dac0cb4 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -1929,12 +1929,15 @@ QString QTime::toString(Qt::DateFormat format) const \row \li ss \li The whole second, with a leading zero where applicable (00 to 59) \row \li z or zz \li The fractional part of the second, to go after a decimal point, - without trailing zeroes. Thus "\c{s.z}" reports the seconds to - full available (millisecond) precision without trailing zeroes (0 - to 999). + without trailing zeroes. Thus \c{"s.z"} reports the seconds to full + available (millisecond) precision without trailing zeroes (0 to + 999). For example, \c{"s.z"} would produce \c{"0.25"} for a time a + quarter second into a minute. \row \li zzz \li The fractional part of the second, to millisecond precision, - including trailing zeroes where applicable (000 to 999). + including trailing zeroes where applicable (000 to 999). For + example, \c{"ss.zzz"} would produce \c{"00.250"} for a time a + quarter second into a minute. \row \li AP or A \li Use AM/PM display. \c A/AP will be replaced by 'AM' or 'PM'. In localized forms (only relevant to \l{QLocale::toString()}), the @@ -2332,12 +2335,20 @@ QTime QTime::fromString(QStringView string, Qt::DateFormat format) \row \li mm \li The minute with a leading zero (00 to 59) \row \li s \li The whole second, without any leading zero (0 to 59) \row \li ss \li The whole second, with a leading zero where applicable (00 to 59) - \row \li z \li The fractional part of the second, to go after a decimal - point, without trailing zeroes (0 to 999). Thus "\c{s.z}" - reports the seconds to full available (millisecond) precision - without trailing zeroes. - \row \li zzz \li The fractional part of the second, to millisecond - precision, including trailing zeroes where applicable (000 to 999). + \row \li z or zz + \li The fractional part of the second, as would usually follow a + decimal point, without requiring trailing zeroes (0 to 999). Thus + \c{"s.z"} matches the seconds with up to three digits of fractional + part supplying millisecond precision, without needing trailing + zeroes. For example, \c{"s.z"} would recognize either \c{"00.250"} + or \c{"0.25"} as representing a time a quarter second into its + minute. + \row \li zzz + \li Three digit fractional part of the second, to millisecond + precision, including trailing zeroes where applicable (000 to 999). + For example, \c{"ss.zzz"} would reject \c{"0.25"} but recognize + \c{"00.250"} as representing a time a quarter second into its + minute. \row \li AP, A, ap, a, aP or Ap \li Either 'AM' indicating a time before 12:00 or 'PM' for later times, matched case-insensitively. diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 49dad1e6fc..54b0c251b0 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -501,10 +501,11 @@ bool QDateTimeParser::parseFormat(QStringView newFormat) case 'z': if (parserType != QMetaType::QDate) { - const SectionNode sn = { MSecSection, i - add, countRepeat(newFormat, i, 3) < 3 ? 1 : 3, 0 }; + const int repeat = countRepeat(newFormat, i, 3); + const SectionNode sn = { MSecSection, i - add, repeat < 3 ? 1 : 3, 0 }; newSectionNodes.append(sn); appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); - i += sn.count - 1; + i += repeat - 1; index = i + 1; newDisplay |= MSecSection; } diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 17e59a2c18..a527b328e9 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2752,9 +2752,15 @@ void tst_QDateTime::fromStringStringFormat_data() QTest::newRow("data15") << QString("Thu January 2004") << QString("ddd MMMM yyyy") << QDate(2004, 1, 1).startOfDay(); - QTest::newRow("data16") << QString("2005-06-28T07:57:30.001Z") - << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1), Qt::UTC); + QTest::newRow("zulu-time-with-z-centisec") + << QString("2005-06-28T07:57:30.01Z") << QString("yyyy-MM-ddThh:mm:ss.zt") + << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 10), Qt::UTC); + QTest::newRow("zulu-time-with-zz-decisec") + << QString("2005-06-28T07:57:30.1Z") << QString("yyyy-MM-ddThh:mm:ss.zzt") + << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 100), Qt::UTC); + QTest::newRow("zulu-time-with-zzz-centisec") + << QString("2005-06-28T07:57:30.01Z") << QString("yyyy-MM-ddThh:mm:ss.zzzt") + << QDateTime(); // Invalid because too few digits for zzz QTest::newRow("utc-time-spec-as:UTC+0") << QString("2005-06-28T07:57:30.001UTC+0") << QString("yyyy-MM-ddThh:mm:ss.zt") << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); |