date - Get timezone where it's 10AM (or any arbitrary hour)? -


i've been stumped trying solve while, logic keeps escaping me. on given language, logic calculate timezones it's given time?

my first answer had bug pointed out matt johnson. such major design flaw in answer instead of editing answer, decided start on new answer.

to assure myself had right time, looped on 24 "requested" hours (00 - 23), , output places requested hours. output rather lengthy, , i'm giving link it:

http://codepad.org/ppnaiewf

note in answer, there times 6am (for example), different dates:

time 06:00 etc/gmt+11                     2016-01-27 06:00:00 gmt+11 etc/gmt-13                     2016-01-28 06:00:00 gmt-13 pacific/auckland               2016-01-28 06:00:00 nzdt pacific/chatham                2016-01-28 06:45:00 chadt pacific/enderbury              2016-01-28 06:00:00 phot pacific/fakaofo                2016-01-28 06:00:00 tkt pacific/niue                   2016-01-27 06:00:00 nut pacific/pago_pago              2016-01-27 06:00:00 sst pacific/tongatapu              2016-01-28 06:00:00 tot 

the algorithm doing loop on time zones, current local time, , compare hour of time "requested" hour. here code:

#include "tz.h" #include <chrono> #include <iomanip> #include <iostream>  int main() {     (int hh = 0; hh < 24; ++hh)     {         using namespace std::chrono;         using namespace date;         auto& db = get_tzdb();         auto = floor<hours>(system_clock::now());         auto target = hours{hh};         std::cout << "time " << make_time(target + 0min) << '\n';         (auto& z : db.zones)         {             auto zt = make_zoned(&z, now);             auto local_time = zt.get_local_time();             auto dp = floor<days>(local_time);             auto time = make_time(local_time - dp);             if (time.hours() == target)             {                 std::cout << std::setw(30) << std::left << z.name() << " "                           << zt << '\n';             }         }         std::cout << '\n';     } } 

note time comparison i'm using comparing hour, , ignoring both finer (minutes, seconds) , courser (days).

this uses free, open source parser of iana timezone database:

http://howardhinnant.github.io/date/tz.html

https://github.com/howardhinnant/date


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -