| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | // Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // Class template month_day [time.cal.month_day] |
| 21 | |
| 22 | #include <chrono> |
| 23 | |
| 24 | constexpr void |
| 25 | constexpr_year_month_weekday_last() |
| 26 | { |
| 27 | using namespace std::chrono; |
| 28 | using ymwdl = year_month_weekday_last; |
| 29 | |
| 30 | constexpr ymwdl ymwdl1 = {2015y, August, weekday_last{Friday}}; |
| 31 | static_assert(ymwdl1.ok()); |
| 32 | static_assert(ymwdl1.year() == 2015y); |
| 33 | static_assert(ymwdl1.month() == August); |
| 34 | static_assert(ymwdl1.weekday() == Friday); |
| 35 | static_assert(ymwdl1.weekday_last() == Friday[last]); |
| 36 | static_assert(year_month_day{sys_days{ymwdl1}} == 2015y/August/28d); |
| 37 | static_assert(year_month_day{local_days{ymwdl1}} == 2015y/August/28d); |
| 38 | |
| 39 | static_assert(2015y/August/Friday[last] == ymwdl{year{2015}, month{8}, weekday_last{weekday{5u}}}); |
| 40 | static_assert(2015y/(August/Friday[last]) == ymwdl{year{2015}, month{8}, weekday_last{weekday{5u}}}); |
| 41 | static_assert(2015/(August/Friday[last]) == ymwdl{year{2015}, month{8}, weekday_last{weekday{5u}}}); |
| 42 | static_assert(August/Friday[last]/2015y == ymwdl{year{2015}, month{8}, weekday_last{weekday{5u}}}); |
| 43 | static_assert(August/Friday[last]/2015 == ymwdl{year{2015}, month{8}, weekday_last{weekday{5u}}}); |
| 44 | |
| 45 | static_assert((ymwdl{ymwdl1} += months{5} -= months{5}) == ymwdl1); |
| 46 | static_assert((ymwdl{ymwdl1} += years{5} -= years{5}) == ymwdl1); |
| 47 | |
| 48 | static_assert(ymwdl1 + months{10} == 2016y/June/Friday[last]); |
| 49 | static_assert(months{10} + ymwdl1 == ymwdl1 + months{10}); |
| 50 | static_assert(ymwdl1 - months{10} == 2014y/October/Friday[last]); |
| 51 | |
| 52 | static_assert(ymwdl1 + years{10} == 2025y/August/Friday[last]); |
| 53 | static_assert(years{10} + ymwdl1 == ymwdl1 + years{10}); |
| 54 | static_assert(ymwdl1 - years{10} == 2005y/August/Friday[last]); |
| 55 | |
| 56 | constexpr ymwdl ymwdl2 = Saturday[last]/August/2015y; |
| 57 | static_assert(ymwdl2.ok()); |
| 58 | static_assert(ymwdl1 == ymwdl1); |
| 59 | static_assert(ymwdl1 != ymwdl2); |
| 60 | } |