from_time_t(t1 + t2) gains incorrect and different results on Windows and Linux
- Dominant language
- C++
- Stars
- 70
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
OS: `Windows 7 x64 `
Compilers: `MSVC 2017 15.9.19`, `GCC 4.9.3`
boost: `1.72.0`
#include
namespace boost_ptime = boost::posix_time;
std::istringstream iss1{ "%H:%M:%S" };
iss1.imbue(std::locale(std::locale::classic(), new boost_ptime::time_input_facet("07:00:00")));
boost_ptime::ptime time_value1;
iss1 >> time_value1;
std::time_t t1 = 0;
if (!time_value1.is_not_a_date_time()) {
t1 = boost_ptime::to_time_t(time_value1);
}
std::istringstream iss2{ "%Y-%m-%d" };
iss2.imbue(std::locale(std::locale::classic(), new boost_ptime::time_input_facet("2019-06-17")));
boost_ptime::ptime time_value2;
iss2 >> time_value2;
std::time_t t2 = 0;
if (!time_value2.is_not_a_date_time()) {
t2 = boost_ptime::to_time_t(time_value2);
}
std::ostringstream oss;
oss.imbue(std::locale(std::locale::classic(), new boost_ptime::time_facet("%d.%m.%y %H:%M:%S")));
boost_ptime::ptime time_value3 = boost_ptime::from_time_t(t1 + t2);
oss << time_value3;
if (!oss.fail()) {
printf("%s\n", oss.str().c_str());
}
On Windows it prints:
```
27.10.18 03:46:08
```
On Linux it crashes (sometimes not, but gains a different result):
```
terminate called after throwing an instance of 'boost::wrapexcept'
what(): Year is out of valid range: 1400..9999
```
The same code over a standard library (`std::get_time`, `std::put_time`) works as expected.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.