Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85149

qv4dateobject.cpp uses incorrect daylight savings calculation

    XMLWordPrintable

Details

    • 13
    • dff02466a0 (qt/qtdeclarative/dev) 3033e99fa8 (qt/qtdeclarative/6.4) 3033e99fa8 (qt/tqtc-qtdeclarative/6.4)

    Description

      In the case that we don't use QTimeZone for the date/time calculations, DaylightSavingTA() looks like this:

      // This implementation fails to take account of past changes in standard offset.
      static inline double DaylightSavingTA(double t, double /*localTZA*/)
      {
          struct tm tmtm;
      #if defined(Q_CC_MSVC)
          __time64_t  tt = (__time64_t)(t / msPerSecond);
          // _localtime_64_s returns non-zero on failure
          if (_localtime64_s(&tmtm, &tt) != 0)
      #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
          long int tt = (long int)(t / msPerSecond);
          if (!localtime_r((const time_t*) &tt, &tmtm))
      #else
          // Returns shared static data which may be overwritten at any time
          // (for MinGW/Windows localtime is luckily thread safe)
          long int tt = (long int)(t / msPerSecond);
          if (struct tm *tmtm_p = localtime((const time_t*) &tt))
              tmtm = *tmtm_p;
          else
      #endif
              return 0;
          return (tmtm.tm_isdst > 0) ? msPerHour : 0;
      }
      

      This is obviously wrong because it can only return an hour or 0. There are non-zero daylight savings offsets different from one hour (two hours, minus an hour, at least). Also, as the initial comment points out, this code fails to take account of historical changes to the standard offset, which (despite its name) this function should be reporting (but can't).

      With https://codereview.qt-project.org/c/qt/qtdeclarative/+/305018 we still use this implementation if !QT_CONFIG(timezone) and on windows. We need to reconsider what to do with it.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Eddy Edward Welbourne
              ulherman Ulf Hermann
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes