1 #ifndef DATE_TIME_TIME_SYSTEM_SPLIT_HPP
2 #define DATE_TIME_TIME_SYSTEM_SPLIT_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
14 #include "boost/date_time/compiler_config.hpp"
15 #include "boost/date_time/special_defs.hpp"
20 //! An unadjusted time system implementation.
21 #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT))
22 template<typename config
, boost::int32_t ticks_per_second
>
24 template<typename config
>
26 class split_timedate_system
29 typedef typename
config::time_rep_type time_rep_type
;
30 typedef typename
config::date_type date_type
;
31 typedef typename
config::time_duration_type time_duration_type
;
32 typedef typename
config::date_duration_type date_duration_type
;
33 typedef typename
config::int_type int_type
;
34 typedef typename
config::resolution_traits resolution_traits
;
36 //86400 is number of seconds in a day...
37 #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT))
38 typedef date_time::wrapping_int
<int_type
, INT64_C(86400) * ticks_per_second
> wrap_int_type
;
41 BOOST_STATIC_CONSTANT(int_type
, ticks_per_day
= INT64_C(86400) * config::tick_per_second
);
43 # if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0X581) )
44 typedef date_time::wrapping_int
< split_timedate_system::int_type
, split_timedate_system::ticks_per_day
> wrap_int_type
;
46 typedef date_time::wrapping_int
<int_type
, ticks_per_day
> wrap_int_type
;
50 static time_rep_type
get_time_rep(special_values sv
)
54 return time_rep_type(date_type(not_a_date_time
),
55 time_duration_type(not_a_date_time
));
57 return time_rep_type(date_type(pos_infin
),
58 time_duration_type(pos_infin
));
60 return time_rep_type(date_type(neg_infin
),
61 time_duration_type(neg_infin
));
63 time_duration_type td
= time_duration_type(24,0,0,0) - time_duration_type(0,0,0,1);
64 return time_rep_type(date_type(max_date_time
), td
);
67 return time_rep_type(date_type(min_date_time
), time_duration_type(0,0,0,0));
70 return time_rep_type(date_type(not_a_date_time
),
71 time_duration_type(not_a_date_time
));
77 static time_rep_type
get_time_rep(const date_type
& day
,
78 const time_duration_type
& tod
,
79 date_time::dst_flags
/* dst */ = not_dst
)
81 if(day
.is_special() || tod
.is_special()) {
82 if(day
.is_not_a_date() || tod
.is_not_a_date_time()) {
83 return time_rep_type(date_type(not_a_date_time
),
84 time_duration_type(not_a_date_time
));
86 else if(day
.is_pos_infinity()) {
87 if(tod
.is_neg_infinity()) {
88 return time_rep_type(date_type(not_a_date_time
),
89 time_duration_type(not_a_date_time
));
92 return time_rep_type(day
, time_duration_type(pos_infin
));
95 else if(day
.is_neg_infinity()) {
96 if(tod
.is_pos_infinity()) {
97 return time_rep_type(date_type(not_a_date_time
),
98 time_duration_type(not_a_date_time
));
101 return time_rep_type(day
, time_duration_type(neg_infin
));
104 else if(tod
.is_pos_infinity()) {
105 if(day
.is_neg_infinity()) {
106 return time_rep_type(date_type(not_a_date_time
),
107 time_duration_type(not_a_date_time
));
110 return time_rep_type(date_type(pos_infin
), tod
);
113 else if(tod
.is_neg_infinity()) {
114 if(day
.is_pos_infinity()) {
115 return time_rep_type(date_type(not_a_date_time
),
116 time_duration_type(not_a_date_time
));
119 return time_rep_type(date_type(neg_infin
), tod
);
123 return time_rep_type(day
, tod
);
125 static date_type
get_date(const time_rep_type
& val
)
127 return date_type(val
.day
);
129 static time_duration_type
get_time_of_day(const time_rep_type
& val
)
131 return time_duration_type(val
.time_of_day
);
133 static std::string
zone_name(const time_rep_type
&)
135 return std::string();
137 static bool is_equal(const time_rep_type
& lhs
, const time_rep_type
& rhs
)
139 return ((lhs
.day
== rhs
.day
) && (lhs
.time_of_day
== rhs
.time_of_day
));
141 static bool is_less(const time_rep_type
& lhs
, const time_rep_type
& rhs
)
143 if (lhs
.day
< rhs
.day
) return true;
144 if (lhs
.day
> rhs
.day
) return false;
145 return (lhs
.time_of_day
< rhs
.time_of_day
);
147 static time_rep_type
add_days(const time_rep_type
& base
,
148 const date_duration_type
& dd
)
150 return time_rep_type(base
.day
+dd
, base
.time_of_day
);
152 static time_rep_type
subtract_days(const time_rep_type
& base
,
153 const date_duration_type
& dd
)
155 return split_timedate_system::get_time_rep(base
.day
-dd
, base
.time_of_day
);
157 static time_rep_type
subtract_time_duration(const time_rep_type
& base
,
158 const time_duration_type
& td
)
160 if(base
.day
.is_special() || td
.is_special())
162 return split_timedate_system::get_time_rep(base
.day
, -td
);
164 if (td
.is_negative()) {
165 time_duration_type td1
= td
.invert_sign();
166 return add_time_duration(base
,td1
);
169 wrap_int_type
day_offset(base
.time_of_day
.ticks());
170 date_duration_type
day_overflow(static_cast<typename
date_duration_type::duration_rep_type
>(day_offset
.subtract(td
.ticks())));
172 return time_rep_type(base
.day
-day_overflow
,
173 time_duration_type(0,0,0,day_offset
.as_int()));
175 static time_rep_type
add_time_duration(const time_rep_type
& base
,
176 time_duration_type td
)
178 if(base
.day
.is_special() || td
.is_special()) {
179 return split_timedate_system::get_time_rep(base
.day
, td
);
181 if (td
.is_negative()) {
182 time_duration_type td1
= td
.invert_sign();
183 return subtract_time_duration(base
,td1
);
186 wrap_int_type
day_offset(base
.time_of_day
.ticks());
187 date_duration_type
day_overflow(static_cast< typename
date_duration_type::duration_rep_type
>(day_offset
.add(td
.ticks())));
189 return time_rep_type(base
.day
+day_overflow
,
190 time_duration_type(0,0,0,day_offset
.as_int()));
192 static time_duration_type
subtract_times(const time_rep_type
& lhs
,
193 const time_rep_type
& rhs
)
195 date_duration_type dd
= lhs
.day
- rhs
.day
;
196 time_duration_type
td(dd
.days()*24,0,0); //days * 24 hours
197 time_duration_type td2
= lhs
.time_of_day
- rhs
.time_of_day
;
199 // return time_rep_type(base.day-dd, base.time_of_day);
204 } } //namespace date_time