Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 2.22 KB

253.md

File metadata and controls

63 lines (44 loc) · 2.22 KB
Info

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());

https://godbolt.org/z/eda4d35xT

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?*/);

https://godbolt.org/z/6h755jqPE

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?*/);

https://jonathan.godbolt.org/z/G6T4zEKn1

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));

https://godbolt.org/z/e37KPxGbv

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?*/);

https://godbolt.org/z/qKcE4x373