| 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 day [time.cal.year_month_day] |
| 21 |
|
| 22 |
#include <chrono> |
| 23 |
|
| 24 |
constexpr void |
| 25 |
constexpr_year_month_day() |
| 26 |
{ |
| 27 |
using namespace std::chrono; |
| 28 |
using ymd = year_month_day; |
| 29 |
|
| 30 |
constexpr ymd ymd1{year{1984}, August, 3d}; |
| 31 |
static_assert(ymd1.ok()); |
| 32 |
static_assert(ymd1.year() == year{1984}); |
| 33 |
static_assert(ymd1.month() == August); |
| 34 |
static_assert(ymd1.day() == 3d); |
| 35 |
//static_assert(sys_days(ymd1) == time_point_cast<days>(days{5356})); |
| 36 |
//static_assert(local_days(ymd1) == time_point_cast<days>(days{5356})); |
| 37 |
|
| 38 |
static_assert(2015y/August/14d == ymd{year{2015}, month{8}, day{14}}); |
| 39 |
static_assert(2015y/August/14 == ymd{year{2015}, month{8}, day{14}}); |
| 40 |
static_assert(2015y/(August/14d) == ymd{year{2015}, month{8}, day{14}}); |
| 41 |
static_assert(2015/(August/14d) == ymd{year{2015}, month{8}, day{14}}); |
| 42 |
static_assert(August/14d/2015y == ymd{year{2015}, month{8}, day{14}}); |
| 43 |
static_assert(August/14d/2015 == ymd{year{2015}, month{8}, day{14}}); |
| 44 |
|
| 45 |
static_assert(((ymd{1000y, January, 1d} += months{1}) += years{1}) |
| 46 |
== February/1d/1001y); |
| 47 |
static_assert(((ymd{1000y, January, 1d} -= years{1}) -= months{1}) |
| 48 |
== December/1d/998y); |
| 49 |
|
| 50 |
static_assert(!ymd{1000y, February, 30d}.ok()); |
| 51 |
|
| 52 |
static_assert(June/1d/1977y == June/1d/1977y); |
| 53 |
static_assert(June/1d/1977y != June/1d/1987y); |
| 54 |
static_assert(May/15d/1950y <=> May/15d/1950y == std::strong_ordering::equal); |
| 55 |
static_assert(May/15d/1950y <=> May/14d/1950y == std::strong_ordering::greater); |
| 56 |
static_assert(April/15d/1950y <=> May/14d/1950y == std::strong_ordering::less); |
| 57 |
|
| 58 |
static_assert(January/1d/1900y + months{13} == February/1d/1901y); |
| 59 |
static_assert(months{13} + January/1d/1900y == February/1d/1901y); |
| 60 |
static_assert(January/1d/1900y + years{1} == January/1d/1901y); |
| 61 |
static_assert(years{1} + January/1d/1900y == January/1d/1901y); |
| 62 |
static_assert(January/1d/1900y - months{13} == December/1d/1898y); |
| 63 |
static_assert(January/1d/1900y - years{1} == January/1d/1899y); |
| 64 |
|
| 65 |
// N.B. unix seems to be a macro somewhere! |
| 66 |
constexpr ymd myunix = 1970y/1/1; |
| 67 |
static_assert(myunix.ok()); |
| 68 |
static_assert(myunix.year() == year{1970}); |
| 69 |
static_assert(myunix.month() == January); |
| 70 |
static_assert(myunix.day() == day{1}); |
| 71 |
static_assert(sys_days(myunix).time_since_epoch() == days{0}); |
| 72 |
//static_assert(local_days(myunix) == time_point_cast<days>(days{0})); |
| 73 |
|
| 74 |
static_assert(sys_days{August/20d/2020y}.time_since_epoch() == days{18494}); |
| 75 |
|
| 76 |
static_assert(ymd{sys_days{2017y/January/0}} == 2016y/December/31); |
| 77 |
static_assert(ymd{sys_days{2017y/January/31}} == 2017y/January/31); |
| 78 |
static_assert(ymd{sys_days{2017y/January/32}} == 2017y/February/1); |
| 79 |
static_assert(ymd{sys_days{2017y/33/59 + months{0}}} == 2019y/10/29); |
| 80 |
|
| 81 |
static_assert(ymd{local_days{2017y/January/0}} == 2016y/December/31); |
| 82 |
static_assert(ymd{local_days{2017y/January/31}} == 2017y/January/31); |
| 83 |
static_assert(ymd{local_days{2017y/January/32}} == 2017y/February/1); |
| 84 |
static_assert(ymd{local_days{2017y/33/59 + months{0}}} == 2019y/10/29); |
| 85 |
|
| 86 |
static_assert((2000y/February/29d).ok()); |
| 87 |
static_assert(!(2001y/February/29d).ok()); |
| 88 |
static_assert(!(2100y/February/29d).ok()); |
| 89 |
static_assert(!(1999y/February/29d).ok()); |
| 90 |
} |