Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "date/tz.h"
- #include <chrono>
- #include <iostream>
- #include <string>
- #include <thread>
- #include <mutex>
- std::ostream&
- print_one(std::ostream& os)
- {
- return os;
- }
- template <class A0, class ...Args>
- std::ostream&
- print_one(std::ostream& os, const A0& a0, const Args& ...args)
- {
- os << a0;
- return print_one(os, args...);
- }
- template <class ...Args>
- std::ostream&
- print(std::ostream& os, const Args& ...args)
- {
- return print_one(os, args...);
- }
- std::mutex&
- get_cerr_mutex()
- {
- static std::mutex m;
- return m;
- }
- template <class ...Args>
- std::ostream&
- print(const Args& ...args)
- {
- std::lock_guard<std::mutex> _(get_cerr_mutex());
- return print(std::cerr, args...);
- }
- void
- daily_work(std::string msg, date::time_zone const* tz)
- {
- using namespace date;
- using namespace std::chrono;
- zoned_seconds zt{tz, floor<seconds>(system_clock::now())};
- zt = floor<days>(zt.get_local_time()) + days{1};
- while (true)
- {
- std::this_thread::sleep_until(zt.get_sys_time());
- print(msg, " : ", zt.get_local_time(), '\n');
- zt = zt.get_local_time() + days{1};
- }
- }
- int
- main()
- {
- using namespace date;
- using namespace std;
- thread t1{daily_work, "Newfoundland Stanard Time", locate_zone("America/St_Johns")};
- thread t2{daily_work, "India Standard time", locate_zone("Asia/Kolkata")};
- thread t3{daily_work, "+0545", locate_zone("Asia/Kathmandu")};
- t3.join();
- t2.join();
- t1.join();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement