From 047e0e5118584149d0c6b1840644d902cfe548ef Mon Sep 17 00:00:00 2001 From: David Fries Date: Sun, 23 Jul 2017 19:56:55 -0500 Subject: Docs: Fix day/year format in QDateTime QDateTime takes dd and yyyy. It is confusing when the example format strings don't work because they use DD YYYY, and it is a silent error with the characters not getting substituted and can be easy to miss. Improved Qt::ISODate, TZD isn't a format character so skip writing out a bad format example. Task-number: QTBUG-62111 Change-Id: Ia61d561074ae885fc0a99238d93cb34aaa9953bb Reviewed-by: David Fries Reviewed-by: Edward Welbourne --- src/corelib/global/qnamespace.qdoc | 5 +++-- src/corelib/tools/qdatetime.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 076b006235..4ddb89014e 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -672,8 +672,9 @@ be short, localized names. This is basically equivalent to using the date format string, "ddd MMM d yyyy". See QDate::toString() for more information. - \value ISODate \l{ISO 8601} extended format: either \c{YYYY-MM-DD} for dates or - \c{YYYY-MM-DDTHH:mm:ss}, \c{YYYY-MM-DDTHH:mm:ssTZD} (e.g., 1997-07-16T19:20:30+01:00) + \value ISODate \l{ISO 8601} extended format: either \c{yyyy-MM-dd} for dates or + \c{yyyy-MM-ddTHH:mm:ss} (e.g. 2017-07-24T15:46:29), or with a time-zone + suffix (Z for UTC otherwise an offset as [+|-]HH:mm) where appropriate for combined dates and times. \value ISODateWithMs \l{ISO 8601} extended format, including milliseconds if applicable. diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 88270643d9..b6bec9b376 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -211,7 +211,7 @@ static ParsedRfcDateTime rfcDateImpl(const QString &s) { ParsedRfcDateTime result; - // Matches "Wdy, DD Mon YYYY HH:mm:ss ±hhmm" (Wdy, being optional) + // Matches "Wdy, dd Mon yyyy HH:mm:ss ±hhmm" (Wdy, being optional) 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))?")); if (s.indexOf(rex) == 0) { const QStringList cap = rex.capturedTexts(); @@ -223,7 +223,7 @@ static ParsedRfcDateTime rfcDateImpl(const QString &s) const int minOffset = cap[9].toInt(); result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); } else { - // Matches "Wdy Mon DD HH:mm:ss YYYY" + // Matches "Wdy Mon dd HH:mm:ss yyyy" 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))?")); if (s.indexOf(rex) == 0) { const QStringList cap = rex.capturedTexts(); @@ -810,8 +810,8 @@ static QString toStringIsoDate(qint64 jd) If the \a format is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of - dates and times, taking the form YYYY-MM-DD, where YYYY is the - year, MM is the month of the year (between 01 and 12), and DD is + dates and times, taking the form yyyy-MM-dd, where yyyy is the + year, MM is the month of the year (between 01 and 12), and dd is the day of the month between 01 and 31. If the \a format is Qt::SystemLocaleShortDate or @@ -3785,13 +3785,13 @@ void QDateTime::setTime_t(uint secsSince1Jan1970UTC) If the \a format is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of - dates and times, taking the form YYYY-MM-DDTHH:mm:ss[Z|[+|-]HH:mm], + dates and times, taking the form yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm], depending on the timeSpec() of the QDateTime. If the timeSpec() is Qt::UTC, Z will be appended to the string; if the timeSpec() is Qt::OffsetFromUTC, the offset in hours and minutes from UTC will be appended to the string. To include milliseconds in the ISO 8601 date, use the \a format Qt::ISODateWithMs, which corresponds to - YYYY-MM-DDTHH:mm:ss.zzz[Z|[+|-]HH:mm]. + yyyy-MM-ddTHH:mm:ss.zzz[Z|[+|-]HH:mm]. If the \a format is Qt::SystemLocaleShortDate or Qt::SystemLocaleLongDate, the string format depends on the locale -- cgit v1.2.3