Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimeSpan: interest?
Forum Updated to NodeBB v4.3 + New Features

QTimeSpan: interest?

Scheduled Pinned Locked Moved General and Desktop
24 Posts 17 Posters 19.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #1

    Hi,

    Quite a while ago on the qt-interest mailinglist, a "question":http://lists.qt.nokia.com/pipermail/qt-interest/2010-June/024344.html on how to substract two dates in order to get a length of time inspired the creation of a class called QTimeSpan. It can be used to represent a period of time, where QDate, QTime and QDateTime only represent a single point in time. Now, the class is basically finished, and we've submitted it for inclusion in Qt.

    On the "merge request":http://qt.gitorious.org/qt/qt/merge_requests/1014 a question was asked why this class would belong in Qt. Personally, I think it would fit nicely, but I am not the only user of Qt of course. That's where you come in. I think it would be beneficial if the associated "Jira ticket":http://bugreports.qt.nokia.com/browse/QTBUG-16556 would get some votes, to underline that more users than just the authors of this class think it would be useful to have in Qt.

    If you'd like to have more information on the capabilities and design of the class before voting for its inclusion, please refer to the documentation that is available in the .cpp file in the merge request. I think it gives a nice overview of what's possible. Of course, I'd be willing to answer questions here too, and I would be interested in suggestions for further improvement. Note that the comments made in the merge request have already been fixed, but not committed yet.

    André

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Thanks for your effort. Representing an amount of time is something that is definitely useful in any general purpose library. I did vote for it.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        Since you're there, how about a nice set of classes to handle datetimes and durations in a way that's really useful for the REAL world? :)

        I.e. something

        • that supports micro/nano seconds;
        • that supports timezones and DST changes;
        • that accounts for leap seconds;
        • that accounts for working days;
        • that supports arbitrary spans for months, days, hours, minutes, seconds and micro/nano second (and implement a reasonable logic for all of this);

        etc? :-)

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          This class looks really helpful, so I voted for it. Hope it comes in.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            @peppe:

            QTimeSpan actually does support timezones, at least in so far QDateTime supports it. :-)
            DST changes is actually a good point. We did not considder this, and we should test what happens. I don't know if it would be possible to take into account, I guess it depends if QDateTime already does this or not. A problem may be that DST's rules tend to change now and then...

            The support for arbitrary spans is currently quite extensive, I'd say. QTimeSpan can represent (in theory) anything from 1 ms to roughly 292 million years. I doubt if it makes sense to use it for such long time periods (at 1 ms precision), but don't let me stop you :-) That does make me think though: we should probably test what happens at really long time periods that would move out of QDate's range. Currently, that is not something that we covered in the unit tests.

            While we're at it: is there a reason to stop at nano seconds? A zeptosecond or yoctosecond could also be useful perhaps? ;-)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              With DST (and respectivly 23/25 h days) QDateTiem has a problem, and afaik it's not fixed up to now.

              You do not get out of QDateTime it its the first 2 o'clock in the morning or the second one :-( (DST in Germany happens at 3 o'clock with a switch back to 2 o'clock, so you have 2 o'clock two times that day).

              Same applies to the QDateTimeEdit, there you don't know, which of the two you set by setting 2:30 ...

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • O Offline
                O Offline
                Olorin5800
                wrote on last edited by
                #7

                Nice class. Voted for it.


                My programs never have bugs, they just develop random features.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  @Gerolf:
                  So, the problem is, that 02:30 on the date the clock goes back an hour is simply an ambigous time. I am not sure there is anything you can do about that, other than specifying the time in UTC instead. There are "bugreports":http://bugreports.qt.nokia.com/browse/QTBUG-10219 in Jira to ask for a better support for timezones in QDateTime.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    milot.shala
                    wrote on last edited by
                    #9

                    Great work. I voted for it because I needed this a while ago, and for sure I will need it in the future.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AS.Sri
                      wrote on last edited by
                      #10

                      Thanks a lot Andre, voted in JIRA.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        sabrog
                        wrote on last edited by
                        #11

                        Thanks, André. I voted.

                        QT - Apple QuickTime
                        Qt - Nokia's Qt Development Frameworks
                        Apple is a competitor of Nokia, so QT != Qt

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          janarve
                          wrote on last edited by
                          #12

                          A timespan has some pitfalls:
                          If it uses walltime as the two reference points, you must handle cases where start time is actually after end time. This is because there system time can be updated from a time source (and might jump back in time). IIRC on cell phones this happens quite often, but it can also happen if your desktop system is connected to a NTP time source. It can also happen if you are not connected to a external time source, for instance due to DST changes.
                          This is also mentioned in the documentation for QTime::elapsed(), which is often used for the same purpose. (actually it says that the result is undefined)

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            Thank you for your comment, but that case is handled. The proposed QTimeSpan handles negative time spans just fine.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              DerManu
                              wrote on last edited by
                              #14

                              Voted and Watched.
                              So, after two years, are timespans still not added to Qt? What a shame!

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                Note that that is also a due to Sean and me not pushing hard enough to get it in after the first attempt.

                                1 Reply Last reply
                                0
                                • U Offline
                                  U Offline
                                  utcenter
                                  wrote on last edited by
                                  #16

                                  Useful class - voted.

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    JulienMaille
                                    wrote on last edited by
                                    #17

                                    voted too

                                    1 Reply Last reply
                                    0
                                    • R Offline
                                      R Offline
                                      romanick
                                      wrote on last edited by
                                      #18

                                      It's very needed class!
                                      +1

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        Benito1979
                                        wrote on last edited by
                                        #19

                                        I need this class, seems to be very useful!!!

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          Andrey Dyatlov
                                          wrote on last edited by
                                          #20

                                          Hello Andre,
                                          I think QTimeSpan class is really a missing part of the Qt Project. Thanks for yours and Sean's efforts!
                                          I have a question regarding the legality. Is it possible to use your sources in a commercial project (we use Qt with LGPL) as a part of a code-base (do not incorporate it to the Qt libs) before it becomes a part of Qt officially?
                                          Thanks!

                                          UPD: English has been slightly improved.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved