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. WEuropeanStandardTime
Forum Updated to NodeBB v4.3 + New Features

WEuropeanStandardTime

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.0k Views 4 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by
    #1

    Hi everybody.
    Is there someone that knows this time of timezone and is there a way to have it with a Qt object?

    WEuropeanStandardTime-1DaylightTime,M3.5.0,M10.5.0/3
    (means +01:00 (Rome) time zone)

    Regards.

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    kshegunovK JKSHJ 2 Replies Last reply
    0
    • mrdebugM mrdebug

      Hi everybody.
      Is there someone that knows this time of timezone and is there a way to have it with a Qt object?

      WEuropeanStandardTime-1DaylightTime,M3.5.0,M10.5.0/3
      (means +01:00 (Rome) time zone)

      Regards.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Do you mean QTimeZone?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • mrdebugM Offline
        mrdebugM Offline
        mrdebug
        wrote on last edited by
        #3

        Not exactly. I need to obtain the string above but I don't know how.

        Need programmers to hire?
        www.labcsp.com
        www.denisgottardello.it
        GMT+1
        Skype: mrdebug

        kshegunovK 1 Reply Last reply
        0
        • mrdebugM mrdebug

          Not exactly. I need to obtain the string above but I don't know how.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          Well I have no idea what the string above means, but any timezone information you might need should be available through the timezone class.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • mrdebugM mrdebug

            Hi everybody.
            Is there someone that knows this time of timezone and is there a way to have it with a Qt object?

            WEuropeanStandardTime-1DaylightTime,M3.5.0,M10.5.0/3
            (means +01:00 (Rome) time zone)

            Regards.

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @mrdebug said in WEuropeanStandardTime:

            Is there someone that knows this time of timezone

            That looks like a POSIX TZ string: http://www.di-mgt.com.au/wclock/tz.html

            and is there a way to have it with a Qt object?

            Not at the moment.

            How do you wish to use that string?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            2
            • mrdebugM Offline
              mrdebugM Offline
              mrdebug
              wrote on last edited by
              #6

              I need that string to implement SetDateTime onvif request

              Need programmers to hire?
              www.labcsp.com
              www.denisgottardello.it
              GMT+1
              Skype: mrdebug

              JKSHJ Paul ColbyP 2 Replies Last reply
              0
              • mrdebugM mrdebug

                I need that string to implement SetDateTime onvif request

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                @mrdebug said in WEuropeanStandardTime:

                I need that string to implement SetDateTime onvif request

                The string format is described at http://www.di-mgt.com.au/wclock/tz.html

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                1
                • mrdebugM mrdebug

                  I need that string to implement SetDateTime onvif request

                  Paul ColbyP Offline
                  Paul ColbyP Offline
                  Paul Colby
                  wrote on last edited by
                  #8

                  @mrdebug said in WEuropeanStandardTime:

                  I need that string to implement SetDateTime onvif request

                  Hmm. That's a particularly ugly format, IMO... I'd be interested in seeing the documentation that says you need to use it. Maybe that API supports alternative formats too?

                  Anyway, to get an idea of how you might do it with Qt...

                  #include <QDateTime>
                  #include <QTimeZone>
                  
                  QString quotePosix1StdDst(const QString &stdDst)
                  {
                      foreach (const QChar c, stdDst) {
                          if (!c.isLetter()) {
                              return QString::fromLatin1("<%1>").arg(stdDst);
                          }
                      }
                      return stdDst;
                  }
                  
                  QString toPosix1Time(const int offset, const bool useSign = false)
                  {
                      QString str;
                      if (useSign) {
                          str += QLatin1Char((offset >= 0) ? '+' : '-');
                      }
                      str += QString::number(qAbs(offset) / 3600);
                      if ((offset % 3600) != 0) {
                          str += QString::fromLatin1(":%1").arg((qAbs(offset) % 3600) / 60, 2, 10, QLatin1Char('0'));
                      }
                      if ((offset % 60) != 0) {
                          str += QString::fromLatin1(":%1").arg(qAbs(offset) % 60, 2, 10, QLatin1Char('0'));
                      }
                      return str;
                  }
                  
                  QString toPosix1Rule(const QDateTime &dt)
                  {
                      return QString::fromLatin1("M%1.%2.%3/%4")
                          .arg(dt.date().month())
                          .arg((dt.date().day() - dt.date().dayOfWeek()) / 7 + 1)
                          .arg(dt.date().dayOfWeek()%7) // Convert 1-based to 0-based.
                          .arg(toPosix1Time(dt.time().msecsSinceStartOfDay()/1000));
                  }
                  
                  QString toPosix1Tz(const QTimeZone &tz,
                                     const QTimeZone::NameType nt = QTimeZone::ShortName)
                  {
                      // std
                      QString str = quotePosix1StdDst(tz.displayName(QTimeZone::StandardTime, nt));
                  
                      // offset (if no transitions)
                      if (!tz.hasTransitions()) {
                          str += toPosix1Time(tz.offsetFromUtc(QDateTime::currentDateTime()), true);
                          return str;
                      }
                  
                      // Get the first DST and non-DST transitions.
                      QTimeZone::OffsetData dst, nonDst;
                      {
                          const QDateTime dt = QDateTime::currentDateTimeUtc(); // Any valid, unambiguous timestamp.
                          const QTimeZone::OffsetData data1 = tz.previousTransition(dt);
                          const QTimeZone::OffsetData data2 = tz.previousTransition(data1.atUtc);
                          Q_ASSERT(data1.atUtc.isValid() && data2.atUtc.isValid());
                          Q_ASSERT((data1.daylightTimeOffset == 0) || (data2.daylightTimeOffset == 0));
                          Q_ASSERT((data1.daylightTimeOffset != 0) || (data2.daylightTimeOffset != 0));
                          dst = (data1.daylightTimeOffset == 0) ? data2 : data1;
                          nonDst = (data1.daylightTimeOffset == 0) ? data1 : data2;
                      }
                  
                      // offset
                      str += toPosix1Time(dst.standardTimeOffset, true);
                  
                      // dst
                      str += dst.abbreviation;
                  
                      // dst-offset
                      str += toPosix1Time(dst.daylightTimeOffset, true);
                  
                      // start
                      str += QLatin1Char(',') + toPosix1Rule(dst.atUtc.toTimeZone(tz));
                  
                      // end
                      str += QLatin1Char(',') + toPosix1Rule(nonDst.atUtc.toTimeZone(tz));
                  
                      return str;
                  }
                  
                  void tryIt()
                  {
                      foreach (const QByteArray &ianaId, QTimeZone::availableTimeZoneIds()) {
                          qDebug() << ianaId << toPosix1Tz(QTimeZone(ianaId));
                      }
                  }
                  

                  That code seems to work mostly - that is, the output looks okay at a quick glance. I guarantee it will have bugs, issues, and failed corner cases, but it does give you an idea of what might be required.

                  Good luck! :)

                  1 Reply Last reply
                  3

                  • Login

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