Results 1 to 4 of 4

Thread: Qt ISO 8601 time support

  1. #1
    Join Date
    Aug 2013
    Posts
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Qt ISO 8601 time support

    Hi,
    Can any Qt5 time related class deal with time formatted as "PT23H12M48S"?
    I tried QTime and QDateTime and none works.

    Example:
    QString str = "PT23H12M48S";
    auto t = QDateTime::fromString(str);
    qDebug() << "time is:" << t.toString("HH:mm::ss"); // prints empty string

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt ISO 8601 time support

    That encoding is not the time but a duration (or part of a time interval), i.e. 23 hours, 12 minutes and 48 seconds not 11:12:48 PM. Nothing I am aware of handles that directly in Qt. You could disassemble it with a QRegularExpression and build a number of seconds fairly easily, but there are quite a few variations you need to be careful of in the standard. You also need to be careful if you are adding durations to absolute times around daylight savings changes.

  3. #3
    Join Date
    Aug 2013
    Posts
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Qt ISO 8601 time support

    Thanks for the intelligent answer. Right, that's a duration. For some reason the ODF standard (LibreOffice) stores time values in this format. Alright, I'll parse it back and forth myself.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt ISO 8601 time support

    ISO 8601 also defines a format for absolute time and date, i.e. YYYY-MM-DDThh:mm:ss, and that is handled by Qt's QDateTime.

    AFAICT the ODF uses both XML dateTime and duration (inspired by ISO 8601) in different contexts.

Similar Threads

  1. Replies: 6
    Last Post: 25th June 2015, 10:54
  2. run-time vs linked OpenSSL support
    By piotr.dobrogost in forum Installation and Deployment
    Replies: 12
    Last Post: 30th March 2012, 06:56
  3. QDateTime and Support for Daylight Savings Time
    By Goug in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2011, 01:21
  4. Replies: 5
    Last Post: 19th November 2010, 02:25

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.