std::chrono::operator/(calendar) - cppreference.com
Namespaces
Variants

std::chrono::operator/(calendar)

From cppreference.com
 
 
 

These operator/ overloads provide a conventional syntax for the creation of Proleptic Gregorian calendar dates.

For creation of a full date, any of the following three orders are accepted:

  • year/month/day,
  • month/day/year,
  • day/month/year.

In each case day can replaced with one of:

  • std::chrono::last, for the last day of the month;
  • weekday[i], for the ith weekday of the month;
  • weekday[std::chrono::last], for the last weekday of the month.

A plain integer is accepted if its meaning is unambiguous from the types of other operands: 2005y/4/5 is allowed, but 5/April/2005 is not.

Partial-date types (year_month, month_day, etc.) can be created by not applying the second operator/ in any of the three orders.

Return value

1) std::chrono::year_month(y, m)
2) std::chrono::year_month(y, std::chrono::month(m))
3,6) std::chrono::month_day(m, d)
4) std::chrono::month_day(m, std::chrono::day(d))
5,7) std::chrono::month_day(std::chrono::month(m), d)
8,10) std::chrono::month_day_last(m)
9,11) std::chrono::month_day_last(std::chrono::month(m))
12,14) std::chrono::month_weekday(m, wdi)
13,15) std::chrono::month_weekday(std::chrono::month(m), wdi)
16,18) std::chrono::month_weekday_last(m, wdl)
17,19) std::chrono::month_weekday_last(std::chrono::month(m), wdl)
20) std::chrono::year_month_day(ym.year(), ym.month(), d)
21) std::chrono::year_month_day(ym.year(), ym.month(), std::chrono::day(d))
22,24) std::chrono::year_month_day(y, md.month(), md.day())
23,25) std::chrono::year_month_day(std::chrono::year(y), md.month(), md.day())
26) std::chrono::year_month_day_last(ym.year(), std::chrono::month_day_last(ym.month()))
27,29) std::chrono::year_month_day_last(y, mdl)
28,30) std::chrono::year_month_day_last(std::chrono::year(y), mdl)
31) std::chrono::year_month_weekday(ym.year(), ym.month(), wdi)
32,34) std::chrono::year_month_weekday(y, mwd.month(), mwd.weekday_indexed())
33,35) std::chrono::year_month_weekday(std::chrono::year(y), mwd.month(), mwd.weekday_indexed())
36) std::chrono::year_month_weekday_last(ym.year(), ym.month(), wdl)
37,39) std::chrono::year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last())
38,40) std::chrono::year_month_weekday_last(std::chrono::year(y), mwdl.month(), mwdl.weekday_last())

Example

#include <chrono>
using namespace std::chrono;

constexpr auto ym{2021y/8};
static_assert(ym == year_month(year(2021), August));

constexpr auto md{9/15d};
static_assert(md == month_day(September, day(15)));

constexpr auto mdl{October/last};
static_assert(mdl == month_day_last(month(10)));

constexpr auto mw{11/Monday[3]};
static_assert(mw == month_weekday(November, Monday[3]));

constexpr auto mwdl{December/Sunday[last]};
static_assert(mwdl == month_weekday_last(month(12), weekday_last(Sunday)));

// Those 3 year/month/day orders that people actually use on this planet and beyond:
constexpr auto ymd{year(2021)/January/day(23)};
static_assert(ymd == month{1}/23/2021);
static_assert(ymd == day{23}/1/2021);
static_assert(ymd == year_month_day(2021y, month(January), 23d));

int main() {}