1 | #include <boost/date_time/posix_time/posix_time.hpp>
|
---|
2 | #include <boost/date_time/posix_time/posix_time_config.hpp>
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | // Demonstrates the conversion error in boost::date_time::time_resolution_traits
|
---|
6 | // Since v_type is boost::int32_t, even for 64-bit systems like
|
---|
7 | // time_resolution_traits_bi64_impl and time_resolution_traits_adapted64_impl,
|
---|
8 | // date-times whose tick-counts exceed the int32_t limit will overflow.
|
---|
9 | int main()
|
---|
10 | {
|
---|
11 | typedef boost::posix_time::ptime system_time;
|
---|
12 | typedef system_time::date_type date_type;
|
---|
13 | typedef system_time::time_duration_type time_duration_type;
|
---|
14 |
|
---|
15 | date_type d(2038,1,19);
|
---|
16 | time_duration_type td(3,14,8,0);
|
---|
17 | system_time st(system_time(d,td));
|
---|
18 | // snippet found in boost/thread/pthread/timespec.hpp
|
---|
19 | boost::posix_time::time_duration const time_since_epoch =
|
---|
20 | st - boost::posix_time::from_time_t(0);
|
---|
21 | // the typecast error will cause total_seconds to be negative.
|
---|
22 | std::cerr << st << std::endl;
|
---|
23 | std::cerr << time_since_epoch.total_seconds() << std::endl;
|
---|
24 | }
|
---|
25 |
|
---|