c++ - 添加长年持续时间的 Boost.DateTime 问题

标签 c++ datetime boost duration

将 3000 年添加到有效的 boost::gregorian::date 对象时出现异常。

#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";
}

我看到第一个输出:

1500-Jun-01 + 3000Y

但随后我得到异常 Year is out of valid range: 1400..10000。我使用的持续时间类型错误吗? Boost 库版本为 1.59。我正在使用 Visual Studio 2015(64 位版本)。

最佳答案

这是 Boost::DateTime 中的一个错误:https://github.com/boostorg/date_time/pull/41

关于c++ - 添加长年持续时间的 Boost.DateTime 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45537280/

相关文章:

c++ - 在 Boost (C++) 中没有类跟踪的派生类序列化

c++ - unique_ptr<>() 初始化会失败吗?

C++ 段错误

c++ - 使用const类型变量的for循环中的堆错误?

php - 在 PHP 中将一种日期格式转换为另一种日期格式

php - datetime PHP 和 MySQL 的值不正确

mysql - 使用 "where"和 "order by"子句为我的 sql 表创建索引以进行查询

c++ - 'boost::make_shared':对重载函数的模糊调用

c++ - Boost Multi-Index 自定义复合键比较器

c++ - Microsoft 如何处理 UTF-16 在其 C++ 标准库实现中是可变长度编码这一事实