test_10631.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 Vicente J. Botet Escriba
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // See http://www.boost.org/LICENSE_1_0.txt
  4. // See http://www.boost.org/libs/chrono for documentation.
  5. #define BOOST_CHRONO_VERION 2
  6. #include <iostream>
  7. #include <boost/chrono/chrono.hpp>
  8. #include <boost/chrono/chrono_io.hpp>
  9. // a custom clock
  10. // here based on boost's own system_clock
  11. class MyMillenniumClock
  12. {
  13. public:
  14. typedef boost::chrono::system_clock::rep rep;
  15. typedef boost::chrono::system_clock::period period;
  16. typedef boost::chrono::duration<rep, period> duration;
  17. typedef boost::chrono::time_point<MyMillenniumClock> time_point;
  18. BOOST_STATIC_CONSTEXPR bool is_steady = boost::chrono::system_clock::is_steady;
  19. public:
  20. /// Returns a time_point representing the current value of the clock.
  21. static time_point now() {
  22. return time_point(boost::chrono::system_clock::now().time_since_epoch() - boost::chrono::hours(30*365));
  23. }
  24. };
  25. namespace boost
  26. {
  27. namespace chrono
  28. {
  29. template <class CharT>
  30. struct clock_string<MyMillenniumClock, CharT>
  31. {
  32. static std::basic_string<CharT> name() {
  33. static const CharT a[] = {'M', 'y', 'M', 'i', 'l', 'l', 'e', 'n', 'n', 'i', 'u', 'm', 'C', 'l', 'o', 'c', 'k'};
  34. return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
  35. }
  36. static std::basic_string<CharT> since() {
  37. static const CharT a[] = {' ', 's', 'i', 'n', 'c', 'e', ' ', 'y', 'e', 'a', 'r', ' ', '2', 'k'};
  38. return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
  39. }
  40. };
  41. }
  42. }
  43. template <typename CharT, typename TPUFacet>
  44. std::basic_string<CharT> get_epoch_custom(MyMillenniumClock, TPUFacet&)
  45. {
  46. return boost::chrono::clock_string<MyMillenniumClock,CharT>::since();
  47. }
  48. int main()
  49. {
  50. std::cout << boost::chrono::steady_clock::now() << std::endl;
  51. std::cout << MyMillenniumClock::now() << std::endl;
  52. return 0;
  53. }