chrono :: year对象如何构造? [英] How is a chrono::year Object Constructed?

查看:88
本文介绍了chrono :: year对象如何构造?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到c ++ 20 将具有 chrono ::年 。它的构造函数采用 int 的范围为 [-32767,32767] ,但是我不清楚此参数表示什么。

I just noticed that c++20 is going to have chrono::year. It's constructor takes in an int in the range: [-32767, 32767], however I am unclear what this argument represents.

  • Would this be consistent with tm_year's 1900 origin?
  • Or perhaps time_t's 1970 origin?
  • Or perhaps it's in Anno Domini with a 0 origin?

编辑:

这对于理解< a href = https://en.cppreference.com/w/cpp/chrono/year/is_leap rel = nofollow noreferrer> is_leap 函数 chrono :: year 优惠。没有起源,目前尚不清楚是哪一年。


This is key to the understanding of what is meant by the is_leap function chrono::year offers. Without an origin it's unclear what year is represented here.

推荐答案

在25.8.1 [time.cal.general]中:

In 25.8.1 [time.cal.general]:


25.8中的类型描述了民用(格里高利历)日历及其与 sys_days local_days

关于此措辞的意图是具有挑战性的是要为公历建模(就像目前通过C API的C ++一样),而不会冒犯遵循其他日历的人。

The wording on this was (is) challenging as the intent is to model the Gregorian calendar (as does C++ currently via the C API) without offending those who follow other calendars.

我现在也注意到了 proleptic ,应该将其添加到战略位置。

I also am just now noting that the word "proleptic" is missing from the spec, and should probably be added in a strategic spot.

要直接回答这个问题,与 std :: chrono :: year 相关的积分是Anno Domini参考,定义如下由教皇格里高利(1582年)创作,但时间上来回向前和向后。在我撰写本文时,年份是 2018y

To directly answer the question, the integral associated with std::chrono::year is the Anno Domini reference, as defined by Pope Gregory in 1582, but running both backwards and forwards in time. As I write this, the year is 2018y.

然后(回答下面的乔纳森·米的评论),该程序是:

And (answering Jonathan Mee's comment below), this program:

#include <chrono>
#include <iostream>

int
main()
{
    using namespace std;
    using namespace std::chrono;
    const auto foo = 2018y;
    cout << int{foo} << '\n';
}

输出:

2018

您可以试用的实时演示,条件是 date.h 示例实现将内容放入命名空间日期而不是命名空间std :: chrono

Live demo that you can experiment with with the proviso that the "date.h" example implementation puts things in namespace date instead of namespace std::chrono.

我还应注意,该软件允许用户编写的日历与 std互操作:: chrono 系统。这是朱利安日历的示例。 此处

I should also note that this software allows for user-written calendars to interoperate with the std::chrono system. Here is an example of the Julian calendar. There are a couple more examples here.

最后,简要说明一下为什么将本年度表示为 year {2018} 的理由(Anno Domini) ,而不是 year {48} time_t 的1970年起源)或 year {118} tm_year 的1900年起源):

Finally, a brief note on the rationale as to why the current year is represented as year{2018} (Anno Domini), as opposed to year{48} (time_t's 1970 origin), or year{118} (tm_year's 1900 origin):

在电影中使用时,这种哲学是歇斯底里的。但是在软件设计中使用时会很累。该库尝试执行预期的操作。

This philosophy is hysterical when used in movies. But gets tiresome when used in software design. This library tries to do the expected.

这篇关于chrono :: year对象如何构造?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆