1
1
---
2
2
description : " Learn more about: <chrono> operators"
3
3
title : " <chrono> operators"
4
- ms.date : " 08/13 /2021"
5
- f1_keywords: ["chrono/std::operator modulo", "chrono/std::operator+", "chrono/std::chrono::day::operator+", "chrono/std::chrono::duration::operator+", "chrono/std::chrono::month::operator+", "chrono/std::chrono::time_point::operator+", "chrono/std::chrono::weekday::operator+", "chrono/std::chrono::year_month::operator+", "chrono/std::chrono::year::operator+", "chrono/std::chrono::year_month_day::operator+", "chrono/std::chrono::year_month_day_last::operator+", "chrono/std::chrono::year_month_weekday::operator+", "chrono/std::chrono::year_month_weekday_last::operator+", "chrono/std::operator!=", "chrono/std::operator*", "chrono/std::operator/", "chrono/std::operator-", "chrono/std::operator<", "chrono/std::operator<=", "chrono/std::operator<", "chrono/std::operator==", "chrono/std::operator>>", "chrono/std::operator<=>", "chrono/std::chrono::day::operator<=>", "chrono/std::chrono::month::operator<=>", "chrono/std::chrono::year::operator<=>", "chrono/std::chrono::year_month::operator<=>", "chrono/std::chrono::time_point::operator<=>", "chrono/std::chrono::duration::operator<=>", "chrono/std::chrono::month_day_last::operator<=>", "chrono/std::chrono::year_month_day_last::operator<=>", "chrono/std::operator==", "chrono/std::chrono::year::operator<==>", "chrono/std::chrono::day::operator==", "chrono/std::chrono::duration::operator==", "chrono/std::chrono::month::operator==", "chrono/std::chrono::month_day::operator==", "chrono/std::chrono::month_day_last::operator==", "chrono/std::chrono::month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::time_point::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year_month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::weekday_last::operator==", "chrono/std::chrono::year_month_weekday_indexed::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::operator-", "chrono/std::chrono::day::operator-", "chrono/std::chrono::duration::operator-", "chrono/std::chrono::month::operator-", "chrono/std::chrono::time_point::operator-", "chrono/std::chrono::weekday::operator-", "chrono/std::chrono::year_month::operator-", "chrono/std::chrono::year::operator-", "chrono/std::chrono::year_month_day::operator-", "chrono/std::chrono::year_month_day_last::operator-", "chrono/std::chrono::year_month_weekday::operator-", "chrono/std::chrono::year_month_weekday_last::operator-", "chrono/std::chrono::day::operator<<", "chrono/std::chrono::hh_mm_ss::operator<<", "chrono/std::chrono::month_day::operator<<", "chrono/std::chrono::month_day_last::operator<<", "chrono/std::chrono::month_weekday::operator<<", "chrono/std::chrono::month_weekday_last::operator<<", "chrono/std::chrono::weekday::operator<<", "chrono/std::chrono::weekday_indexed::operator<<", "chrono/std::chrono::weekday_last::operator<<", "chrono/std::chrono::year::operator<<", "chrono/std::chrono::year_month_day::operator<<", "chrono/std::chrono::year_month_day_last::operator<<", "chrono/std::chrono::year_month_weekday::operator<<", "chrono/std::chrono::utc_time::operator<<", "chrono/std::chrono::tai_time::operator<<", "chrono/std::chrono::gps_time::operator<<", "chrono/std::chrono::local_time::operator<<", "chrono/std::chrono::file_time::operator<<"]
4
+ ms.date : 09/02 /2021
5
+ f1_keywords: ["chrono/std::operator modulo", "chrono/std::operator+", "chrono/std::chrono::day::operator+", "chrono/std::chrono::duration::operator+", "chrono/std::chrono::month::operator+", "chrono/std::chrono::time_point::operator+", "chrono/std::chrono::weekday::operator+", "chrono/std::chrono::year_month::operator+", "chrono/std::chrono::year::operator+", "chrono/std::chrono::year_month_day::operator+", "chrono/std::chrono::year_month_day_last::operator+", "chrono/std::chrono::year_month_weekday::operator+", "chrono/std::chrono::year_month_weekday_last::operator+", "chrono/std::operator!=", "chrono/std::operator*", "chrono/std::operator/", "chrono/std::operator-", "chrono/std::operator<", "chrono/std::operator<=", "chrono/std::operator<", "chrono/std::operator==", "chrono/std::operator>>", "chrono/std::operator<=>", "chrono/std::chrono::day::operator<=>", "chrono/std::chrono::month::operator<=>", "chrono/std::chrono::year::operator<=>", "chrono/std::chrono::year_month::operator<=>", "chrono/std::chrono::time_point::operator<=>", "chrono/std::chrono::time_zone_link::operator<=>", "chrono/std::chrono::time_zone_link::operator==", "chrono/std::chrono::duration::operator<=>", "chrono/std::chrono::month_day_last::operator<=>", "chrono/std::chrono::year_month_day_last::operator<=>", "chrono/std::operator==", "chrono/std::chrono::year::operator<==>", "chrono/std::chrono::day::operator==", "chrono/std::chrono::duration::operator==", "chrono/std::chrono::month::operator==", "chrono/std::chrono::month_day::operator==", "chrono/std::chrono::month_day_last::operator==", "chrono/std::chrono::month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::time_point::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year_month_weekday::operator==", "chrono/std::chrono::month_weekday_last::operator==", "chrono/std::chrono::weekday::operator==", "chrono/std::chrono::weekday_last::operator==", "chrono/std::chrono::year_month_weekday_indexed::operator==", "chrono/std::chrono::year_month_weekday_last::operator==", "chrono/std::chrono::year::operator==", "chrono/std::chrono::year_month::operator==", "chrono/std::chrono::year_month_day::operator==", "chrono/std::chrono::year_month_day_last::operator==", "chrono/std::operator-", "chrono/std::chrono::day::operator-", "chrono/std::chrono::duration::operator-", "chrono/std::chrono::month::operator-", "chrono/std::chrono::time_point::operator-", "chrono/std::chrono::weekday::operator-", "chrono/std::chrono::year_month::operator-", "chrono/std::chrono::year::operator-", "chrono/std::chrono::year_month_day::operator-", "chrono/std::chrono::year_month_day_last::operator-", "chrono/std::chrono::year_month_weekday::operator-", "chrono/std::chrono::year_month_weekday_last::operator-", "chrono/std::chrono::day::operator<<", "chrono/std::chrono::hh_mm_ss::operator<<", "chrono/std::chrono::month_day::operator<<", "chrono/std::chrono::month_day_last::operator<<", "chrono/std::chrono::month_weekday::operator<<", "chrono/std::chrono::month_weekday_last::operator<<", "chrono/std::chrono::weekday::operator<<", "chrono/std::chrono::weekday_indexed::operator<<", "chrono/std::chrono::weekday_last::operator<<", "chrono/std::chrono::year::operator<<", "chrono/std::chrono::year_month_day::operator<<", "chrono/std::chrono::year_month_day_last::operator<<", "chrono/std::chrono::year_month_weekday::operator<<", "chrono/std::chrono::utc_time::operator<<", "chrono/std::chrono::tai_time::operator<<", "chrono/std::chrono::gps_time::operator<<", "chrono/std::chrono::local_time::operator<<", "chrono/std::chrono::file_time::operator<<"]
6
6
---
7
7
# ` <chrono> ` operators
8
8
@@ -109,7 +109,7 @@ constexpr year_month_weekday_last operator+(const years& dy, const year_month_we
109
109
110
110
4\) Returns the result of `d+ds.count()`. If the result is out of the range [0, 255], then the result is unspecified.
111
111
112
- 5\) Returns the result of `m+ms.count()`. If the result is out of the range [1, 12], it's reduced modulo 12 and then +1.
112
+ 5\) Returns the result of `m+ms.count()`. If the result is out of the range [1, 12], it's reduced modulo 12 and then +1.
113
113
114
114
6\) Returns the result of adding the number of days/weekdays to the `weekday`. The result will be modulo 7, so always in the range \[0,6]
115
115
@@ -119,7 +119,7 @@ constexpr year_month_weekday_last operator+(const years& dy, const year_month_we
119
119
120
120
9\) Returns the result of adding months or years to a `year_month_day`. If `ymd.month()` is `February` and `ymd.day()` is not in the range [1d, 28d], `ok()` may return `false` for the result of the addition.
121
121
122
- 10\) Returns `(ymdl.year() / ymdl.month() + dm) / last`. Note: The `/` used here is not a division operator but the date operator.
122
+ 10\) Returns `(ymdl.year() / ymdl.month() + dm) / last`. Note: The `/` used here isn't a division operator but the date operator.
123
123
124
124
11\) Returns `ymdl + dm`.
125
125
@@ -129,7 +129,7 @@ constexpr year_month_weekday_last operator+(const years& dy, const year_month_we
129
129
130
130
14-15\) Returns `{ymwd.year()+dy, ymwd.month(), ymwd.weekday_indexed()}`.
131
131
132
- 16\) Returns `(ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last()`. Note: The `/` used here is not a division operator but the date operator.
132
+ 16\) Returns `(ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last()`. Note: The `/` used here isn't a division operator but the date operator.
133
133
134
134
17\) Returns: `ymwdl + dy`
135
135
@@ -307,9 +307,9 @@ constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl
307
307
308
308
10\) Returns `years(int(y) - int(y2))`. Subtracting two `year` values results in a `std::chrono::years`, which represents the difference in years between `y` and `y2`. For example, `2021y-2000y` produces `years(21)`.
309
309
310
- 11\) Returns the result of subtracting a number of months or years from a `year_month` value.
310
+ 11\) Returns the result of subtracting months or years from a `year_month` value.
311
311
312
- 12\) Returns the result of subtracting a number of months years from a `year_month_day` value.
312
+ 12\) Returns the result of subtracting months years from a `year_month_day` value.
313
313
314
314
13\) Returns the result of subtracting the number of months from the `year_month_day_last` value. Essentially: `ymdl-dm`.
315
315
@@ -567,7 +567,8 @@ Determines whether:
567
567
14\) [ ` year_month_day ` ] ( year-month-day-class.md ) represent the same year, month, and day.\
568
568
15\) [ ` year_month_day_last ` ] ( year-month-day-last-class.md ) represent the same last day of the year and month.\
569
569
16\) [ ` year_month_weekday ` ] ( year-month-weekday-class.md ) represent the same weekday, year, and month.\
570
- 17\) [ ` year_month_weekday_last ` ] ( year-month-weekday-last-class.md ) represent the same last weekday of the month, year, and month.
570
+ 17\) [ ` year_month_weekday_last ` ] ( year-month-weekday-last-class.md ) represent the same last weekday of the month, year, and month.\
571
+ 18\) [ ` time_zone_link ` ] ( time-zone-link-class.md ) have the same ` name ` . The ` target ` name isn't considered.
571
572
572
573
``` cpp
573
574
// 1) duration<Rep, Period>
@@ -626,6 +627,9 @@ constexpr bool operator==(const year_month_weekday& Left, const year_month_weekd
626
627
627
628
// 17) year_month_weekday_last
628
629
constexpr bool operator==(const year_month_weekday_last& Left, const year_month_weekday_last& Right) noexcept; // C++ 20
630
+
631
+ // 18) time_zone_link
632
+ bool operator==(const time_zone_link& Left, const time_zone_link& Right) noexcept;
629
633
```
630
634
631
635
### Parameters
@@ -638,9 +642,10 @@ The right object to compare.
638
642
639
643
### Return value
640
644
641
- 1\) Returns **`true`** if *`Left`* and *`Right`* represent time intervals that have the same length. Otherwise, the function returns **`false`**.\
645
+ 1\) Returns **`true`** if *`Left`* and *`Right`* represent time intervals that have the same length. Otherwise, returns **`false`**.\
642
646
2\) Returns **`true`** if *`Left`* and *`Right`* represent the same point in time. Otherwise, returns **`false`**.\
643
- 3-17\) Returns **`true`** if *`Left`* and *`Right`* have the same value. Otherwise, returns **`false`**.
647
+ 3-17\) Returns **`true`** if *`Left`* and *`Right`* have the same value. Otherwise, returns **`false`**.\
648
+ 18\) Returns **`true`** if `Left.name() == Right.name()`. Otherwise, returns `*false*`.
644
649
645
650
## <a name="op_gt"></a> `operator>`
646
651
@@ -708,6 +713,7 @@ The spaceship operator, in conjunction with `operator==`, synthesizes operators
708
713
- [`month_day`](month-day-class.md)
709
714
- [`month_day_last`](month-day-last-class.md)
710
715
- [`time_point`](time-point-class.md)
716
+ - [`time_zone_link`](time-zone-link-class.md)
711
717
- [`year`](year-class.md)
712
718
- [`year_month`](year-month-class.md)
713
719
- [`year_month_day_last`](year-month-day-last-class.md)
@@ -736,12 +742,15 @@ constexpr strong_ordering operator<=>(const month_day_last& Left, const month_da
736
742
737
743
// 3)
738
744
constexpr strong_ordering operator<=>(const year_month_day_last& Left, const year_month_day_last& Right) noexcept;
745
+
746
+ //4)
747
+ strong_ordering operator<=>(const time_zone_link& Left, const time_zone_link& Right) noexcept;
739
748
```
740
749
741
750
### Parameters
742
751
743
752
* ` Left ` , ` Right ` * \
744
- The [ ` day ` ] ( day-class.md ) , [ ` duration ` ] ( duration-class.md ) , [ ` month ` ] ( month-class.md ) , [ ` month_day ` ] ( month-day-class.md ) , [ ` month_day_last ` ] ( month-day-last-class.md ) , [ ` time_point ` ] ( time-point-class.md ) , [ ` year ` ] ( year-class.md ) , [ ` year_month ` ] ( year-month-class.md ) , [ ` year_month_day ` ] ( year-month-day-class.md ) , [ ` year_month_day_last ` ] ( year-month-day-last-class.md ) to compare.
753
+ The [ ` day ` ] ( day-class.md ) , [ ` duration ` ] ( duration-class.md ) , [ ` month ` ] ( month-class.md ) , [ ` month_day ` ] ( month-day-class.md ) , [ ` month_day_last ` ] ( month-day-last-class.md ) , [ ` time_point ` ] ( time-point-class.md ) , [ ` time_zone_link ` ] ( time-zone-link-class.md ) , [ ` year ` ] ( year-class.md ) , [ ` year_month ` ] ( year-month-class.md ) , [ ` year_month_day ` ] ( year-month-day-class.md ) , [ ` year_month_day_last ` ] ( year-month-day-last-class.md ) to compare.
745
754
746
755
### Return value
747
756
@@ -761,6 +770,12 @@ if (auto c = Left.year() <=> Right.year(); c != 0) return c;
761
770
return Left.month_day_last() <=> Right.month_day_last();
762
771
```
763
772
773
+ 4\) \
774
+ Equivalent to:
775
+ ``` cpp
776
+ Left.name() <=> Right.name()
777
+ ```
778
+
764
779
### Example: ` operator<=> `
765
780
766
781
``` cpp
0 commit comments