Daily bit(e) of C++ | std::chrono - relative "pseudo-dates"
Daily bit(e) of C++ ♻️75, Expressing relative "pseudo-dates" using the C++20 std::chrono date support.
One of the very useful features of the C++20 extension to std::chrono is support for relative "pseudo-dates".
Particularly when working with real-world events, we often describe dates in relative terms, such as the last day in May or the second Friday in June.
Expressing such dates in code without explicit support is cumbersome, as it typically requires hand-rolled logic.
The std::chrono library directly supports expressing the last day and weekday of a month and also supports expressions for the nth weekday of a month (e.g., the 2nd Sunday in June).