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. QDateTime: How does one distinguish the "double hour" during DST switch?
Forum Updated to NodeBB v4.3 + New Features

QDateTime: How does one distinguish the "double hour" during DST switch?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 2.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
    Asperamanca
    wrote on last edited by
    #1

    According to docs, QDateTime supports daylight saving time. But how to I distinguish the twin time periods that happen when the clock is turned back during a DST switch? For example, before reaching 3am, the clock is turned back to 2am. If QDateTime says it's 2:39am, are we talking about the first or second such period?
    Also, the toString() method seems to lack a way to express this.

    1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi,

      I would guess that the function isDaylightTime() returns true during the first and false during the second such hour.

      -Michael.

      1 Reply Last reply
      4
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @m.sue said in QDateTime: How does one distinguish the "double hour" during DST switch?:

        Hi,

        I would guess that the function isDaylightTime() returns true during the first and false during second such hour.

        -Michael.

        True. That would still make it very cumbersome to "mark" the second of a duplicate time span, because I would need to understand the specific rules of the DST switch to know whether this is a time period that I need to mark at all.

        Here is an example of what I am looking for.

        UTC      DST   DESIRED OUTPUT
        01:00:00 true  02:00:00
        01:30:00 true  02:30:00
        02:00:00 false 02b00:00
        02:30:00 false 02b30:00
        03:00:00 false 03:00:00
        

        The details of the DST switch should best remain buried within Qt - as a user of the class, I would rather not know the details whether my timezone has DST at all, when and how often the switch occurs, and with what time difference.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          In that case, shouldn't you use a date time format that includes time zone information ? You'll then have the offset applied with DST and without.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          3
          • SGaistS SGaist

            Hi,

            In that case, shouldn't you use a date time format that includes time zone information ? You'll then have the offset applied with DST and without.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @SGaist said in QDateTime: How does one distinguish the "double hour" during DST switch?:

            Hi,

            In that case, shouldn't you use a date time format that includes time zone information ? You'll then have the offset applied with DST and without.

            I think you refer to the ISO 8601 format (Qt::ISODate). That format gives you time zone information, but it doesn't tell you (at one glance) whether you are in a double hour, either. As a user, you again have to understand the time zone specification, and I'd like to avoid that.
            Also, it is rather long.

            1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on last edited by
              #6

              Hi, I think @SGaist meant the vanilla QDateTime, anyway, what you can try:
              #include "qdatetime.h"
              and

              if (!QDateTime::currentDateTime().isDaylightTime() && QDateTime::currentDateTime().addSecs(-3600).isDaylightTime())
                  // inside the double hour
              A 1 Reply Last reply
              1
              • hskoglundH hskoglund

                Hi, I think @SGaist meant the vanilla QDateTime, anyway, what you can try:
                #include "qdatetime.h"
                and

                if (!QDateTime::currentDateTime().isDaylightTime() && QDateTime::currentDateTime().addSecs(-3600).isDaylightTime())
                    // inside the double hour
                A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                @hskoglund said in QDateTime: How does one distinguish the "double hour" during DST switch?:

                Hi, I think @SGaist meant the vanilla QDateTime, anyway, what you can try:
                #include "qdatetime.h"
                and

                if (!QDateTime::currentDateTime().isDaylightTime() && QDateTime::currentDateTime().addSecs(-3600).isDaylightTime())
                    // inside the double hour
                

                Good point. That could work. Thanks!

                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