std::chrono:: operator+, std::chrono:: operator- (std::chrono::month)
|
|
Time point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Time of day | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Calendar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Time zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono
I/O
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C-style date and time |
Member functions | ||||
Nonmember functions | ||||
operator+
operator-
|
||||
Helper classes | ||||
(C++26)
|
Defined in header
<chrono>
|
||
constexpr
std::
chrono
::
month
operator
+
(
const
std::
chrono
::
month
&
m,
const std:: chrono :: months & ms ) noexcept ; |
(1) | (since C++20) |
constexpr
std::
chrono
::
month
operator
+
(
const
std::
chrono
::
months
&
ms,
const std:: chrono :: month & m ) noexcept ; |
(2) | (since C++20) |
constexpr
std::
chrono
::
month
operator
-
(
const
std::
chrono
::
month
&
m,
const std:: chrono :: months & ms ) noexcept ; |
(3) | (since C++20) |
constexpr
std::
chrono
::
months
operator
-
(
const
std::
chrono
::
month
&
m1,
const std:: chrono :: month & m2 ) noexcept ; |
(4) | (since C++20) |
[
0
,
11
]
, and then adding 1.
[
0
,
11
]
and
m2
+
m
==
m1
. Otherwise the returned value is unspecified.
Return value
Notes
As long as the computation doesn't overflow, (1-3) always return a valid month even if m. ok ( ) is false .
The result of subtracting two
month
values is a duration of type
std::chrono::months
. That duration unit represents the length of the average Gregorian month, and the resulting duration bears no relationship to the number of days in the particular months represented by the operands. For example,
std::
chrono
::
seconds
(
std::
chrono
::
April
-
std::
chrono
::
March
)
is not the number of seconds in March (
2678400s
), but
2629746s
(30.436875 days).
Example
#include <cassert> #include <chrono> int main() { std::chrono::month m{6}; m = m + std::chrono::months(2); assert(m == std::chrono::month(8)); m = m - std::chrono::months(3); assert(m == std::chrono::month(5)); constexpr std::chrono::months ms = std::chrono::month(8) - std::chrono::month(6); static_assert(ms == std::chrono::months(2)); }
See also
increments or decrements the month
(public member function) |
|
adds or subtracts a number of months
(public member function) |