PDA

View Full Version : QDateTime ISODate parses not as expected



JacquesBaniaque
6th August 2010, 15:57
I have encountered a strange parsing issue.
It looks like when there are fractions of a second present there have to be at least 4 digits after '.' or else time will be parsed as 00:00:00.
Also issue does NOT show when we remove timezone part
I don't know much about ISO 8601 standard much but as i was able to check on wiki all strings are correct with the standard. So is it a bug or ... ?

This code (Qt 4.6.3, tried on desktop and Simulator):


QString datetime1("2010-08-06T18:34:14.3+02:00");
QString datetime2("2010-08-06T18:34:14.386+02:00");
QString datetime3("2010-08-06T18:34:14.386625+02:00");
qDebug() << datetime1;
qDebug() << datetime2;
qDebug() << datetime3;
QDateTime datetime11 = QDateTime::fromString(datetime1, Qt::ISODate);
QDateTime datetime22 = QDateTime::fromString(datetime2, Qt::ISODate);
QDateTime datetime33 = QDateTime::fromString(datetime3, Qt::ISODate);
qDebug() << datetime11.toString(Qt::ISODate);
qDebug() << datetime22.toString(Qt::ISODate);
qDebug() << datetime33.toString(Qt::ISODate);

generates this output:


"2010-08-06T18:34:14.3+02:00"
"2010-08-06T18:34:14.386+02:00"
"2010-08-06T18:34:14.386625+02:00"
"2010-08-06T00:00:00"
"2010-08-06T00:00:00"
"2010-08-06T18:34:14"

norobro
6th August 2010, 18:26
A bug report (link (http://bugreports.qt.nokia.com/browse/QTBUG-11623)) has been filed and marked as closed. Not sure what the partial solution is.

The problem is the "+". From qdatetime.cpp:
QTime QTime::fromString(const QString& s, Qt::DateFormat f)
{
. . .
const QString msec_s(QLatin1String("0.") + s.mid(9, 4));
const float msec(msec_s.toFloat(&ok));
if (!ok)
return QTime();
. . .