1 #ifndef POSIX_TIME_CONFIG_HPP___
2 #define POSIX_TIME_CONFIG_HPP___
4 /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
12 #include <cstdlib> //for MCW 7.2 std::abs(long long)
13 #include <boost/limits.hpp>
14 #include <boost/cstdint.hpp>
15 #include <boost/config/no_tr1/cmath.hpp>
16 #include <boost/date_time/time_duration.hpp>
17 #include <boost/date_time/time_resolution_traits.hpp>
18 #include <boost/date_time/gregorian/gregorian_types.hpp>
19 #include <boost/date_time/wrapping_int.hpp>
20 #include <boost/date_time/compiler_config.hpp>
23 namespace posix_time {
25 //Remove the following line if you want 64 bit millisecond resolution time
26 //#define BOOST_GDTL_POSIX_TIME_STD_CONFIG
28 #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
29 // set up conditional test compilations
30 #define BOOST_DATE_TIME_HAS_MILLISECONDS
31 #define BOOST_DATE_TIME_HAS_MICROSECONDS
32 #define BOOST_DATE_TIME_HAS_NANOSECONDS
33 typedef date_time::time_resolution_traits<boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::nano,
34 1000000000, 9 > time_res_traits;
36 // set up conditional test compilations
37 #define BOOST_DATE_TIME_HAS_MILLISECONDS
38 #define BOOST_DATE_TIME_HAS_MICROSECONDS
39 #undef BOOST_DATE_TIME_HAS_NANOSECONDS
40 typedef date_time::time_resolution_traits<
41 boost::date_time::time_resolution_traits_adapted64_impl, boost::date_time::micro,
42 1000000, 6 > time_res_traits;
45 // #undef BOOST_DATE_TIME_HAS_MILLISECONDS
46 // #undef BOOST_DATE_TIME_HAS_MICROSECONDS
47 // #undef BOOST_DATE_TIME_HAS_NANOSECONDS
48 // typedef date_time::time_resolution_traits<boost::int64_t, boost::date_time::tenth,
49 // 10, 0 > time_res_traits;
54 //! Base time duration type
55 /*! \ingroup time_basics
58 public date_time::time_duration<time_duration, time_res_traits>
61 typedef time_res_traits rep_type;
62 typedef time_res_traits::day_type day_type;
63 typedef time_res_traits::hour_type hour_type;
64 typedef time_res_traits::min_type min_type;
65 typedef time_res_traits::sec_type sec_type;
66 typedef time_res_traits::fractional_seconds_type fractional_seconds_type;
67 typedef time_res_traits::tick_type tick_type;
68 typedef time_res_traits::impl_type impl_type;
69 time_duration(hour_type hour,
72 fractional_seconds_type fs=0) :
73 date_time::time_duration<time_duration, time_res_traits>(hour,min,sec,fs)
76 date_time::time_duration<time_duration, time_res_traits>(0,0,0)
78 //! Construct from special_values
79 time_duration(boost::date_time::special_values sv) :
80 date_time::time_duration<time_duration, time_res_traits>(sv)
82 //Give duration access to ticks constructor -- hide from users
83 friend class date_time::time_duration<time_duration, time_res_traits>;
85 explicit time_duration(impl_type tick_count) :
86 date_time::time_duration<time_duration, time_res_traits>(tick_count)
90 #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
92 //! Simple implementation for the time rep
93 struct simple_time_rep
95 typedef gregorian::date date_type;
96 typedef time_duration time_duration_type;
97 simple_time_rep(date_type d, time_duration_type tod) :
101 // make sure we have sane values for date & time
102 if(!day.is_special() && !time_of_day.is_special()){
103 if(time_of_day >= time_duration_type(24,0,0)) {
104 while(time_of_day >= time_duration_type(24,0,0)) {
105 day += date_type::duration_type(1);
106 time_of_day -= time_duration_type(24,0,0);
109 else if(time_of_day.is_negative()) {
110 while(time_of_day.is_negative()) {
111 day -= date_type::duration_type(1);
112 time_of_day += time_duration_type(24,0,0);
118 time_duration_type time_of_day;
119 bool is_special()const
121 return(is_pos_infinity() || is_neg_infinity() || is_not_a_date_time());
123 bool is_pos_infinity()const
125 return(day.is_pos_infinity() || time_of_day.is_pos_infinity());
127 bool is_neg_infinity()const
129 return(day.is_neg_infinity() || time_of_day.is_neg_infinity());
131 bool is_not_a_date_time()const
133 return(day.is_not_a_date() || time_of_day.is_not_a_date_time());
137 class posix_time_system_config
140 typedef simple_time_rep time_rep_type;
141 typedef gregorian::date date_type;
142 typedef gregorian::date_duration date_duration_type;
143 typedef time_duration time_duration_type;
144 typedef time_res_traits::tick_type int_type;
145 typedef time_res_traits resolution_traits;
146 #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
148 BOOST_STATIC_CONSTANT(boost::int64_t, tick_per_second = 1000000000);
154 class millisec_posix_time_system_config
157 typedef boost::int64_t time_rep_type;
158 //typedef time_res_traits::tick_type time_rep_type;
159 typedef gregorian::date date_type;
160 typedef gregorian::date_duration date_duration_type;
161 typedef time_duration time_duration_type;
162 typedef time_res_traits::tick_type int_type;
163 typedef time_res_traits::impl_type impl_type;
164 typedef time_res_traits resolution_traits;
165 #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers
167 BOOST_STATIC_CONSTANT(boost::int64_t, tick_per_second = 1000000);
173 } }//namespace posix_time