2

I am making a world clock QML program. I am currently using an API to get the timezone ID of a certain city.

So for instance, for Delft, it would return

TimezoneID = Europe/Amsterdam 

I store the city name and its timezoneID in a local sql database so that I wouldn't have to keep parsing online for the timezone info.

In my application, I have a ListView which displays the cityname along side its local time. How do I calculate the time at Delft using my system time and its timezoneID?

Nik
  • 759
  • 3
  • 10
  • 24

1 Answers1

2

As far as I know, QML itself does not have this functionality, here are alternatives:

Since you already use a database, why don't you simply add the zone.tab part of the tz database to your database and calculate the times yourself? (Don't forget about daylight saving time...)

If you don't like that, you can also use TimezoneJS, a javascript library for handling timezones (which needs a copy of the same database mentioned above).

Or you write a C++ plugin for QML that encapsulatesdate and tzset.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
xubuntix
  • 2,333
  • 18
  • 19
  • I would love to use the first suggestions (zone.tab), however how can I know when to apply daylight saving time and when not to? Countries change from DST to Normal at different dates. The second method does not have this limitation, however I am not really leaning towards it due to the large javascript library that I need to include. I am hesitant because javascript reduces performance amongst other reasons in QML. – Nik Jul 09 '13 at 18:07
  • Zone.tab is supplemental info. The info needed for DST calculation is the bulk of the TZDB. @Nik - I don't know anything about QML, but if you can run javascript like Xubuntix suggested, there are several different libraries to choose from. I list them [here](http://stackoverflow.com/a/15171030/634824). – Matt Johnson-Pint Jul 10 '13 at 00:18
  • If you're going the C++ route, you might look into using Boost, which supports the IANA style timezones (like `Europe/Amsterdam`). You can read more [here](http://www.boost.org/doc/libs/1_54_0/doc/html/date_time/local_time.html) – Matt Johnson-Pint Jul 15 '13 at 19:38