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
13class MyMillenniumClock
14{
15public:
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
23public:
24 /// Returns a time_point representing the current value of the clock.
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
31namespace boost
32{
33 namespace chrono
34 {
35 template <class CharT>
36 struct clock_string<MyMillenniumClock, CharT>
37 {
38 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 }
42 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
50template <typename CharT, typename TPUFacet>
51std::basic_string<CharT> get_epoch_custom(MyMillenniumClock, TPUFacet&)
52{
53 return boost::chrono::clock_string<MyMillenniumClock,CharT>::since();
54}
55
56int main()
57{
58 std::cout << boost::chrono::steady_clock::now() << std::endl;
59 std::cout << MyMillenniumClock::now() << std::endl;
60 return 0;
61}
62

source code of boost/libs/chrono/test/test_10631.cpp