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 
6 #define BOOST_CHRONO_VERION 2
7 #include <iostream>
8 #include <boost/chrono/chrono.hpp>
9 #include <boost/chrono/chrono_io.hpp>
10 
11 // a custom clock
12 // here based on boost's own system_clock
13 class MyMillenniumClock
14 {
15 public:
16   typedef boost::chrono::system_clock::rep rep;
17   typedef boost::chrono::system_clock::period period;
18   typedef boost::chrono::duration<rep, period> duration;
19   typedef boost::chrono::time_point<MyMillenniumClock> time_point;
20 
21   BOOST_STATIC_CONSTEXPR bool is_steady = boost::chrono::system_clock::is_steady;
22 
23 public:
24   /// Returns a time_point representing the current value of the clock.
now()25   static time_point now() {
26     return time_point(boost::chrono::system_clock::now().time_since_epoch() - boost::chrono::hours(30*365));
27   }
28 };
29 
30 
31 namespace boost
32 {
33   namespace chrono
34   {
35     template <class CharT>
36     struct clock_string<MyMillenniumClock, CharT>
37     {
nameboost::chrono::clock_string38       static std::basic_string<CharT> name() {
39         static const CharT a[] = {'M', 'y', 'M', 'i', 'l', 'l', 'e', 'n', 'n', 'i', 'u', 'm', 'C', 'l', 'o', 'c', 'k'};
40         return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
41       }
sinceboost::chrono::clock_string42       static std::basic_string<CharT> since() {
43         static const CharT a[] = {' ', 's', 'i', 'n', 'c', 'e', ' ', 'y', 'e', 'a', 'r', ' ', '2', 'k'};
44         return std::basic_string<CharT>(a, a + sizeof(a)/sizeof(a[0]));
45       }
46     };
47   }
48 }
49 
50 template <typename CharT, typename TPUFacet>
get_epoch_custom(MyMillenniumClock,TPUFacet &)51 std::basic_string<CharT> get_epoch_custom(MyMillenniumClock, TPUFacet&)
52 {
53   return boost::chrono::clock_string<MyMillenniumClock,CharT>::since();
54 }
55 
main()56 int main()
57 {
58     std::cout << boost::chrono::steady_clock::now() << std::endl;
59     std::cout << MyMillenniumClock::now() << std::endl;
60     return 0;
61 }
62