quant_dev
quant_dev

Reputation: 6231

Boost.DateTime issue with adding long year durations

I get an exception when adding 3000 years to a valid boost::gregorian::date object.

#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>

int main(void) {
    boost::gregorian::date d1(1500, 6, 1);
    boost::gregorian::date d2(4500, 6, 1);
    const auto duration = boost::gregorian::years(3000);
    std::cout << d1 << " + " << duration.number_of_years() << "Y\n";
    const auto d3 = d1 + duration;
    std::cout << d3 << "\n";
}

I see the first output:

1500-Jun-01 + 3000Y

but then I get the exception Year is out of valid range: 1400..10000. Am I using the duration type wrong? The Boost library version is 1.59. I'm using Visual Studio 2015 (64 bit build).

Upvotes: 0

Views: 623

Answers (1)

quant_dev
quant_dev

Reputation: 6231

It's a bug in Boost::DateTime: https://github.com/boostorg/date_time/pull/41

Upvotes: 1

Related Questions