Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include "date/tz.h"
  2. #include <chrono>
  3. #include <iostream>
  4. #include <string>
  5. #include <thread>
  6. #include <mutex>
  7.  
  8. std::ostream&
  9. print_one(std::ostream& os)
  10. {
  11.     return os;
  12. }
  13.  
  14. template <class A0, class ...Args>
  15. std::ostream&
  16. print_one(std::ostream& os, const A0& a0, const Args& ...args)
  17. {
  18.     os << a0;
  19.     return print_one(os, args...);
  20. }
  21.  
  22. template <class ...Args>
  23. std::ostream&
  24. print(std::ostream& os, const Args& ...args)
  25. {
  26.     return print_one(os, args...);
  27. }
  28.  
  29. std::mutex&
  30. get_cerr_mutex()
  31. {
  32.     static std::mutex m;
  33.     return m;
  34. }
  35.  
  36. template <class ...Args>
  37. std::ostream&
  38. print(const Args& ...args)
  39. {
  40.     std::lock_guard<std::mutex> _(get_cerr_mutex());
  41.     return print(std::cerr, args...);
  42. }
  43.  
  44.  
  45. void
  46. daily_work(std::string msg, date::time_zone const* tz)
  47. {
  48.     using namespace date;
  49.     using namespace std::chrono;
  50.     zoned_seconds zt{tz, floor<seconds>(system_clock::now())};
  51.     zt = floor<days>(zt.get_local_time()) + days{1};
  52.     while (true)
  53.     {
  54.         std::this_thread::sleep_until(zt.get_sys_time());
  55.         print(msg, " : ", zt.get_local_time(), '\n');
  56.         zt = zt.get_local_time() + days{1};
  57.     }
  58. }
  59.  
  60. int
  61. main()
  62. {
  63.     using namespace date;
  64.     using namespace std;
  65.     thread t1{daily_work, "Newfoundland Stanard Time", locate_zone("America/St_Johns")};
  66.     thread t2{daily_work, "India Standard time", locate_zone("Asia/Kolkata")};
  67.     thread t3{daily_work, "+0545", locate_zone("Asia/Kathmandu")};
  68.     t3.join();
  69.     t2.join();
  70.     t1.join();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement