1841 if (!ok) |
1841 if (!ok) |
1842 return QTime(); |
1842 return QTime(); |
1843 const QString msec_s(QLatin1String("0.") + s.mid(9, 4)); |
1843 const QString msec_s(QLatin1String("0.") + s.mid(9, 4)); |
1844 const float msec(msec_s.toFloat(&ok)); |
1844 const float msec(msec_s.toFloat(&ok)); |
1845 if (!ok) |
1845 if (!ok) |
1846 return QTime(); |
1846 return QTime(hour, minute, second, 0); |
1847 return QTime(hour, minute, second, qMin(qRound(msec * 1000.0), 999)); |
1847 return QTime(hour, minute, second, qMin(qRound(msec * 1000.0), 999)); |
1848 } |
1848 } |
1849 } |
1849 } |
1850 } |
1850 } |
1851 |
1851 |
2383 } |
2383 } |
2384 |
2384 |
2385 /*! |
2385 /*! |
2386 \since 4.7 |
2386 \since 4.7 |
2387 |
2387 |
2388 Sets the date and time given the number of \a mulliseconds that have |
2388 Sets the date and time given the number of milliseconds,\a msecs, that have |
2389 passed since 1970-01-01T00:00:00.000, Coordinated Universal Time |
2389 passed since 1970-01-01T00:00:00.000, Coordinated Universal Time |
2390 (Qt::UTC). On systems that do not support time zones this function |
2390 (Qt::UTC). On systems that do not support time zones this function |
2391 will behave as if local time were Qt::UTC. |
2391 will behave as if local time were Qt::UTC. |
2392 |
2392 |
2393 Note that there are possible values for \a msecs that lie outside the |
2393 Note that there are possible values for \a msecs that lie outside the |
3186 } |
3186 } |
3187 |
3187 |
3188 /*! |
3188 /*! |
3189 \since 4.7 |
3189 \since 4.7 |
3190 |
3190 |
3191 Returns a datetime whose date and time are the number of milliseconds \a msec |
3191 Returns a datetime whose date and time are the number of milliseconds, \a msecs, |
3192 that have passed since 1970-01-01T00:00:00.000, Coordinated Universal |
3192 that have passed since 1970-01-01T00:00:00.000, Coordinated Universal |
3193 Time (Qt::UTC). On systems that do not support time zones, the time |
3193 Time (Qt::UTC). On systems that do not support time zones, the time |
3194 will be set as if local time were Qt::UTC. |
3194 will be set as if local time were Qt::UTC. |
3195 |
3195 |
3196 Note that there are possible values for \a msecs that lie outside the valid |
3196 Note that there are possible values for \a msecs that lie outside the valid |
3302 Qt::TimeSpec ts = Qt::LocalTime; |
3302 Qt::TimeSpec ts = Qt::LocalTime; |
3303 const QDate date = QDate::fromString(tmp.left(10), Qt::ISODate); |
3303 const QDate date = QDate::fromString(tmp.left(10), Qt::ISODate); |
3304 if (tmp.size() == 10) |
3304 if (tmp.size() == 10) |
3305 return QDateTime(date); |
3305 return QDateTime(date); |
3306 |
3306 |
|
3307 tmp = tmp.mid(11); |
|
3308 |
3307 // Recognize UTC specifications |
3309 // Recognize UTC specifications |
3308 if (tmp.endsWith(QLatin1Char('Z'))) { |
3310 if (tmp.endsWith(QLatin1Char('Z'))) { |
3309 ts = Qt::UTC; |
3311 ts = Qt::UTC; |
3310 tmp.chop(1); |
3312 tmp.chop(1); |
3311 } |
3313 } |
3312 return QDateTime(date, QTime::fromString(tmp.mid(11), Qt::ISODate), ts); |
3314 |
|
3315 // Recognize timezone specifications |
|
3316 QRegExp rx(QLatin1String("[+-]")); |
|
3317 if (tmp.contains(rx)) { |
|
3318 int idx = tmp.indexOf(rx); |
|
3319 QString tmp2 = tmp.mid(idx); |
|
3320 tmp = tmp.left(idx); |
|
3321 bool ok = true; |
|
3322 int ntzhour = 1; |
|
3323 int ntzminute = 3; |
|
3324 if ( tmp2.indexOf(QLatin1Char(':')) == 3 ) |
|
3325 ntzminute = 4; |
|
3326 const int tzhour(tmp2.mid(ntzhour, 2).toInt(&ok)); |
|
3327 const int tzminute(tmp2.mid(ntzminute, 2).toInt(&ok)); |
|
3328 QTime tzt(tzhour, tzminute); |
|
3329 int utcOffset = (tzt.hour() * 60 + tzt.minute()) * 60; |
|
3330 if ( utcOffset != 0 ) { |
|
3331 ts = Qt::OffsetFromUTC; |
|
3332 QDateTime dt(date, QTime::fromString(tmp, Qt::ISODate), ts); |
|
3333 dt.setUtcOffset( utcOffset * (tmp2.startsWith(QLatin1Char('-')) ? -1 : 1) ); |
|
3334 return dt; |
|
3335 } |
|
3336 } |
|
3337 return QDateTime(date, QTime::fromString(tmp, Qt::ISODate), ts); |
3313 } |
3338 } |
3314 case Qt::SystemLocaleDate: |
3339 case Qt::SystemLocaleDate: |
3315 case Qt::SystemLocaleShortDate: |
3340 case Qt::SystemLocaleShortDate: |
3316 case Qt::SystemLocaleLongDate: |
3341 case Qt::SystemLocaleLongDate: |
3317 return fromString(s, QLocale::system().dateTimeFormat(f == Qt::SystemLocaleLongDate ? QLocale::LongFormat |
3342 return fromString(s, QLocale::system().dateTimeFormat(f == Qt::SystemLocaleLongDate ? QLocale::LongFormat |