[英]How to add chrono::year_month_day to chrono::sys_seconds
Am holding duration's in a year_month_day.我持有年月日的持续时间。 Is there a simple way to add the year_month_day duration to a time_point like sys_seconds?
有没有一种简单的方法可以将 year_month_day 持续时间添加到像 sys_seconds 这样的 time_point?
sys_seconds date1 = {};
sys_seconds dat2 = {};
year_month_day calDuration;
date1 = date2 + calDuration; //error: no match for ‘operator+’
This is chrono catching logic bugs for you at compile-time.这是在编译时为您捕获逻辑错误的时间。 Adding
date2 + calDuration
is akin to adding tomorrow + today.添加
date2 + calDuration
类似于添加明天 + 今天。 It just doesn't make sense.这没有任何意义。 And that's why it is a compile-time error.
这就是为什么它是一个编译时错误。
What you may mean is that you have durations years
, months
and days
.你可能的意思是你有
years
, months
和days
的持续时间。 This is not the same as the similarly named types year
, month
and day
.这与名称相似的类型
year
、 month
和day
不同。 The plural forms are chrono::duration
s, just like minutes
and nanoseconds
.复数 forms 是 chrono
chrono::duration
s,就像minutes
和nanoseconds
一样。 days
is 24h
. days
是24h
。 And years
and months
are the average length of those units in the civil calendar. years
和months
是这些单位在民用日历中的平均长度。
Conversely, the singular forms year
, month
and day
are the calendrical components that give a name to a day in the civil calendar, eg 2020y
, December
, and 18d
.相反,单数 forms
year
、 month
和day
是为民用日历中的一天命名的日历组件,例如2020y
、 December
和18d
。 And it is these singular forms that make up a year_month_day
, eg 2020y/December/18d
.正是这些奇异的 forms 构成了
year_month_day
,例如2020y/December/18d
。
See this SO answer for a deep-dive on the difference between month
and months
.请参阅此 SO 答案以深入了解
month
和months
之间的区别。
There are multiple ways to add the units years
and months
to a time_point
.有多种方法可以将单位
years
和months
添加到time_point
。 See this SO answer for a deep-dive on that topic.请参阅此 SO 答案以深入了解该主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.