Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved time and time zones

    Brainstorm
    6
    18
    1368
    Loading More Posts
    • 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.
    • mzimmers
      mzimmers last edited by

      (Geez, am I the only person who asks questions in this forum?!)

      Anyway, I have a Qt app that is an interface to an embedded system. The embedded system (FreeRTOS/LwIP/ESP32) needs to be aware of what time zone it's in, and supports time zone functions using TZ strings (eg "PST+8PDT,M3.2.0,M11.1.0"), but not official time zone names (eg "America/Los_Angeles").

      I'd like my Qt app to give the user a list of official time zone names, which I can obtain with QTimeZone::availableTimeZoneIds(). I don't see a way, though, to convert the name to a TZ string (which I would pass to the embedded app).

      Any ideas? Thanks...

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        Why can't you build it by yourself with e.g. QTimeZone::offsetFromUtc()?

        Qt has to stay free or it will die.

        mzimmers 1 Reply Last reply Reply Quote 1
        • mzimmers
          mzimmers @Christian Ehrlicher last edited by

          @Christian-Ehrlicher the TZ string is more than just an offset; it's a series of tokens, most of which are intended to instruct the time-keeping facility as to what to do for DST. I'd greatly prefer not to have to build this string myself.

          This page has a short table containing what I want; if I could find a table that includes more names (the call to availableTimeZoneIds() returns 475 items), I'd just use it to create a table in my Qt app. I'm just hoping that someone knows of a way to obviate the need for doing this.

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @mzimmers last edited by

            @mzimmers
            You haven't been around for a while!

            I don't see Qt code for that "extended TZ syntax". Posix or something? You might better find conversion code elsewhere on the web?

            mzimmers 1 Reply Last reply Reply Quote 1
            • mzimmers
              mzimmers @JonB last edited by

              @JonB yeah, I think this is outside the realm of Qt-dom. As for finding a pre-made table, I've been looking without success. For now, I'll create my own (borrowing from the link I posted above), but if anyone knows of a more complete listing, I'd love to hear about it.

              Thanks...

              1 Reply Last reply Reply Quote 0
              • hskoglund
                hskoglund last edited by

                Maybe you'll have to bite the bullet and go for the mother lode https://www.iana.org/time-zones

                mzimmers 1 Reply Last reply Reply Quote 0
                • mzimmers
                  mzimmers @hskoglund last edited by

                  @hskoglund unfortunately, even that doesn't have what I'm looking for; at least I didn't see it. Lots of other stuff, but not this.

                  hskoglund 1 Reply Last reply Reply Quote 0
                  • hskoglund
                    hskoglund @mzimmers last edited by

                    @mzimmers Lots of stuff it is, but for example, if I look at my Ubuntu 19.10 machine, and go to /usr/share/zoneinfo (which is Ubuntu's copy of that mother lode), if i type for example the CET file, I get lots of junk but in the end I get

                    I?I??J?K??L̿?M??N???OnnP???QW??Rle?S7l?TLG?UN?V,)?V?0?XFX??Y?(Z???[?
                    \?]??^?_??`_?a}?b??c]̐d?e=????g??g藐h?r?i?y?j?T?k?[?l?qm?=?n?Soh?p?5qQ<rfs1tE?uv/?v??x??x??y?ِz??{λ?|?}???~y????  CETCEST
                    CET-1CEST,M3.5.0,M10.5.0/3
                    

                    so it's there. But the zdump program refuses to dump it, I tried all the command switches :-(

                    mzimmers 1 Reply Last reply Reply Quote 0
                    • mzimmers
                      mzimmers @hskoglund last edited by

                      @hskoglund so, if I understand this, I'd have to build the IANA software, generate all the files, and extract the TZ string I want from each one. That's just too labor-intensive to be a viable approach.

                      I'm still amazed that someone out there doesn't maintain a table stored in a grid on a web page somewhere that I could just grab, but oh well...

                      hskoglund JonB 2 Replies Last reply Reply Quote 0
                      • hskoglund
                        hskoglund @mzimmers last edited by

                        @mzimmers said in time and time zones:

                        I'm still amazed that someone out there doesn't maintain a table stored in a grid on a web page somewhere that I could just grab, but oh well...

                        Well never say never, if you build those files, you could be the one maintaining that table :=)

                        1 Reply Last reply Reply Quote 2
                        • JonB
                          JonB @mzimmers last edited by

                          @mzimmers
                          Can you give some "official", "definitive" link to the TZ formats you are talking about? Is there an RFC or an official body or something? So far I think I only saw a link to some example from 2012. Maybe there is a "body" which has a web service to return the tz format you require from a country name?

                          mzimmers 1 Reply Last reply Reply Quote 0
                          • mzimmers
                            mzimmers @JonB last edited by

                            @JonB I wish I could. If I knew of such a body, it might have helped me in my search for the table I was looking for. I only know of it the POSIX time zone format as it's referenced by IANA and a few other sites like this.

                            JonB 1 Reply Last reply Reply Quote 0
                            • JonB
                              JonB @mzimmers last edited by JonB

                              @mzimmers
                              OK, so this is all to do with zoneinfo. Are you Linux?

                              jon@ubuntu-19:~$ file /usr/share/zoneinfo/America/Los_Angeles 
                              /usr/share/zoneinfo/America/Los_Angeles: timezone data, version 2, 5 gmt time flags, 5 std time flags, no leap seconds, 186 transition times, 5 abbreviation chars
                              

                              Start reading from man tzfile (if you're not Linux man pages are available online).

                              I don't know where you ended up getting your table from, and the strings in the "tz extended format" for each "friendly" country name, but there may be a call or enough information there if you want to get/make these strings. If the host for your Qt app is Linux, you could leverage that from code.

                              Meanwhile, you might be interested in my own solution for the world's horrendous timezone rules? Abolish all timezones, and daylight savings, world-wide. Everywhere works on identical current time. (All set to one standard, which will obviously be UK/London/GMT/UTC.) If it's 08:14am in England, then it's same in Australia. So now there is no time conversions anywhere. The only difference is if I go to work from 8am to 5pm in England, Aussies go to work from 8pm to 5am, or similar. We all agree what a conference at 9am means, because it's 9am everywhere. Computer programs no longer have to worry about where you are. Simplez! I don't know why they don't put me in charge of international issues like this....

                              kshegunov 1 Reply Last reply Reply Quote 0
                              • kshegunov
                                kshegunov Moderators @JonB last edited by

                                @JonB said in time and time zones:

                                I don't know where you ended up getting your table from, and the strings in the "tz extended format" for each "friendly" country name, but there may be a call or enough information there if you want to get/make these strings. If the host for your Qt app is Linux, you could leverage that from code

                                @mzimmers, I'd rather advise this instead of calling things on the command line:
                                http://man7.org/linux/man-pages/man3/strptime.3.html
                                http://man7.org/linux/man-pages/man3/strftime.3.html

                                unfortunately it does seem you need to build the TZ strings by hand. At least that's my understanding ...

                                Read and abide by the Qt Code of Conduct

                                JonB 1 Reply Last reply Reply Quote 0
                                • JonB
                                  JonB @kshegunov last edited by JonB

                                  @kshegunov
                                  I never intended he should do anything as a command (unless there is a convenient one which returns all the strings, which I have not seen). Only use the information from code. I thought the information in man tzfile where it documents the structure/content of the file would be enough to generate the "extended TZ format" string from?

                                  strftime/strptime() are for dealing with datetime instances. I don't see how they would help generating the formatting strings he wants.

                                  kshegunov 1 Reply Last reply Reply Quote 0
                                  • kshegunov
                                    kshegunov Moderators @JonB last edited by kshegunov

                                    May be, but I'm not convinced. This file may very well be in a privileged location, and it may change at any time under your feet (while you read), and ... well it's a file, you get it ... not ideal, by far.

                                    @JonB said in time and time zones:

                                    I don't see how they would help generating the formatting strings he wants.

                                    You could extract the pertinent identifiers from the dt instances is the point (e.g. offsets and such). But again ... not ideal, by far.

                                    Read and abide by the Qt Code of Conduct

                                    1 Reply Last reply Reply Quote 0
                                    • mzimmers
                                      mzimmers last edited by

                                      Not ideal, to say the least. I'm going to stand down on this exercise for now. Thanks to all who looked.

                                      1 Reply Last reply Reply Quote 0
                                      • Kent-Dorfman
                                        Kent-Dorfman last edited by Kent-Dorfman

                                        what you are asking for is POSIX TZ format. It can be pulled or generated from the POSIX tzfile(5) database. A quick search of the database on my machine shows that all of the timesonze files I searched contained a newline terminated TZ string fallback for dates after the prior exception rules. You most likely would have to parse the tzfiles according to the zone selected and use the fallback string if it exists, or build the correct string from the data if it doesn't exist. This of course assumes that you are on a unix/linux machine.

                                        1 Reply Last reply Reply Quote 1
                                        • First post
                                          Last post