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

Qt doesn't really follow Windows short time format

    XMLWordPrintable

Details

    • Windows
    • 763884cfb (dev), 841efd077 (6.5), a765c1043 (6.4), 3d6e3fe20 (tqtc/lts-5.15), 8d58c7d7a (tqtc/lts-6.2)

    Description

      1. Set the short time format in intl.cpl as H:mm:ss
      2. Check the result of

      QLocale().toString(QDateTime::currentDateTime().time(), QLocale::ShortFormat);

      Expected result: follows the format
      Observed result: uses H:mm format

      I was able to fix this with the following patch

      diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp
      index cb7131667c..bc9a30e828 100644
      --- a/src/corelib/text/qlocale_win.cpp
      +++ b/src/corelib/text/qlocale_win.cpp
      @@ -485,12 +485,12 @@ QVariant QSystemLocalePrivate::toString(QTime time, QLocale::FormatType type)
           st.wMilliseconds = 0;
       
           DWORD flags = 0;
      -    // keep the same conditional as timeFormat() above
      -    if (type == QLocale::ShortFormat)
      -        flags = TIME_NOSECONDS;
      +    std::wstring format = type == QLocale::ShortFormat
      +        ? getLocaleInfo(LOCALE_SSHORTTIME).toString().toStdWString()
      +        : std::wstring();
       
           wchar_t buf[255];
      -    if (getTimeFormat(flags, &st, NULL, buf, 255)) {
      +    if (getTimeFormat(flags, &st, !format.empty() ? format.c_str() : NULL, buf, 255)) {
               QString text = QString::fromWCharArray(buf);
               if (substitution() == SAlways)
                   text = substituteDigits(std::move(text));
      

      I can submit it to gerrit if it's the right fix.

      Attachments

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

        Activity

          People

            Eddy Edward Welbourne
            ilya-fedin Ilya Fedin
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: