Hi. Since time_duration uses <long> to represent each of the fields (H:M:S:FS), I should be able to add any hour offset to a ptime, as long as the resultant ptime is inside the date/time range representable by boost? With the date ranges of boost being 1400-Jan-1 00:00:00 -> 10000-Jan-1 00:00:00, the number of hours between these dates is (very roughly!) 7.534E7. This is less than the <long> limit on my system, which is +/- 2.147E9. That is good. So; doing the following: ptime t_max( date(10000,Jan,1) ); ptime t_min( date(1400,Jan,1) ); time_duration td = t_max - t_min; std::cout << to_simple_string( td ) << std::endl; should produce something like : 7.534E7:0:0 or if you want to write it out: 7533600:0:0 not? Instead; the output I get is : 224112:19:12. This corresponds to a timespan of roughly 25 years which means I just ran into some overflow/underflow problem somewhere. What gives? What time range is supported by time_duration if it does not use the <long> limits? I have difficulty deducing this information from the header files, the source for the lib is not too helpfull either! What am I missing here? Greetings, Andre.
Since time_duration uses <long> to represent each of the fields (H:M:S:FS), I should be able to add any hour offset to a ptime, as long as the resultant ptime is inside the date/time range representable by boost?
With the date ranges of boost being 1400-Jan-1 00:00:00 -> 10000-Jan-1 00:00:00, the number of hours between these dates is (very roughly!) 7.534E7. This is less than the <long> limit on my system, which is +/- 2.147E9. That is good.
Yes, but the resolution of the time_duration is much higher than hours. Depending on your library configuration it is either microseconds or nano-seconds. So you need to multiply your number of hours by 10^6 or 10^9 for the value represented internally. Internally the duration uses a 64 bit integer. So, all and all the range is about 2 million hours. The following program will print out the resolution based on your settings: #include "boost/date_time/posix_time/posix_time.hpp" #include <iostream> //Must match with time_resolutions enum in date_time/time_defs.h const char* const resolution_names[] = {"Second", "Deci", "Centi", "Milli", "Ten_Thousanth", "Micro", "Nano"}; int main() { using namespace boost::posix_time; std::cout << "Resolution: " << resolution_names[time_duration::rep_type::resolution()] << " -- Ticks per second: " << time_duration::rep_type::res_adjust() << std::endl; } Just to confuse things more there is a bug in 1.29 and 1.30 that causes the conversion calculation to be rounded down to a long thus limiting the range of the internal calculation. There is a fix in date_time/time_resolution_traits.hpp in CVS if you want to patch your install. Jeff
participants (2)
-
Andre du Toit
-
Jeff Garland