src/corelib/tools/qdatetime.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
--- a/src/corelib/tools/qdatetime.cpp	Tue Jul 06 15:10:48 2010 +0300
+++ b/src/corelib/tools/qdatetime.cpp	Wed Aug 18 10:37:55 2010 +0300
@@ -1843,7 +1843,7 @@
             const QString msec_s(QLatin1String("0.") + s.mid(9, 4));
             const float msec(msec_s.toFloat(&ok));
             if (!ok)
-                return QTime();
+                return QTime(hour, minute, second, 0);
             return QTime(hour, minute, second, qMin(qRound(msec * 1000.0), 999));
         }
     }
@@ -2385,7 +2385,7 @@
 /*!
     \since 4.7
 
-    Sets the date and time given the number of \a mulliseconds that have
+    Sets the date and time given the number of milliseconds,\a msecs, that have
     passed since 1970-01-01T00:00:00.000, Coordinated Universal Time
     (Qt::UTC). On systems that do not support time zones this function
     will behave as if local time were Qt::UTC.
@@ -3188,7 +3188,7 @@
 /*!
   \since 4.7
 
-  Returns a datetime whose date and time are the number of milliseconds \a msec
+  Returns a datetime whose date and time are the number of milliseconds, \a msecs,
   that have passed since 1970-01-01T00:00:00.000, Coordinated Universal
   Time (Qt::UTC). On systems that do not support time zones, the time
   will be set as if local time were Qt::UTC.
@@ -3304,12 +3304,37 @@
         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: