Example
constexpr auto thanksgiving = November / 25 / 2021y;
static_assert(year(2021) == thanksgiving.year());
static_assert(month(11) == thanksgiving.month());
static_assert(day(25) == thanksgiving.day());
Puzzle
- Can you apply std::chrono data time utilities to verify Thanksgiving dates?
constexpr auto thanksgiving = November / 25 / 2021y;
constexpr auto cpptipday = 21d / 11 / 2021;
static_assert( /*is thanksgivng a valid date?*/);
static_assert(Thursday == /*what day is thanksgiving?*/);
static_assert(days(4) == /*how many days to thanksgivnig from cpptipday?*/);
static_assert(25d / November/ 2022 == /*when will be thankgiving next year?*/);
Solutions
static_assert(thanksgiving.ok() /*is thanksgiving a valid date?*/);
static_assert(Thursday == weekday{sys_days{thanksgiving}} /*what day is thanksgiving?*/);
static_assert(days(4) == sys_days{thanksgiving} - sys_days{cpptipday} /*how many days to thanksgiving from cpptipday?*/);
static_assert(24d / November/ 2022 == sys_days{Thursday[4] / November / 2022} /*when will be thanksgiving next year?*/);
static_assert(thanksgiving.ok());
static_assert(Thursday == weekday{sys_days(thanksgiving)});
static_assert(days(4) == thanksgiving.day() - cpptipday.day());
static_assert(25d / November/ 2022 == thanksgiving + years(1));
static_assert(thanksgiving.ok() /*is thanksgivng a valid date?*/);
static_assert(Thursday == weekday{thanksgiving} /*what day is thanksgiving?*/);
static_assert(days(4) == thanksgiving.day() - cpptipday.day() /*how many days to thanksgiving from cpptipday?*/);
static_assert(24d / November/ 2022 == sys_days{2022y / November/ Thursday[4]} /*when will be thankgiving next year?*/);