Results 1 to 2 of 2

Thread: QDateTime ISODate parses not as expected

  1. #1
    Join Date
    Sep 2009
    Location
    Kraków, Poland
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default QDateTime ISODate parses not as expected

    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):
    Qt Code:
    1. QString datetime1("2010-08-06T18:34:14.3+02:00");
    2. QString datetime2("2010-08-06T18:34:14.386+02:00");
    3. QString datetime3("2010-08-06T18:34:14.386625+02:00");
    4. qDebug() << datetime1;
    5. qDebug() << datetime2;
    6. qDebug() << datetime3;
    7. QDateTime datetime11 = QDateTime::fromString(datetime1, Qt::ISODate);
    8. QDateTime datetime22 = QDateTime::fromString(datetime2, Qt::ISODate);
    9. QDateTime datetime33 = QDateTime::fromString(datetime3, Qt::ISODate);
    10. qDebug() << datetime11.toString(Qt::ISODate);
    11. qDebug() << datetime22.toString(Qt::ISODate);
    12. qDebug() << datetime33.toString(Qt::ISODate);
    To copy to clipboard, switch view to plain text mode 
    generates this output:
    Qt Code:
    1. "2010-08-06T18:34:14.3+02:00"
    2. "2010-08-06T18:34:14.386+02:00"
    3. "2010-08-06T18:34:14.386625+02:00"
    4. "2010-08-06T00:00:00"
    5. "2010-08-06T00:00:00"
    6. "2010-08-06T18:34:14"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QDateTime ISODate parses not as expected

    A bug report (link) has been filed and marked as closed. Not sure what the partial solution is.

    The problem is the "+". From qdatetime.cpp:
    Qt Code:
    1. QTime QTime::fromString(const QString& s, Qt::DateFormat f)
    2. {
    3. . . .
    4. const QString msec_s(QLatin1String("0.") + s.mid(9, 4));
    5. const float msec(msec_s.toFloat(&ok));
    6. if (!ok)
    7. return QTime();
    8. . . .
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to norobro for this useful post:

    JacquesBaniaque (6th August 2010)

Similar Threads

  1. QXmlStreamReader parses XML in weird order
    By Zeddy in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2010, 09:57
  2. QDateTime problem
    By Majdi in forum Newbie
    Replies: 11
    Last Post: 28th January 2009, 15:57
  3. Replies: 2
    Last Post: 7th July 2008, 08:44
  4. QDateTime fromString
    By mklieber in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2008, 21:15
  5. QDateTime without Day
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2006, 11:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.