diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-07-05 19:16:53 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-07-05 19:16:53 (GMT) |
commit | 6f1b1f4e5eb6666ed25f770ded1a721b5d1e4907 (patch) | |
tree | 9700668d9f8c787835e5c90f040748ae0e9520d0 | |
parent | d4bed7dac60406fb98cc6c2b67689db153a56abf (diff) | |
parent | fa650284ad6a838118946be88ac9c73a83361391 (diff) | |
download | Qt-6f1b1f4e5eb6666ed25f770ded1a721b5d1e4907.zip Qt-6f1b1f4e5eb6666ed25f770ded1a721b5d1e4907.tar.gz Qt-6f1b1f4e5eb6666ed25f770ded1a721b5d1e4907.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-s60-public into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-s60-public:
Support time zone designator in QDateTime::fromString() based on ISO 8601-2004 standard.
-rw-r--r-- | doc/src/external-resources.qdoc | 7 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 5 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qdatetime/tst_qdatetime.cpp | 6 |
4 files changed, 41 insertions, 4 deletions
diff --git a/doc/src/external-resources.qdoc b/doc/src/external-resources.qdoc index d4dc2b1..cbd66ee 100644 --- a/doc/src/external-resources.qdoc +++ b/doc/src/external-resources.qdoc @@ -410,6 +410,11 @@ */ /*! + \externalpage http://www.iso.org/iso/date_and_time_format + \title ISO 8601 +*/ + +/*! \externalpage http://opensource.org/licenses/bsd-license.php \title New and Modified BSD Licenses -*/ +*/
\ No newline at end of file diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index d419759..ed2ae6e 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -565,8 +565,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 ISO 8601 extended format: either \c{YYYY-MM-DD} for dates or - \c{YYYY-MM-DDTHH:MM:SS} for combined dates and times. + \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) + for combined dates and times. \value SystemLocaleShortDate The \l{QLocale::ShortFormat}{short format} used by the \l{QLocale::system()}{operating system}. diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 5edb364..ab7530d 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3304,12 +3304,37 @@ QDateTime QDateTime::fromString(const QString& s, Qt::DateFormat f) if (tmp.size() == 10) return QDateTime(date); + tmp = tmp.mid(11); + // Recognize UTC specifications if (tmp.endsWith(QLatin1Char('Z'))) { ts = Qt::UTC; tmp.chop(1); } - return QDateTime(date, QTime::fromString(tmp.mid(11), Qt::ISODate), ts); + + // Recognize timezone specifications + QRegExp rx(QLatin1String("[+-]")); + if (tmp.contains(rx)) { + int idx = tmp.indexOf(rx); + QString tmp2 = tmp.mid(idx); + tmp = tmp.left(idx); + bool ok = true; + int ntzhour = 1; + int ntzminute = 3; + if ( tmp2.indexOf(QLatin1Char(':')) == 3 ) + ntzminute = 4; + const int tzhour(tmp2.mid(ntzhour, 2).toInt(&ok)); + const int tzminute(tmp2.mid(ntzminute, 2).toInt(&ok)); + QTime tzt(tzhour, tzminute); + int utcOffset = (tzt.hour() * 60 + tzt.minute()) * 60; + if ( utcOffset != 0 ) { + ts = Qt::OffsetFromUTC; + QDateTime dt(date, QTime::fromString(tmp, Qt::ISODate), ts); + dt.setUtcOffset( utcOffset * (tmp2.startsWith(QLatin1Char('-')) ? -1 : 1) ); + return dt; + } + } + return QDateTime(date, QTime::fromString(tmp, Qt::ISODate), ts); } case Qt::SystemLocaleDate: case Qt::SystemLocaleShortDate: diff --git a/tests/auto/qdatetime/tst_qdatetime.cpp b/tests/auto/qdatetime/tst_qdatetime.cpp index 47c54a5..0900b35 100644 --- a/tests/auto/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/qdatetime/tst_qdatetime.cpp @@ -1456,6 +1456,12 @@ void tst_QDateTime::fromString() dt = QDateTime::fromString("2002-10-01", Qt::ISODate); QCOMPARE(dt, QDateTime(QDate(2002, 10, 1), QTime(0, 0, 0, 0))); + dt = QDateTime::fromString("1987-02-13T13:24:51+01:00", Qt::ISODate); + QCOMPARE(dt, QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC)); + + dt = QDateTime::fromString("1987-02-13T13:24:51-01:00", Qt::ISODate); + QCOMPARE(dt, QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC)); + dt = QDateTime::fromString("Thu Jan 1 00:12:34 1970 GMT"); QCOMPARE(dt.toUTC(), QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC)); |