Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

time and time zones



  • (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...


  • Lifetime Qt Champion

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



  • @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.



  • @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?



  • @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...



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



  • @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.



  • @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 :-(



  • @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...



  • @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 :=)



  • @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?



  • @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.



  • @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....


  • Qt Champions 2017

    @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 ...



  • @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.


  • Qt Champions 2017

    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.



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



  • 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.


Log in to reply