chrono::year 对象是如何构造的?
How is a chrono::year Object Constructed?
我刚刚注意到 c++20 is going to have chrono::year
。它的构造函数接受范围内的 int
:[-32767, 32767],但是我不清楚这个参数代表什么。
- 这是否符合
tm_year
的 1900 年起源?
- 或者
time_t
的 1970 年起源?
- 或者它可能在 Anno Domini 中,起点为 0?
编辑:
这是理解 is_leap
函数 chrono::year
提供的含义的关键。没有来源,不清楚这里代表的是哪一年。
在 25.8.1 [time.cal.general]:
The types in 25.8 describe the civil (Gregorian) calendar and its relationship to sys_days
and local_days
.
关于这个的措辞是具有挑战性的,因为其目的是在不冒犯那些遵循其他日历的人的情况下模拟公历(就像 C++ 目前通过 C API 所做的那样)。
我现在还注意到规范中缺少 "proleptic" 一词,应该在重要位置添加。
为了直接回答这个问题,与 std::chrono::year
相关的积分是公元 1582 年教皇格雷戈里所定义的纪元,但 运行 在时间上前后颠倒。在我写这篇文章时,年份是 2018y
.
并且(在下面回答 Jonathan Mee 的评论),这个程序:
#include <chrono>
#include <iostream>
int
main()
{
using namespace std;
using namespace std::chrono;
const auto foo = 2018y;
cout << int{foo} << '\n';
}
输出:
2018
Live demo that you can experiment with with the proviso that the "date.h" 示例实现将内容放在 namespace date
而不是 namespace std::chrono
.
我还应该注意,此软件允许 用户编写的 日历与 std::chrono
系统互操作。这是 Julian calendar. There are a couple more examples here.
的示例
最后,简要说明为什么将当前年份表示为 year{2018}
(Anno Domini),而不是 year{48}
(time_t
的 1970 年起源) ),或 year{118}
(tm_year
的 1900 年起源):
This philosophy用在电影里是歇斯底里的。但是在软件设计中使用时会让人厌烦。这个库试图做预期的事情。
我刚刚注意到 c++20 is going to have chrono::year
。它的构造函数接受范围内的 int
:[-32767, 32767],但是我不清楚这个参数代表什么。
- 这是否符合
tm_year
的 1900 年起源? - 或者
time_t
的 1970 年起源? - 或者它可能在 Anno Domini 中,起点为 0?
编辑:
这是理解 is_leap
函数 chrono::year
提供的含义的关键。没有来源,不清楚这里代表的是哪一年。
在 25.8.1 [time.cal.general]:
The types in 25.8 describe the civil (Gregorian) calendar and its relationship to
sys_days
andlocal_days
.
关于这个的措辞是具有挑战性的,因为其目的是在不冒犯那些遵循其他日历的人的情况下模拟公历(就像 C++ 目前通过 C API 所做的那样)。
我现在还注意到规范中缺少 "proleptic" 一词,应该在重要位置添加。
为了直接回答这个问题,与 std::chrono::year
相关的积分是公元 1582 年教皇格雷戈里所定义的纪元,但 运行 在时间上前后颠倒。在我写这篇文章时,年份是 2018y
.
并且(在下面回答 Jonathan Mee 的评论),这个程序:
#include <chrono>
#include <iostream>
int
main()
{
using namespace std;
using namespace std::chrono;
const auto foo = 2018y;
cout << int{foo} << '\n';
}
输出:
2018
Live demo that you can experiment with with the proviso that the "date.h" 示例实现将内容放在 namespace date
而不是 namespace std::chrono
.
我还应该注意,此软件允许 用户编写的 日历与 std::chrono
系统互操作。这是 Julian calendar. There are a couple more examples here.
最后,简要说明为什么将当前年份表示为 year{2018}
(Anno Domini),而不是 year{48}
(time_t
的 1970 年起源) ),或 year{118}
(tm_year
的 1900 年起源):
This philosophy用在电影里是歇斯底里的。但是在软件设计中使用时会让人厌烦。这个库试图做预期的事情。