From 5b08c1742a536f54bd5e270b00ff851cbc7314ef Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 16 Oct 2018 17:27:54 +0000 Subject: [PATCH] Recommit changes with a couple xtra tests marked to fail on apple's clang. Reviewed as D51762 llvm-svn: 344627 --- libcxx/include/__config | 5 + libcxx/include/chrono | 1033 +++++++++++++++++++- libcxx/test/std/utilities/time/days.pass.cpp | 28 + libcxx/test/std/utilities/time/months.pass.cpp | 29 + .../test/std/utilities/time/time.cal/euclidian.h | 40 + .../utilities/time/time.cal/nothing_to_do.pass.cpp | 12 + .../time.cal.day.members/ctor.pass.cpp | 46 + .../time.cal.day.members/decrement.pass.cpp | 52 + .../time.cal.day.members/increment.pass.cpp | 52 + .../time.cal.day/time.cal.day.members/ok.pass.cpp | 37 + .../time.cal.day.members/plus_minus_equal.pass.cpp | 57 ++ .../time.cal.day.nonmembers/comparisons.pass.cpp | 44 + .../time.cal.day.nonmembers/literals.fail.cpp | 28 + .../time.cal.day.nonmembers/literals.pass.cpp | 47 + .../time.cal.day.nonmembers/minus.pass.cpp | 58 ++ .../time.cal.day.nonmembers/plus.pass.cpp | 59 ++ .../time.cal.day.nonmembers/streaming.pass.cpp | 56 ++ .../time/time.cal/time.cal.day/types.pass.cpp | 26 + .../time/time.cal/time.cal.last/types.pass.cpp | 33 + .../time.cal.md/time.cal.md.members/ctor.pass.cpp | 47 + .../time.cal.md/time.cal.md.members/day.pass.cpp | 39 + .../time.cal.md/time.cal.md.members/month.pass.cpp | 39 + .../time.cal.md/time.cal.md.members/ok.pass.cpp | 55 ++ .../time.cal.md.nonmembers/comparisons.pass.cpp | 70 ++ .../time.cal.md.nonmembers/streaming.pass.cpp | 41 + .../time/time.cal/time.cal.md/types.pass.cpp | 26 + .../time.cal/time.cal.mdlast/comparisons.pass.cpp | 43 + .../time/time.cal/time.cal.mdlast/ctor.pass.cpp | 41 + .../time/time.cal/time.cal.mdlast/month.pass.cpp | 38 + .../time/time.cal/time.cal.mdlast/ok.pass.cpp | 46 + .../time.cal/time.cal.mdlast/streaming.pass.cpp | 34 + .../time/time.cal/time.cal.mdlast/types.pass.cpp | 27 + .../time.cal.month.members/ctor.pass.cpp | 46 + .../time.cal.month.members/decrement.pass.cpp | 53 + .../time.cal.month.members/increment.pass.cpp | 52 + .../time.cal.month.members/ok.pass.cpp | 38 + .../plus_minus_equal.pass.cpp | 67 ++ .../time.cal.month.nonmembers/comparisons.pass.cpp | 47 + .../time.cal.month.nonmembers/literals.pass.cpp | 87 ++ .../time.cal.month.nonmembers/minus.pass.cpp | 72 ++ .../time.cal.month.nonmembers/plus.pass.cpp | 72 ++ .../time.cal.month.nonmembers/streaming.pass.cpp | 53 + .../time/time.cal/time.cal.month/types.pass.cpp | 26 + .../time.cal.mwd.members/ctor.pass.cpp | 46 + .../time.cal.mwd.members/month.pass.cpp | 42 + .../time.cal.mwd/time.cal.mwd.members/ok.pass.cpp | 51 + .../time.cal.mwd.members/weekday_indexed.pass.cpp | 43 + .../time.cal.mwd.nonmembers/comparisons.pass.cpp | 86 ++ .../time.cal.mwd.nonmembers/streaming.pass.cpp | 36 + .../time/time.cal/time.cal.mwd/types.pass.cpp | 26 + .../time.cal.mwdlast.members/ctor.pass.cpp | 60 ++ .../time.cal.mwdlast.members/month.pass.cpp | 42 + .../time.cal.mwdlast.members/ok.pass.cpp | 52 + .../time.cal.mwdlast.members/weekday_last.pass.cpp | 44 + .../comparisons.pass.cpp | 73 ++ .../time.cal.mwdlast.nonmembers/streaming.pass.cpp | 37 + .../time/time.cal/time.cal.mwdlast/types.pass.cpp | 27 + .../time.cal/time.cal.operators/month_day.pass.cpp | 108 ++ .../time.cal.operators/month_day_last.pass.cpp | 107 ++ .../time.cal.operators/month_weekday.pass.cpp | 115 +++ .../time.cal.operators/month_weekday_last.pass.cpp | 107 ++ .../time.cal.operators/year_month.pass.cpp | 68 ++ .../time.cal.operators/year_month_day.pass.cpp | 192 ++++ .../year_month_day_last.pass.cpp | 129 +++ .../time.cal.operators/year_month_weekday.pass.cpp | 145 +++ .../year_month_weekday_last.pass.cpp | 154 +++ .../time.cal.wdidx.members/ctor.pass.cpp | 61 ++ .../time.cal.wdidx.members/index.pass.cpp | 38 + .../time.cal.wdidx.members/ok.pass.cpp | 49 + .../time.cal.wdidx.members/weekday.pass.cpp | 39 + .../time.cal.wdidx.nonmembers/comparisons.pass.cpp | 48 + .../time.cal.wdidx.nonmembers/streaming.pass.cpp | 36 + .../time/time.cal/time.cal.wdidx/types.pass.cpp | 26 + .../time.cal.wdlast.members/ctor.pass.cpp | 47 + .../time.cal.wdlast.members/ok.pass.cpp | 37 + .../time.cal.wdlast.members/weekday.pass.cpp | 33 + .../comparisons.pass.cpp | 43 + .../time.cal.wdlast.nonmembers/streaming.pass.cpp | 34 + .../time/time.cal/time.cal.wdlast/types.pass.cpp | 26 + .../time.cal.weekday.members/ctor.pass.cpp | 51 + .../time.cal.weekday.members/decrement.pass.cpp | 53 + .../time.cal.weekday.members/increment.pass.cpp | 53 + .../time.cal.weekday.members/ok.pass.cpp | 38 + .../time.cal.weekday.members/operator[].pass.cpp | 59 ++ .../plus_minus_equal.pass.cpp | 63 ++ .../comparisons.pass.cpp | 42 + .../time.cal.weekday.nonmembers/literals.pass.cpp | 62 ++ .../time.cal.weekday.nonmembers/minus.pass.cpp | 76 ++ .../time.cal.weekday.nonmembers/plus.pass.cpp | 70 ++ .../time.cal.weekday.nonmembers/streaming.pass.cpp | 56 ++ .../time/time.cal/time.cal.weekday/types.pass.cpp | 26 + .../time.cal.year.members/ctor.pass.cpp | 46 + .../time.cal.year.members/decrement.pass.cpp | 52 + .../time.cal.year.members/increment.pass.cpp | 52 + .../time.cal.year.members/is_leap.pass.cpp | 53 + .../time.cal.year.members/ok.pass.cpp | 53 + .../time.cal.year.members/plus_minus.pass.cpp | 51 + .../plus_minus_equal.pass.cpp | 57 ++ .../time.cal.year.nonmembers/comparisons.pass.cpp | 47 + .../time.cal.year.nonmembers/literals.fail.cpp | 28 + .../time.cal.year.nonmembers/literals.pass.cpp | 44 + .../time.cal.year.nonmembers/minus.pass.cpp | 62 ++ .../time.cal.year.nonmembers/plus.pass.cpp | 59 ++ .../time.cal.year.nonmembers/streaming.pass.cpp | 55 ++ .../time/time.cal/time.cal.year/types.pass.cpp | 26 + .../time.cal.ym/time.cal.ym.members/ctor.pass.cpp | 52 + .../time.cal.ym/time.cal.ym.members/month.pass.cpp | 39 + .../time.cal.ym/time.cal.ym.members/ok.pass.cpp | 50 + .../plus_minus_equal_month.pass.cpp | 64 ++ .../plus_minus_equal_year.pass.cpp | 65 ++ .../time.cal.ym/time.cal.ym.members/year.pass.cpp | 39 + .../time.cal.ym.nonmembers/comparisons.pass.cpp | 69 ++ .../time.cal.ym.nonmembers/minus.pass.cpp | 90 ++ .../time.cal.ym.nonmembers/plus.pass.cpp | 106 ++ .../time.cal.ym.nonmembers/streaming.pass.cpp | 57 ++ .../time/time.cal/time.cal.ym/types.pass.cpp | 26 + .../time.cal.ymd.members/ctor.local_days.pass.cpp | 44 + .../time.cal.ymd.members/ctor.pass.cpp | 56 ++ .../time.cal.ymd.members/ctor.sys_days.pass.cpp | 44 + .../ctor.year_month_day_last.pass.cpp | 42 + .../time.cal.ymd/time.cal.ymd.members/day.pass.cpp | 40 + .../time.cal.ymd.members/month.pass.cpp | 40 + .../time.cal.ymd/time.cal.ymd.members/ok.pass.cpp | 65 ++ .../plus_minus_equal_month.pass.cpp | 70 ++ .../plus_minus_equal_year.pass.cpp | 70 ++ .../time.cal.ymd.members/year.pass.cpp | 40 + .../time.cal.ymd.nonmembers/comparisons.pass.cpp | 118 +++ .../time.cal.ymd.nonmembers/minus.pass.cpp | 60 ++ .../time.cal.ymd.nonmembers/plus.pass.cpp | 112 +++ .../time.cal.ymd.nonmembers/streaming.pass.cpp | 58 ++ .../time/time.cal/time.cal.ymd/types.pass.cpp | 26 + .../time.cal.ymdlast.members/ctor.pass.cpp | 54 + .../time.cal.ymdlast.members/day.pass.cpp | 43 + .../time.cal.ymdlast.members/month.pass.cpp | 39 + .../month_day_last.pass.cpp | 39 + .../time.cal.ymdlast.members/ok.pass.cpp | 53 + .../op_local_days.pass.cpp | 36 + .../time.cal.ymdlast.members/op_sys_days.pass.cpp | 36 + .../plus_minus_equal_month.pass.cpp | 67 ++ .../plus_minus_equal_year.pass.cpp | 66 ++ .../time.cal.ymdlast.members/year.pass.cpp | 39 + .../comparisons.pass.cpp | 88 ++ .../time.cal.ymdlast.nonmembers/minus.pass.cpp | 92 ++ .../time.cal.ymdlast.nonmembers/plus.pass.cpp | 123 +++ .../time.cal.ymdlast.nonmembers/streaming.pass.cpp | 37 + .../time.cal.ymwd.members/ctor.local_days.pass.cpp | 44 + .../time.cal.ymwd.members/ctor.pass.cpp | 65 ++ .../time.cal.ymwd.members/ctor.sys_days.pass.cpp | 43 + .../ctor.year_month_day_last.pass.cpp | 41 + .../time.cal.ymwd.members/index.pass.cpp | 42 + .../time.cal.ymwd.members/month.pass.cpp | 42 + .../time.cal.ymwd.members/ok.pass.cpp | 76 ++ .../plus_minus_equal_month.pass.cpp | 82 ++ .../plus_minus_equal_year.pass.cpp | 82 ++ .../time.cal.ymwd.members/weekday.pass.cpp | 42 + .../time.cal.ymwd.members/weekday_indexed.pass.cpp | 46 + .../time.cal.ymwd.members/year.pass.cpp | 42 + .../time.cal.ymwd.nonmembers/comparisons.pass.cpp | 114 +++ .../time.cal.ymwd.nonmembers/minus.pass.cpp | 101 ++ .../time.cal.ymwd.nonmembers/plus.pass.cpp | 121 +++ .../time.cal.ymwd.nonmembers/streaming.pass.cpp | 57 ++ .../time/time.cal/time.cal.ymwd/types.pass.cpp | 26 + .../time.cal.ymwdlast.members/ctor.pass.cpp | 52 + .../time.cal.ymwdlast.members/month.pass.cpp | 41 + .../time.cal.ymwdlast.members/ok.pass.cpp | 73 ++ .../op_local_days.pass.cpp | 35 + .../time.cal.ymwdlast.members/op_sys_days.pass.cpp | 36 + .../plus_minus_equal_month.pass.cpp | 75 ++ .../plus_minus_equal_year.pass.cpp | 76 ++ .../time.cal.ymwdlast.members/weekday.pass.cpp | 41 + .../time.cal.ymwdlast.members/year.pass.cpp | 41 + .../comparisons.pass.cpp | 114 +++ .../time.cal.ymwdlast.nonmembers/minus.pass.cpp | 93 ++ .../time.cal.ymwdlast.nonmembers/plus.pass.cpp | 116 +++ .../streaming.pass.cpp | 38 + .../time/time.cal/time.cal.ymwdlast/types.pass.cpp | 26 + .../time.duration.literals/literals.pass.cpp | 3 + .../time.duration.literals/literals1.pass.cpp | 25 +- libcxx/test/std/utilities/time/weeks.pass.cpp | 28 + libcxx/test/std/utilities/time/years.pass.cpp | 28 + 180 files changed, 10901 insertions(+), 2 deletions(-) create mode 100644 libcxx/test/std/utilities/time/days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/months.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/euclidian.h create mode 100644 libcxx/test/std/utilities/time/time.cal/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/decrement.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/increment.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/plus_minus_equal.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.fail.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.day/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.last/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/day.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.md/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/decrement.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/increment.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/plus_minus_equal.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/literals.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.month/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/weekday_indexed.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwd/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/weekday_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/index.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/weekday.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/weekday.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/decrement.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/increment.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/operator[].pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/plus_minus_equal.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/literals.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.weekday/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/decrement.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/increment.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/is_leap.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus_equal.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.fail.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.year/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ym/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.local_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.sys_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.year_month_day_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/day.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymd/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/day.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month_day_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_local_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_sys_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.local_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.sys_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.year_month_day_last.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/index.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday_indexed.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ctor.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ok.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_local_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_sys_days.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_month.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/weekday.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/year.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/comparisons.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/minus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/plus.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/streaming.pass.cpp create mode 100644 libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/types.pass.cpp create mode 100644 libcxx/test/std/utilities/time/weeks.pass.cpp create mode 100644 libcxx/test/std/utilities/time/years.pass.cpp diff --git a/libcxx/include/__config b/libcxx/include/__config index 14ecb8f..7e47f44 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -492,6 +492,11 @@ namespace std { #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) +// No apple compilers support ""d and ""y at this time. +#if _LIBCPP_CLANG_VER < 800 || defined(__apple_build_version__) +#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS +#endif + #elif defined(_LIBCPP_COMPILER_GCC) #define _ALIGNAS(x) __attribute__((__aligned__(x))) diff --git a/libcxx/include/chrono b/libcxx/include/chrono index 0691101..75258ab 100644 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -748,6 +748,7 @@ unspecified parse(const basic_string& format, Parsable& tp, basic_string& abbrev, minutes& offset); +// calendrical constants inline constexpr last_spec last{}; // C++20 inline constexpr chrono::weekday Sunday{0}; // C++20 inline constexpr chrono::weekday Monday{1}; // C++20 @@ -1091,7 +1092,12 @@ typedef duration milliseconds; typedef duration seconds; typedef duration< long, ratio< 60> > minutes; typedef duration< long, ratio<3600> > hours; - +#if _LIBCPP_STD_VER > 17 +typedef duration< int, ratio_multiply, hours::period>> days; +typedef duration< int, ratio_multiply, days::period>> weeks; +typedef duration< int, ratio_multiply, days::period>> years; +typedef duration< int, ratio_divide>> months; +#endif // Duration == template @@ -1574,6 +1580,1020 @@ typedef steady_clock high_resolution_clock; typedef system_clock high_resolution_clock; #endif +#if _LIBCPP_STD_VER > 17 + +struct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; }; + + +class _LIBCPP_TYPE_VIS day { +private: + unsigned char __d; +public: + day() = default; + explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast(__val)) {} + inline constexpr day& operator++() noexcept { ++__d; return *this; } + inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } + inline constexpr day& operator--() noexcept { --__d; return *this; } + inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } + constexpr day& operator+=(const days& __dd) noexcept; + constexpr day& operator-=(const days& __dd) noexcept; + explicit inline constexpr operator unsigned() const noexcept { return __d; } + inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } + }; + + +inline constexpr +bool operator==(const day& __lhs, const day& __rhs) noexcept +{ return static_cast(__lhs) == static_cast(__rhs); } + +inline constexpr +bool operator!=(const day& __lhs, const day& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const day& __lhs, const day& __rhs) noexcept +{ return static_cast(__lhs) < static_cast(__rhs); } + +inline constexpr +bool operator> (const day& __lhs, const day& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const day& __lhs, const day& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const day& __lhs, const day& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +day operator+ (const day& __lhs, const days& __rhs) noexcept +{ return day(static_cast(__lhs) + __rhs.count()); } + +inline constexpr +day operator+ (const days& __lhs, const day& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +day operator- (const day& __lhs, const days& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +days operator-(const day& __lhs, const day& __rhs) noexcept +{ return days(static_cast(static_cast(__lhs)) - + static_cast(static_cast(__rhs))); } + +inline constexpr day& day::operator+=(const days& __dd) noexcept +{ *this = *this + __dd; return *this; } + +inline constexpr day& day::operator-=(const days& __dd) noexcept +{ *this = *this - __dd; return *this; } + + +class _LIBCPP_TYPE_VIS month { +private: + unsigned char __m; +public: + month() = default; + explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast(__val)) {} + inline constexpr month& operator++() noexcept { ++__m; return *this; } + inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } + inline constexpr month& operator--() noexcept { --__m; return *this; } + inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } + constexpr month& operator+=(const months& __m1) noexcept; + constexpr month& operator-=(const months& __m1) noexcept; + explicit inline constexpr operator unsigned() const noexcept { return __m; } + inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } +}; + + +inline constexpr +bool operator==(const month& __lhs, const month& __rhs) noexcept +{ return static_cast(__lhs) == static_cast(__rhs); } + +inline constexpr +bool operator!=(const month& __lhs, const month& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const month& __lhs, const month& __rhs) noexcept +{ return static_cast(__lhs) < static_cast(__rhs); } + +inline constexpr +bool operator> (const month& __lhs, const month& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const month& __lhs, const month& __rhs) noexcept +{ return !(__rhs < __lhs); } + +inline constexpr +bool operator>=(const month& __lhs, const month& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +month operator+ (const month& __lhs, const months& __rhs) noexcept +{ + auto const __mu = static_cast(static_cast(__lhs)) + (__rhs.count() - 1); + auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; + return month{static_cast(__mu - __yr * 12 + 1)}; +} + +inline constexpr +month operator+ (const months& __lhs, const month& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +month operator- (const month& __lhs, const months& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +months operator-(const month& __lhs, const month& __rhs) noexcept +{ + auto const __dm = static_cast(__lhs) - static_cast(__rhs); + return months(__dm <= 11 ? __dm : __dm + 12); +} + +inline constexpr month& month::operator+=(const months& __dm) noexcept +{ *this = *this + __dm; return *this; } + +inline constexpr month& month::operator-=(const months& __dm) noexcept +{ *this = *this - __dm; return *this; } + + +class _LIBCPP_TYPE_VIS year { +private: + short __y; +public: + year() = default; + explicit inline constexpr year(int __val) noexcept : __y(static_cast(__val)) {} + + inline constexpr year& operator++() noexcept { ++__y; return *this; }; + inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }; + inline constexpr year& operator--() noexcept { --__y; return *this; }; + inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }; + constexpr year& operator+=(const years& __dy) noexcept; + constexpr year& operator-=(const years& __dy) noexcept; + inline constexpr year operator+() const noexcept { return *this; } + inline constexpr year operator-() const noexcept { return year{-__y}; }; + + inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } + explicit inline constexpr operator int() const noexcept { return __y; } + constexpr bool ok() const noexcept; + static inline constexpr year min() noexcept { return year{-32767}; } + static inline constexpr year max() noexcept { return year{ 32767}; } +}; + + +inline constexpr +bool operator==(const year& __lhs, const year& __rhs) noexcept +{ return static_cast(__lhs) == static_cast(__rhs); } + +inline constexpr +bool operator!=(const year& __lhs, const year& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year& __lhs, const year& __rhs) noexcept +{ return static_cast(__lhs) < static_cast(__rhs); } + +inline constexpr +bool operator> (const year& __lhs, const year& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year& __lhs, const year& __rhs) noexcept +{ return !(__rhs < __lhs); } + +inline constexpr +bool operator>=(const year& __lhs, const year& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +year operator+ (const year& __lhs, const years& __rhs) noexcept +{ return year(static_cast(__lhs) + __rhs.count()); } + +inline constexpr +year operator+ (const years& __lhs, const year& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year operator- (const year& __lhs, const years& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +years operator-(const year& __lhs, const year& __rhs) noexcept +{ return years{static_cast(__lhs) - static_cast(__rhs)}; } + + +inline constexpr year& year::operator+=(const years& __dy) noexcept +{ *this = *this + __dy; return *this; } + +inline constexpr year& year::operator-=(const years& __dy) noexcept +{ *this = *this - __dy; return *this; } + +inline constexpr bool year::ok() const noexcept +{ return static_cast(min()) <= __y && __y <= static_cast(max()); } + +class _LIBCPP_TYPE_VIS weekday_indexed; +class _LIBCPP_TYPE_VIS weekday_last; + +class _LIBCPP_TYPE_VIS weekday { +private: + unsigned char __wd; +public: + weekday() = default; + explicit inline constexpr weekday(unsigned __val) noexcept: __wd(static_cast(__val)) {} +// inline constexpr weekday(const sys_days& dp) noexcept; +// explicit constexpr weekday(const local_days& dp) noexcept; + inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } + inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } + inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } + inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } + constexpr weekday& operator+=(const days& __dd) noexcept; + constexpr weekday& operator-=(const days& __dd) noexcept; + explicit inline constexpr operator unsigned() const noexcept { return __wd; } + inline constexpr bool ok() const noexcept { return __wd <= 6; } + constexpr weekday_indexed operator[](unsigned __index) const noexcept; + constexpr weekday_last operator[](last_spec) const noexcept; +}; + +inline constexpr +bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept +{ return static_cast(__lhs) == static_cast(__rhs); } + +inline constexpr +bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept +{ return static_cast(__lhs) < static_cast(__rhs); } + +inline constexpr +bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept +{ return !(__lhs < __rhs); } + +constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept +{ + auto const __mu = static_cast(static_cast(__lhs)) + __rhs.count(); + auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; + return weekday{static_cast(__mu - __yr * 7)}; +} + +constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept +{ return __rhs + __lhs; } + +constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept +{ return __lhs + -__rhs; } + +constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept +{ + const int __wdu = static_cast(__lhs) - static_cast(__rhs); + const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7; + return days{__wdu - __wk * 7}; +} + +inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept +{ *this = *this + __dd; return *this; } + +inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept +{ *this = *this - __dd; return *this; } + + +class _LIBCPP_TYPE_VIS weekday_indexed { +private: + _VSTD::chrono::weekday __wd; + unsigned char __idx; +public: + weekday_indexed() = default; + inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept + : __wd{__wdval}, __idx(__idxval) {} + inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; } + inline constexpr unsigned index() const noexcept { return __idx; } + inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; } +}; + +inline constexpr +bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept +{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); } + +inline constexpr +bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept +{ return !(__lhs == __rhs); } + + +class _LIBCPP_TYPE_VIS weekday_last { +private: + _VSTD::chrono::weekday __wd; +public: + explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept + : __wd{__val} {} + constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; } + constexpr bool ok() const noexcept { return __wd.ok(); } +}; + +inline constexpr +bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept +{ return __lhs.weekday() == __rhs.weekday(); } + +inline constexpr +bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } + +inline constexpr +weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } + + +inline constexpr last_spec last{}; +inline constexpr weekday Sunday{0}; +inline constexpr weekday Monday{1}; +inline constexpr weekday Tuesday{2}; +inline constexpr weekday Wednesday{3}; +inline constexpr weekday Thursday{4}; +inline constexpr weekday Friday{5}; +inline constexpr weekday Saturday{6}; + +inline constexpr month January{1}; +inline constexpr month February{2}; +inline constexpr month March{3}; +inline constexpr month April{4}; +inline constexpr month May{5}; +inline constexpr month June{6}; +inline constexpr month July{7}; +inline constexpr month August{8}; +inline constexpr month September{9}; +inline constexpr month October{10}; +inline constexpr month November{11}; +inline constexpr month December{12}; + + +class _LIBCPP_TYPE_VIS month_day { +private: + chrono::month __m; + chrono::day __d; +public: + month_day() = default; + constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept + : __m{__mval}, __d{__dval} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::day day() const noexcept { return __d; } + constexpr bool ok() const noexcept; +}; + +inline constexpr +bool month_day::ok() const noexcept +{ + if (!__m.ok()) return false; + const unsigned __dval = static_cast(__d); + if (__dval < 1 || __dval > 31) return false; + if (__dval <= 29) return true; +// Now we've got either 30 or 31 + const unsigned __mval = static_cast(__m); + if (__mval == 2) return false; + if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) + return __dval == 30; + return true; +} + +inline constexpr +bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept +{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } + +inline constexpr +bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +month_day operator/(const month& __lhs, const day& __rhs) noexcept +{ return month_day{__lhs, __rhs}; } + +constexpr +month_day operator/(const day& __lhs, const month& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +month_day operator/(const month& __lhs, int __rhs) noexcept +{ return __lhs / day(__rhs); } + +constexpr +month_day operator/(int __lhs, const day& __rhs) noexcept +{ return month(__lhs) / __rhs; } + +constexpr +month_day operator/(const day& __lhs, int __rhs) noexcept +{ return month(__rhs) / __lhs; } + + +inline constexpr +bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept +{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } + +inline constexpr +bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept +{ return !(__lhs < __rhs); } + + + +class _LIBCPP_TYPE_VIS month_day_last { +private: + chrono::month __m; +public: + explicit constexpr month_day_last(const chrono::month& __val) noexcept + : __m{__val} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr bool ok() const noexcept { return __m.ok(); } +}; + +inline constexpr +bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return __lhs.month() == __rhs.month(); } + +inline constexpr +bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return __lhs.month() < __rhs.month(); } + +inline constexpr +bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +month_day_last operator/(const month& __lhs, last_spec) noexcept +{ return month_day_last{__lhs}; } + +inline constexpr +month_day_last operator/(last_spec, const month& __rhs) noexcept +{ return month_day_last{__rhs}; } + +inline constexpr +month_day_last operator/(int __lhs, last_spec) noexcept +{ return month_day_last{month(__lhs)}; } + +inline constexpr +month_day_last operator/(last_spec, int __rhs) noexcept +{ return month_day_last{month(__rhs)}; } + + +class _LIBCPP_TYPE_VIS month_weekday { +private: + chrono::month __m; + chrono::weekday_indexed __wdi; +public: + month_weekday() = default; + constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept + : __m{__mval}, __wdi{__wdival} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } + inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); } +}; + +inline constexpr +bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept +{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } + +inline constexpr +bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept +{ return month_weekday{__lhs, __rhs}; } + +inline constexpr +month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept +{ return month_weekday{month(__lhs), __rhs}; } + +inline constexpr +month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept +{ return month_weekday{__rhs, __lhs}; } + +inline constexpr +month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept +{ return month_weekday{month(__rhs), __lhs}; } + + +class _LIBCPP_TYPE_VIS month_weekday_last { + chrono::month __m; + chrono::weekday_last __wdl; + public: + constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept + : __m{__mval}, __wdl{__wdlval} {} + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } + inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); } +}; + +inline constexpr +bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept +{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } + +inline constexpr +bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + + +inline constexpr +month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept +{ return month_weekday_last{__lhs, __rhs}; } + +inline constexpr +month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept +{ return month_weekday_last{month(__lhs), __rhs}; } + +inline constexpr +month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept +{ return month_weekday_last{__rhs, __lhs}; } + +inline constexpr +month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept +{ return month_weekday_last{month(__rhs), __lhs}; } + + +class _LIBCPP_TYPE_VIS year_month { + chrono::year __y; + chrono::month __m; +public: + year_month() = default; + constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept + : __y{__yval}, __m{__mval} {} + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } + inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } + inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } + inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } + inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } +}; + +inline constexpr +year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } + +inline constexpr +year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } + +inline constexpr +bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } + +inline constexpr +bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept +{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } + +inline constexpr +bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept +{ return !(__lhs < __rhs); } + +constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept +{ + int __dmi = static_cast(static_cast(__lhs.month())) - 1 + __rhs.count(); + const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12; + __dmi = __dmi - __dy * 12 + 1; + return (__lhs.year() + years(__dy)) / month(static_cast(__dmi)); +} + +constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept +{ return __rhs + __lhs; } + +constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept +{ return (__lhs.year() + __rhs) / __lhs.month(); } + +constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept +{ return __rhs + __lhs; } + +constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept +{ return (__lhs.year() - __rhs.year()) + months(static_cast(__lhs.month()) - static_cast(__rhs.month())); } + +constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept +{ return __lhs + -__rhs; } + +constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept +{ return __lhs + -__rhs; } + + +class _LIBCPP_TYPE_VIS year_month_day { +private: + chrono::year __y; + chrono::month __m; + chrono::day __d; +public: + year_month_day() = default; + inline constexpr year_month_day( + const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept + : __y{__yval}, __m{__mval}, __d{__dval} {} +// inline constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; +// inline constexpr year_month_day(const sys_days& dp) noexcept; +// inline explicit constexpr year_month_day(const local_days& dp) noexcept; + constexpr year_month_day& operator+=(const months& __dm) noexcept; + constexpr year_month_day& operator-=(const months& __dm) noexcept; + constexpr year_month_day& operator+=(const years& __dy) noexcept; + constexpr year_month_day& operator-=(const years& __dy) noexcept; + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::day day() const noexcept { return __d; } +// inline constexpr operator sys_days() const noexcept; +// inline explicit constexpr operator local_days() const noexcept; + +// TODO: This is not quite correct; requires the calendar bits to do right +// d_ is in the range [1d, (y_/m_/last).day()], + inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __d.ok(); } +}; + +inline constexpr +bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } + +inline constexpr +bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ + if (__lhs.year() < __rhs.year()) return true; + if (__lhs.year() > __rhs.year()) return false; + if (__lhs.month() < __rhs.month()) return true; + if (__lhs.month() > __rhs.month()) return false; + return __lhs.day() < __rhs.day(); +} + +inline constexpr +bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr +year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept +{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } + +inline constexpr +year_month_day operator/(const year_month& __lhs, int __rhs) noexcept +{ return __lhs / day(__rhs); } + +inline constexpr +year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept +{ return __lhs / __rhs.month() / __rhs.day(); } + +inline constexpr +year_month_day operator/(int __lhs, const month_day& __rhs) noexcept +{ return year(__lhs) / __rhs; } + +inline constexpr +year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +year_month_day operator/(const month_day& __lhs, int __rhs) noexcept +{ return year(__rhs) / __lhs; } + + +inline constexpr +year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept +{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); } + +inline constexpr +year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr +year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept +{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } + +inline constexpr +year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept +{ return __lhs + -__rhs; } + +inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +class _LIBCPP_TYPE_VIS year_month_day_last { +private: + chrono::year __y; + chrono::month_day_last __mdl; +public: + constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept + : __y{__yval}, __mdl{__mdlval} {} + + constexpr year_month_day_last& operator+=(const months& __m) noexcept; + constexpr year_month_day_last& operator-=(const months& __m) noexcept; + constexpr year_month_day_last& operator+=(const years& __y) noexcept; + constexpr year_month_day_last& operator-=(const years& __y) noexcept; + + constexpr chrono::year year() const noexcept { return __y; } + constexpr chrono::month month() const noexcept { return __mdl.month(); } + constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; } +// constexpr chrono::day day() const noexcept; +// constexpr operator sys_days() const noexcept; +// explicit constexpr operator local_days() const noexcept; + constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); } +}; + +inline constexpr +bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); } + +inline constexpr +bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ + if (__lhs.year() < __rhs.year()) return true; + if (__lhs.year() > __rhs.year()) return false; + return __lhs.month_day_last() < __rhs.month_day_last(); +} + +inline constexpr +bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return __rhs < __lhs; } + +inline constexpr +bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return !(__rhs < __lhs);} + +inline constexpr +bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept +{ return !(__lhs < __rhs); } + +inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept +{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } + +inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept +{ return year_month_day_last{__lhs, __rhs}; } + +inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept +{ return year_month_day_last{year{__lhs}, __rhs}; } + +inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept +{ return year{__rhs} / __lhs; } + + +inline constexpr +year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept +{ return (__lhs.year() / __lhs.month() + __rhs) / last; } + +inline constexpr +year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr +year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept +{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } + +inline constexpr +year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +class _LIBCPP_TYPE_VIS year_month_weekday { + chrono::year __y; + chrono::month __m; + chrono::weekday_indexed __wdi; +public: + year_month_weekday() = default; + constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, + const chrono::weekday_indexed& __wdival) noexcept + : __y{__yval}, __m{__mval}, __wdi{__wdival} {} +// constexpr year_month_weekday(const sys_days& dp) noexcept; +// explicit constexpr year_month_weekday(const local_days& dp) noexcept; + constexpr year_month_weekday& operator+=(const months& m) noexcept; + constexpr year_month_weekday& operator-=(const months& m) noexcept; + constexpr year_month_weekday& operator+=(const years& y) noexcept; + constexpr year_month_weekday& operator-=(const years& y) noexcept; + + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); } + inline constexpr unsigned index() const noexcept { return __wdi.index(); } + inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } + +// constexpr operator sys_days() const noexcept; +// explicit constexpr operator local_days() const noexcept; + inline constexpr bool ok() const noexcept + { + if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; + // TODO: make sure it's a valid date + return true; + } +}; + +inline constexpr +bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } + +inline constexpr +bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept +{ return !(__lhs == __rhs); } + +inline constexpr +year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept +{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } + +inline constexpr +year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept +{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } + +inline constexpr +year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept +{ return year(__lhs) / __rhs; } + +inline constexpr +year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept +{ return year(__rhs) / __lhs; } + + +inline constexpr +year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept +{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } + +inline constexpr +year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr +year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept +{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } + +inline constexpr +year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept +{ return __lhs + (-__rhs); } + + +inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +class _LIBCPP_TYPE_VIS year_month_weekday_last { +private: + chrono::year __y; + chrono::month __m; + chrono::weekday_last __wdl; +public: + constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, + const chrono::weekday_last& __wdlval) noexcept + : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} + constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; + constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; + constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; + constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; + + inline constexpr chrono::year year() const noexcept { return __y; } + inline constexpr chrono::month month() const noexcept { return __m; } + inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); } + inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } +// constexpr operator sys_days() const noexcept; +// explicit constexpr operator local_days() const noexcept; + inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } +}; + +inline constexpr +bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } + +inline constexpr +bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return !(__lhs == __rhs); } + + +inline constexpr +year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept +{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } + +inline constexpr +year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept +{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } + +inline constexpr +year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept +{ return year(__lhs) / __rhs; } + +inline constexpr +year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept +{ return __rhs / __lhs; } + +inline constexpr +year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept +{ return year(__rhs) / __lhs; } + + +inline constexpr +year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept +{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } + +inline constexpr +year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr +year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept +{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } + +inline constexpr +year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept +{ return __rhs + __lhs; } + +inline constexpr +year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept +{ return __lhs + (-__rhs); } + +inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } +inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } +inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } +inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } + +#endif // _LIBCPP_STD_VER > 17 } // chrono #if _LIBCPP_STD_VER > 11 @@ -1648,6 +2668,17 @@ inline namespace literals return chrono::duration (__ns); } +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS) + constexpr chrono::day operator ""d(unsigned long long __d) noexcept + { + return chrono::day(static_cast(__d)); + } + + constexpr chrono::year operator ""y(unsigned long long __y) noexcept + { + return chrono::year(static_cast(__y)); + } +#endif }} namespace chrono { // hoist the literals into namespace std::chrono diff --git a/libcxx/test/std/utilities/time/days.pass.cpp b/libcxx/test/std/utilities/time/days.pass.cpp new file mode 100644 index 0000000..3954e98 --- /dev/null +++ b/libcxx/test/std/utilities/time/days.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// using days = duration, hours::period>>; + +#include +#include +#include + +int main() +{ + typedef std::chrono::days D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed::value, ""); + static_assert(std::is_integral::value, ""); + static_assert(std::numeric_limits::digits >= 25, ""); + static_assert(std::is_same_v, std::chrono::hours::period>>, ""); +} diff --git a/libcxx/test/std/utilities/time/months.pass.cpp b/libcxx/test/std/utilities/time/months.pass.cpp new file mode 100644 index 0000000..9a48b0a --- /dev/null +++ b/libcxx/test/std/utilities/time/months.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// using months = duration>>; + + +#include +#include +#include + +int main() +{ + typedef std::chrono::months D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed::value, ""); + static_assert(std::is_integral::value, ""); + static_assert(std::numeric_limits::digits >= 20, ""); + static_assert(std::is_same_v>>, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/euclidian.h b/libcxx/test/std/utilities/time/time.cal/euclidian.h new file mode 100644 index 0000000..f2dc28b --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/euclidian.h @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +// Assumption: minValue < maxValue +// Assumption: minValue <= rhs <= maxValue +// Assumption: minValue <= lhs <= maxValue +// Assumption: minValue >= 0 +template +T euclidian_addition(T rhs, T lhs) +{ + const T modulus = maxValue - minValue + 1; + T ret = rhs + lhs; + if (ret > maxValue) + ret -= modulus; + return ret; +} + +// Assumption: minValue < maxValue +// Assumption: minValue <= rhs <= maxValue +// Assumption: minValue <= lhs <= maxValue +// Assumption: minValue >= 0 +template +T euclidian_subtraction(T lhs, T rhs) +{ + const T modulus = maxValue - minValue + 1; + T ret = lhs - rhs; + if (ret < minValue) + ret += modulus; + if (ret > maxValue) // this can happen if T is unsigned + ret += modulus; + return ret; +} + diff --git a/libcxx/test/std/utilities/time/time.cal/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/time/time.cal/nothing_to_do.pass.cpp new file mode 100644 index 0000000..b58f5c5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ctor.pass.cpp new file mode 100644 index 0000000..c2c2eba --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ctor.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// day() = default; +// explicit constexpr day(unsigned d) noexcept; +// explicit constexpr operator unsigned() const noexcept; + +// Effects: Constructs an object of type day by initializing d_ with d. +// The value held is unspecified if d is not in the range [0, 255]. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + + ASSERT_NOEXCEPT(day{}); + ASSERT_NOEXCEPT(day(0U)); + ASSERT_NOEXCEPT(static_cast(day(0U))); + + constexpr day d0{}; + static_assert(static_cast(d0) == 0, ""); + + constexpr day d1{1}; + static_assert(static_cast(d1) == 1, ""); + + for (unsigned i = 0; i <= 255; ++i) + { + day day(i); + assert(static_cast(day) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/decrement.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/decrement.pass.cpp new file mode 100644 index 0000000..819709a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/decrement.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr day& operator--() noexcept; +// constexpr day operator--(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + D d1{10}; + if (static_cast(--d1) != 9) return false; + if (static_cast(d1--) != 9) return false; + if (static_cast(d1) != 8) return false; + return true; +} + +int main() +{ + using day = std::chrono::day; + ASSERT_NOEXCEPT(--(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())--); + + ASSERT_SAME_TYPE(day , decltype( std::declval()--)); + ASSERT_SAME_TYPE(day&, decltype(--std::declval() )); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 10; i <= 20; ++i) + { + day day(i); + assert(static_cast(--day) == i - 1); + assert(static_cast(day--) == i - 1); + assert(static_cast(day) == i - 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/increment.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/increment.pass.cpp new file mode 100644 index 0000000..323bf8b --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/increment.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr day& operator++() noexcept; +// constexpr day operator++(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + D d1{1}; + if (static_cast(++d1) != 2) return false; + if (static_cast(d1++) != 2) return false; + if (static_cast(d1) != 3) return false; + return true; +} + +int main() +{ + using day = std::chrono::day; + ASSERT_NOEXCEPT(++(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())++); + + ASSERT_SAME_TYPE(day , decltype( std::declval()++)); + ASSERT_SAME_TYPE(day&, decltype(++std::declval() )); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 10; i <= 20; ++i) + { + day day(i); + assert(static_cast(++day) == i + 1); + assert(static_cast(day++) == i + 1); + assert(static_cast(day) == i + 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ok.pass.cpp new file mode 100644 index 0000000..c3510fe --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/ok.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr bool ok() const noexcept; +// Returns: 1 <= d_ && d_ <= 31 + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!day{0}.ok(), ""); + static_assert( day{1}.ok(), ""); + + assert(!day{0}.ok()); + for (unsigned i = 1; i <= 31; ++i) + assert(day{i}.ok()); + for (unsigned i = 32; i <= 255; ++i) + assert(!day{i}.ok()); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/plus_minus_equal.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/plus_minus_equal.pass.cpp new file mode 100644 index 0000000..f8fd89a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.members/plus_minus_equal.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr day& operator+=(const days& d) noexcept; +// constexpr day& operator-=(const days& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + D d1{1}; + if (static_cast(d1 += Ds{ 1}) != 2) return false; + if (static_cast(d1 += Ds{ 2}) != 4) return false; + if (static_cast(d1 += Ds{22}) != 26) return false; + if (static_cast(d1 -= Ds{ 1}) != 25) return false; + if (static_cast(d1 -= Ds{ 2}) != 23) return false; + if (static_cast(d1 -= Ds{22}) != 1) return false; + return true; +} + +int main() +{ + using day = std::chrono::day; + using days = std::chrono::days; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(day&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(day&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + day day(i); + assert(static_cast(day += days{22}) == i + 22); + assert(static_cast(day) == i + 22); + assert(static_cast(day -= days{12}) == i + 10); + assert(static_cast(day) == i + 10); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..a5a25b7 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/comparisons.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr bool operator==(const day& x, const day& y) noexcept; +// Returns: unsigned{x} == unsigned{y}. +// constexpr bool operator<(const day& x, const day& y) noexcept; +// Returns: unsigned{x} < unsigned{y}. + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using day = std::chrono::day; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + static_assert(testComparisons6Values(0U, 0U), ""); + static_assert(testComparisons6Values(0U, 1U), ""); + +// Some 'ok' values as well + static_assert(testComparisons6Values( 5U, 5U), ""); + static_assert(testComparisons6Values( 5U, 10U), ""); + + for (unsigned i = 1; i < 10; ++i) + for (unsigned j = 1; j < 10; ++j) + assert(testComparisons6Values(i, j)); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.fail.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.fail.cpp new file mode 100644 index 0000000..0b2a090 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-5, clang-6 +// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9 + +// +// class day; + +// constexpr day operator""d(unsigned long long d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + day d1 = 4d; // expected-error-re {{no matching literal operator for call to 'operator""d' {{.*}}}} +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.pass.cpp new file mode 100644 index 0000000..0911b43 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/literals.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-5, clang-6 +// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9 + +// +// class day; + +// constexpr day operator""d(unsigned long long d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + { + using namespace std::chrono; + ASSERT_NOEXCEPT( 4d); + ASSERT_SAME_TYPE(day, decltype(4d)); + + static_assert( 7d == day(7), ""); + day d1 = 4d; + assert (d1 == day(4)); +} + + { + using namespace std::literals; + ASSERT_NOEXCEPT( 4d); + ASSERT_SAME_TYPE(std::chrono::day, decltype(4d)); + + static_assert( 7d == std::chrono::day(7), ""); + + std::chrono::day d1 = 4d; + assert (d1 == std::chrono::day(4)); + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..53697c1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/minus.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr day operator-(const day& x, const days& y) noexcept; +// Returns: x + -y. +// +// constexpr days operator-(const day& x, const day& y) noexcept; +// Returns: days{int(unsigned{x}) - int(unsigned{y}). + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + D d{23}; + Ds offset{6}; + if (d - offset != D{17}) return false; + if (d - D{17} != offset) return false; + return true; +} + +int main() +{ + using day = std::chrono::day; + using days = std::chrono::days; + + ASSERT_NOEXCEPT(std::declval() - std::declval()); + ASSERT_NOEXCEPT(std::declval() - std::declval()); + + ASSERT_SAME_TYPE(day, decltype(std::declval() - std::declval())); + ASSERT_SAME_TYPE(days, decltype(std::declval() - std::declval())); + + static_assert(testConstexpr(), ""); + + day dy{12}; + for (unsigned i = 0; i <= 10; ++i) + { + day d1 = dy - days{i}; + days off = dy - day {i}; + assert(static_cast(d1) == 12 - i); + assert(off.count() == static_cast(12 - i)); // days is signed + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..fb8f536 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/plus.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +// constexpr day operator+(const day& x, const days& y) noexcept; +// Returns: day(unsigned{x} + y.count()). +// +// constexpr day operator+(const days& x, const day& y) noexcept; +// Returns: y + x. + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + D d{1}; + Ds offset{23}; + if (d + offset != D{24}) return false; + if (offset + d != D{24}) return false; + return true; +} + +int main() +{ + using day = std::chrono::day; + using days = std::chrono::days; + + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(day, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(day, decltype(std::declval() + std::declval())); + + static_assert(testConstexpr(), ""); + + day dy{12}; + for (unsigned i = 0; i <= 10; ++i) + { + day d1 = dy + days{i}; + day d2 = days{i} + dy; + assert(d1 == d2); + assert(static_cast(d1) == i + 12); + assert(static_cast(d2) == i + 12); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..3e859af --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/time.cal.day.nonmembers/streaming.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class day; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const day& d); +// +// Effects: Inserts format(fmt, d) where fmt is "%d" widened to charT. +// If !d.ok(), appends with " is not a valid day". +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const day& d); +// +// Effects: Streams d into os using the format specified by the NTCTS fmt. +// fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// day& d, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the day d using the format flags +// given in the NTCTS fmt as specified in 25.12. +// If the parse fails to decode a valid day, is.setstate(ios_base::failbit) +// shall be called and d shall not be modified. +// If %Z is used and successfully parsed, that value will be assigned to *abbrev +// if abbrev is non-null. If %z (or a modified variant) is used and +// successfully parsed, that value will be assigned to *offset if offset is non-null. +// + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + std::cout << day{1}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.day/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.day/types.pass.cpp new file mode 100644 index 0000000..37c9c57 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.day/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class day; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.last/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.last/types.pass.cpp new file mode 100644 index 0000000..f0d3e3c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.last/types.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// struct last_spec { +// explicit last_spec() = default; +// }; +// +// inline constexpr last_spec last{}; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using last_spec = std::chrono::last_spec; + + ASSERT_SAME_TYPE(const last_spec, decltype(std::chrono::last)); + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ctor.pass.cpp new file mode 100644 index 0000000..2a30bec --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ctor.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +// month_day() = default; +// constexpr month_day(const chrono::month& m, const chrono::day& d) noexcept; +// +// Effects: Constructs an object of type month_day by initializing m_ with m, and d_ with d. +// +// constexpr chrono::month month() const noexcept; +// constexpr chrono::day day() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + using month = std::chrono::month; + using month_day = std::chrono::month_day; + + ASSERT_NOEXCEPT(month_day{}); + ASSERT_NOEXCEPT(month_day{month{1}, day{1}}); + + constexpr month_day md0{}; + static_assert( md0.month() == month{}, ""); + static_assert( md0.day() == day{}, ""); + static_assert(!md0.ok(), ""); + + constexpr month_day md1{std::chrono::January, day{4}}; + static_assert( md1.month() == std::chrono::January, ""); + static_assert( md1.day() == day{4}, ""); + static_assert( md1.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/day.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/day.pass.cpp new file mode 100644 index 0000000..69477a4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/day.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +// constexpr chrono::day day() const noexcept; +// Returns: d_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + using month = std::chrono::month; + using month_day = std::chrono::month_day; + + ASSERT_NOEXCEPT( std::declval().day()); + ASSERT_SAME_TYPE(day, decltype(std::declval().day())); + + static_assert( month_day{}.day() == day{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + month_day md(std::chrono::March, day{i}); + assert( static_cast(md.day()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/month.pass.cpp new file mode 100644 index 0000000..73ddb64 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/month.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + using month = std::chrono::month; + using month_day = std::chrono::month_day; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( month_day{}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + month_day md(month{i}, day{1}); + assert( static_cast(md.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ok.pass.cpp new file mode 100644 index 0000000..6ee79ca --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.members/ok.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +// constexpr bool ok() const noexcept; +// Returns: true if m_.ok() is true, 1d <= d_, and d_ is less than or equal to the +// number of days in month m_; otherwise returns false. +// When m_ == February, the number of days is considered to be 29. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using day = std::chrono::day; + using month = std::chrono::month; + using month_day = std::chrono::month_day; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!month_day{}.ok(), ""); + static_assert( month_day{std::chrono::May, day{2}}.ok(), ""); + + assert(!(month_day(std::chrono::April, day{0}).ok())); + + assert( (month_day{std::chrono::March, day{1}}.ok())); + for (unsigned i = 1; i <= 12; ++i) + { + const bool is31 = i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12; + assert(!(month_day{month{i}, day{ 0}}.ok())); + assert( (month_day{month{i}, day{ 1}}.ok())); + assert( (month_day{month{i}, day{10}}.ok())); + assert( (month_day{month{i}, day{29}}.ok())); + assert( (month_day{month{i}, day{30}}.ok()) == (i != 2)); + assert( (month_day{month{i}, day{31}}.ok()) == is31); + assert(!(month_day{month{i}, day{32}}.ok())); + } + +// If the month is not ok, all the days are bad + for (unsigned i = 1; i <= 35; ++i) + assert(!(month_day{month{13}, day{i}}.ok())); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..4a5a6c9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +// constexpr bool operator==(const month_day& x, const month_day& y) noexcept; +// Returns: x.month() == y.month() && x.day() == y.day(). +// +// constexpr bool operator< (const month_day& x, const month_day& y) noexcept; +// Returns: +// If x.month() < y.month() returns true. +// Otherwise, if x.month() > y.month() returns false. +// Otherwise, returns x.day() < y.day(). + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using day = std::chrono::day; + using month = std::chrono::month; + using month_day = std::chrono::month_day; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + static_assert( testComparisons6( + month_day{std::chrono::January, day{1}}, + month_day{std::chrono::January, day{1}}, + true, false), ""); + + static_assert( testComparisons6( + month_day{std::chrono::January, day{1}}, + month_day{std::chrono::January, day{2}}, + false, true), ""); + + static_assert( testComparisons6( + month_day{std::chrono::January, day{1}}, + month_day{std::chrono::February, day{1}}, + false, true), ""); + +// same day, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons6( + month_day{month{i}, day{1}}, + month_day{month{j}, day{1}}, + i == j, i < j ))); + +// same month, different days + for (unsigned i = 1; i < 31; ++i) + for (unsigned j = 1; j < 31; ++j) + assert((testComparisons6( + month_day{month{2}, day{i}}, + month_day{month{2}, day{j}}, + i == j, i < j ))); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..a197a3e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/time.cal.md.nonmembers/streaming.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class month_day; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const month_day& md); +// +// Returns: os << md.month() << '/' << md.day(). +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const month_day& md); +// +// Effects: Streams md into os using the format specified by the NTCTS fmt. +// fmt encoding follows the rules specified in 25.11. + + +#include +#include +#include +#include +#include "test_macros.h" + +int main() +{ + using month_day = std::chrono::month_day; + using month = std::chrono::month; + using day = std::chrono::day; + std::cout << month_day{month{1}, day{1}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.md/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.md/types.pass.cpp new file mode 100644 index 0000000..2a85c79 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.md/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_day = std::chrono::month_day; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/comparisons.pass.cpp new file mode 100644 index 0000000..f8c74bb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/comparisons.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day_last; + +// constexpr bool operator==(const month_day& x, const month_day& y) noexcept; +// Returns: x.month() == y.month() +// +// constexpr bool operator< (const month_day& x, const month_day& y) noexcept; +// Returns: x.month() < y.month() + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month = std::chrono::month; + using month_day_last = std::chrono::month_day_last; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + static_assert( testComparisons6Values(month{1}, month{1}), ""); + static_assert( testComparisons6Values(month{1}, month{2}), ""); + +// same day, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons6Values(month{i}, month{j}))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ctor.pass.cpp new file mode 100644 index 0000000..3a16ca4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ctor.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day_last; + +// constexpr month_day_last(const chrono::month& m) noexcept; +// +// Effects: Constructs an object of type month_day_last by initializing m_ with m +// +// constexpr chrono::month month() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using month_day_last = std::chrono::month_day_last; + + ASSERT_NOEXCEPT(month_day_last{month{1}}); + + constexpr month_day_last md0{month{}}; + static_assert( md0.month() == month{}, ""); + static_assert(!md0.ok(), ""); + + constexpr month_day_last md1{std::chrono::January}; + static_assert( md1.month() == std::chrono::January, ""); + static_assert( md1.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/month.pass.cpp new file mode 100644 index 0000000..b81d799 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/month.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day_last; + +// constexpr chrono::month month() const noexcept; +// Returns: m_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using month_day_last = std::chrono::month_day_last; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( month_day_last{month{}}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + month_day_last mdl(month{i}); + assert( static_cast(mdl.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ok.pass.cpp new file mode 100644 index 0000000..8d97eb6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/ok.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day_last; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using month_day_last = std::chrono::month_day_last; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!month_day_last{month{}}.ok(), ""); + static_assert( month_day_last{std::chrono::May}.ok(), ""); + + for (unsigned i = 1; i <= 12; ++i) + { + month_day_last mdl{month{i}}; + assert( mdl.ok()); + } + +// If the month is not ok, all the days are bad + for (unsigned i = 13; i <= 50; ++i) + { + month_day_last mdl{month{i}}; + assert(!mdl.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/streaming.pass.cpp new file mode 100644 index 0000000..693acd8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/streaming.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class month_day_last; +// +// template +// basic_ostream& +// operator<<(basic_ostream& os, const month_day_last& mdl); +// +// Returns: os << mdl.month() << "/last". + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_day_last = std::chrono::month_day_last; + using month = std::chrono::month; + std::cout << month_day_last{month{1}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/types.pass.cpp new file mode 100644 index 0000000..f50d22a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mdlast/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class month_day_last; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_day_last = std::chrono::month_day_last; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ctor.pass.cpp new file mode 100644 index 0000000..e9a7abce --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ctor.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// month() = default; +// explicit constexpr month(int m) noexcept; +// explicit constexpr operator int() const noexcept; + +// Effects: Constructs an object of type month by initializing m_ with m. +// The value held is unspecified if d is not in the range [0, 255]. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + + ASSERT_NOEXCEPT(month{}); + ASSERT_NOEXCEPT(month(1)); + ASSERT_NOEXCEPT(static_cast(month(1))); + + constexpr month m0{}; + static_assert(static_cast(m0) == 0, ""); + + constexpr month m1{1}; + static_assert(static_cast(m1) == 1, ""); + + for (unsigned i = 0; i <= 255; ++i) + { + month m(i); + assert(static_cast(m) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/decrement.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/decrement.pass.cpp new file mode 100644 index 0000000..bc39bbc --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/decrement.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr month& operator--() noexcept; +// constexpr month operator--(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + M m1{10}; + if (static_cast(--m1) != 9) return false; + if (static_cast(m1--) != 9) return false; + if (static_cast(m1) != 8) return false; + return true; +} + +int main() +{ + using month = std::chrono::month; + + ASSERT_NOEXCEPT(--(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())--); + + ASSERT_SAME_TYPE(month , decltype( std::declval()--)); + ASSERT_SAME_TYPE(month&, decltype(--std::declval() )); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 10; i <= 20; ++i) + { + month month(i); + assert(static_cast(--month) == i - 1); + assert(static_cast(month--) == i - 1); + assert(static_cast(month) == i - 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/increment.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/increment.pass.cpp new file mode 100644 index 0000000..bdedd6e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/increment.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr month& operator++() noexcept; +// constexpr month operator++(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + M m1{1}; + if (static_cast(++m1) != 2) return false; + if (static_cast(m1++) != 2) return false; + if (static_cast(m1) != 3) return false; + return true; +} + +int main() +{ + using month = std::chrono::month; + ASSERT_NOEXCEPT(++(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())++); + + ASSERT_SAME_TYPE(month , decltype( std::declval()++)); + ASSERT_SAME_TYPE(month&, decltype(++std::declval() )); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + month month(i); + assert(static_cast(++month) == i + 1); + assert(static_cast(month++) == i + 1); + assert(static_cast(month) == i + 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ok.pass.cpp new file mode 100644 index 0000000..3bf8f67 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/ok.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr bool ok() const noexcept; +// Returns: 1 <= d_ && d_ <= 12 + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!month{0}.ok(), ""); + static_assert( month{1}.ok(), ""); + + assert(!month{0}.ok()); + for (unsigned i = 1; i <= 12; ++i) + assert(month{i}.ok()); + for (unsigned i = 13; i <= 255; ++i) + assert(!month{i}.ok()); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/plus_minus_equal.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/plus_minus_equal.pass.cpp new file mode 100644 index 0000000..84d6e9c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.members/plus_minus_equal.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr month& operator+=(const month& d) noexcept; +// constexpr month& operator-=(const month& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + M m1{1}; + if (static_cast(m1 += Ms{ 1}) != 2) return false; + if (static_cast(m1 += Ms{ 2}) != 4) return false; + if (static_cast(m1 += Ms{ 8}) != 12) return false; + if (static_cast(m1 -= Ms{ 1}) != 11) return false; + if (static_cast(m1 -= Ms{ 2}) != 9) return false; + if (static_cast(m1 -= Ms{ 8}) != 1) return false; + return true; +} + +int main() +{ + using month = std::chrono::month; + using months = std::chrono::months; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + ASSERT_SAME_TYPE(month&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(month&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 1; i <= 10; ++i) + { + month month(i); + int exp = i + 10; + while (exp > 12) + exp -= 12; + assert(static_cast(month += months{10}) == static_cast(exp)); + assert(static_cast(month) == static_cast(exp)); + } + + for (unsigned i = 1; i <= 10; ++i) + { + month month(i); + int exp = i - 9; + while (exp < 1) + exp += 12; + assert(static_cast(month -= months{ 9}) == static_cast(exp)); + assert(static_cast(month) == static_cast(exp)); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..59c45d9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr bool operator==(const month& x, const month& y) noexcept; +// constexpr bool operator!=(const month& x, const month& y) noexcept; +// constexpr bool operator< (const month& x, const month& y) noexcept; +// constexpr bool operator> (const month& x, const month& y) noexcept; +// constexpr bool operator<=(const month& x, const month& y) noexcept; +// constexpr bool operator>=(const month& x, const month& y) noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + + +int main() +{ + using month = std::chrono::month; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + static_assert(testComparisons6Values(0U ,0U), ""); + static_assert(testComparisons6Values(0U, 1U), ""); + +// Some 'ok' values as well + static_assert(testComparisons6Values( 5U, 5U), ""); + static_assert(testComparisons6Values( 5U, 10U), ""); + + for (unsigned i = 1; i < 10; ++i) + for (unsigned j = 10; j < 10; ++j) + assert(testComparisons6Values(i, j)); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/literals.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/literals.pass.cpp new file mode 100644 index 0000000..e17852b5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/literals.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// inline constexpr month January{1}; +// inline constexpr month February{2}; +// inline constexpr month March{3}; +// inline constexpr month April{4}; +// inline constexpr month May{5}; +// inline constexpr month June{6}; +// inline constexpr month July{7}; +// inline constexpr month August{8}; +// inline constexpr month September{9}; +// inline constexpr month October{10}; +// inline constexpr month November{11}; +// inline constexpr month December{12}; + + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::January)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::February)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::March)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::April)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::May)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::June)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::July)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::August)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::September)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::October)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::November)); + ASSERT_SAME_TYPE(const std::chrono::month, decltype(std::chrono::December)); + + static_assert( std::chrono::January == std::chrono::month(1), ""); + static_assert( std::chrono::February == std::chrono::month(2), ""); + static_assert( std::chrono::March == std::chrono::month(3), ""); + static_assert( std::chrono::April == std::chrono::month(4), ""); + static_assert( std::chrono::May == std::chrono::month(5), ""); + static_assert( std::chrono::June == std::chrono::month(6), ""); + static_assert( std::chrono::July == std::chrono::month(7), ""); + static_assert( std::chrono::August == std::chrono::month(8), ""); + static_assert( std::chrono::September == std::chrono::month(9), ""); + static_assert( std::chrono::October == std::chrono::month(10), ""); + static_assert( std::chrono::November == std::chrono::month(11), ""); + static_assert( std::chrono::December == std::chrono::month(12), ""); + + assert(std::chrono::January == std::chrono::month(1)); + assert(std::chrono::February == std::chrono::month(2)); + assert(std::chrono::March == std::chrono::month(3)); + assert(std::chrono::April == std::chrono::month(4)); + assert(std::chrono::May == std::chrono::month(5)); + assert(std::chrono::June == std::chrono::month(6)); + assert(std::chrono::July == std::chrono::month(7)); + assert(std::chrono::August == std::chrono::month(8)); + assert(std::chrono::September == std::chrono::month(9)); + assert(std::chrono::October == std::chrono::month(10)); + assert(std::chrono::November == std::chrono::month(11)); + assert(std::chrono::December == std::chrono::month(12)); + + assert(static_cast(std::chrono::January) == 1); + assert(static_cast(std::chrono::February) == 2); + assert(static_cast(std::chrono::March) == 3); + assert(static_cast(std::chrono::April) == 4); + assert(static_cast(std::chrono::May) == 5); + assert(static_cast(std::chrono::June) == 6); + assert(static_cast(std::chrono::July) == 7); + assert(static_cast(std::chrono::August) == 8); + assert(static_cast(std::chrono::September) == 9); + assert(static_cast(std::chrono::October) == 10); + assert(static_cast(std::chrono::November) == 11); + assert(static_cast(std::chrono::December) == 12); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..055a287 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/minus.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr month operator-(const month& x, const months& y) noexcept; +// Returns: x + -y. +// +// constexpr months operator-(const month& x, const month& y) noexcept; +// Returns: If x.ok() == true and y.ok() == true, returns a value m in the range +// [months{0}, months{11}] satisfying y + m == x. +// Otherwise the value returned is unspecified. +// [Example: January - February == months{11}. —end example] + +extern "C" int printf(const char *, ...); + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + { + M m{5}; + Ms offset{3}; + if (m - offset != M{2}) return false; + if (m - M{2} != offset) return false; + } + +// Check the example + if (M{1} - M{2} != Ms{11}) return false; + return true; +} + +#include + +int main() +{ + using month = std::chrono::month; + using months = std::chrono::months; + + ASSERT_NOEXCEPT(std::declval() - std::declval()); + ASSERT_NOEXCEPT(std::declval() - std::declval()); + + ASSERT_SAME_TYPE(month , decltype(std::declval() - std::declval())); + ASSERT_SAME_TYPE(months, decltype(std::declval() - std::declval ())); + +static_assert(testConstexpr(), ""); + + month m{6}; + for (unsigned i = 1; i <= 12; ++i) + { + month m1 = m - months{i}; +// months off = m - month {i}; + int exp = 6 - i; + if (exp < 1) + exp += 12; + assert(static_cast(m1) == static_cast(exp)); +// assert(off.count() == static_cast(exp)); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..31fc277 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/plus.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +// constexpr month operator+(const month& x, const months& y) noexcept; +// Returns: month(int{x} + y.count()). +// +// constexpr month operator+(const months& x, const month& y) noexcept; +// Returns: +// month{modulo(static_cast(int{x}) + (y.count() - 1), 12) + 1} +// where modulo(n, 12) computes the remainder of n divided by 12 using Euclidean division. +// [Note: Given a divisor of 12, Euclidean division truncates towards negative infinity +// and always produces a remainder in the range of [0, 11]. +// Assuming no overflow in the signed summation, this operation results in a month +// holding a value in the range [1, 12] even if !x.ok(). —end note] +// [Example: February + months{11} == January. —end example] + + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + M m{1}; + Ms offset{4}; + if (m + offset != M{5}) return false; + if (offset + m != M{5}) return false; +// Check the example + if (M{2} + Ms{11} != M{1}) return false; + return true; +} + +int main() +{ + using month = std::chrono::month; + using months = std::chrono::months; + + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(month, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(month, decltype(std::declval() + std::declval() )); + + static_assert(testConstexpr(), ""); + + month my{2}; + for (unsigned i = 0; i <= 15; ++i) + { + month m1 = my + months{i}; + month m2 = months{i} + my; + assert(m1 == m2); + unsigned exp = i + 2; + while (exp > 12) + exp -= 12; + assert(static_cast(m1) == exp); + assert(static_cast(m2) == exp); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..274360d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/time.cal.month.nonmembers/streaming.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class month; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const month& m); +// +// Effects: If m.ok() == true inserts format(os.getloc(), fmt, m) where fmt is "%b" widened to charT. +// Otherwise inserts int{m} << " is not a valid month". +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const month& m); +// +// Effects: Streams m into os using the format specified by the NTCTS fmt. +// fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// month& m, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the month m using the format flags +// given in the NTCTS fmt as specified in 25.12. If the parse fails to decode a valid month, +// is.setstate(ios_- base::failbit) shall be called and m shall not be modified. +// If %Z is used and successfully parsed, that value will be assigned to *abbrev if +// abbrev is non-null. If %z (or a modified variant) is used and successfully parsed, +// that value will be assigned to *offset if offset is non-null. + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + std::cout << month{1}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.month/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.month/types.pass.cpp new file mode 100644 index 0000000..e0dc20e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.month/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ctor.pass.cpp new file mode 100644 index 0000000..9b952c4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ctor.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; +// month_weekday represents the nth weekday of a month, of an as yet unspecified year. + +// constexpr month_weekday(const chrono::month& m, const chrono::weekday_indexed& wdi) noexcept; +// Effects: Constructs an object of type month_weekday by initializing m_ with m, and wdi_ with wdi. +// +// constexpr chrono::month month() const noexcept; +// constexpr chrono::weekday_indexed weekday_indexed() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + ASSERT_NOEXCEPT(month_weekday{month{1}, weekday_indexed{weekday{}, 1}}); + + constexpr month_weekday md0{month{}, weekday_indexed{}}; + static_assert( md0.month() == month{}, ""); + static_assert( md0.weekday_indexed() == weekday_indexed{}, ""); + static_assert(!md0.ok(), ""); + + constexpr month_weekday md1{std::chrono::January, weekday_indexed{std::chrono::Friday, 4}}; + static_assert( md1.month() == std::chrono::January, ""); + static_assert( md1.weekday_indexed() == weekday_indexed{std::chrono::Friday, 4}, ""); + static_assert( md1.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/month.pass.cpp new file mode 100644 index 0000000..21d2748 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/month.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + constexpr weekday Sunday = std::chrono::Sunday; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( month_weekday{}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + month_weekday md(month{i}, weekday_indexed{Sunday, 1}); + assert( static_cast(md.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ok.pass.cpp new file mode 100644 index 0000000..bb1bd35 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/ok.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() && wdi_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + constexpr weekday Sunday = std::chrono::Sunday; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!month_weekday{month{}, weekday_indexed{}}.ok(), ""); + static_assert( month_weekday{std::chrono::May, weekday_indexed{Sunday, 2}}.ok(), ""); + + assert(!(month_weekday(std::chrono::April, weekday_indexed{Sunday, 0}).ok())); + assert( (month_weekday{std::chrono::March, weekday_indexed{Sunday, 1}}.ok())); + + for (unsigned i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 6; ++j) + { + month_weekday mwd{month{i}, weekday_indexed{Sunday, j}}; + assert(mwd.ok() == (j >= 1 && j <= 5)); + } + +// If the month is not ok, all the weekday_indexed are bad + for (unsigned i = 1; i <= 10; ++i) + assert(!(month_weekday{month{13}, weekday_indexed{Sunday, i}}.ok())); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/weekday_indexed.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/weekday_indexed.pass.cpp new file mode 100644 index 0000000..9aebab2 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.members/weekday_indexed.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; + +// constexpr chrono::weekday_indexed weekday_indexed() const noexcept; +// Returns: wdi_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + constexpr weekday Sunday = std::chrono::Sunday; + + ASSERT_NOEXCEPT( std::declval().weekday_indexed()); + ASSERT_SAME_TYPE(weekday_indexed, decltype(std::declval().weekday_indexed())); + + static_assert( month_weekday{month{}, weekday_indexed{}}.weekday_indexed() == weekday_indexed{}, ""); + + for (unsigned i = 1; i <= 10; ++i) + { + month_weekday md(std::chrono::March, weekday_indexed{Sunday, i}); + assert( static_cast(md.weekday_indexed().weekday() == Sunday)); + assert( static_cast(md.weekday_indexed().index() == i)); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..6036138 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/comparisons.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; + +// constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; +// Returns: x.month() == y.month() && x.day() == y.day(). +// + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday_indexed = std::chrono::weekday_indexed; + using weekday = std::chrono::weekday; + + constexpr weekday Sunday = std::chrono::Sunday; + constexpr weekday Monday = std::chrono::Monday; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + static_assert( testComparisons2( + month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, + month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, + true), ""); + + static_assert( testComparisons2( + month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, + month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}}, + false), ""); + + static_assert( testComparisons2( + month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, + month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}}, + false), ""); + + static_assert( testComparisons2( + month_weekday{std::chrono::January, weekday_indexed{Monday, 1}}, + month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}}, + false), ""); + + static_assert( testComparisons2( + month_weekday{std::chrono::January, weekday_indexed{Monday, 1}}, + month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}}, + false), ""); + +// same day, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons2( + month_weekday{month{i}, weekday_indexed{Sunday, 1}}, + month_weekday{month{j}, weekday_indexed{Sunday, 1}}, + i == j))); + +// same month, different weeks + for (unsigned i = 1; i < 5; ++i) + for (unsigned j = 1; j < 5; ++j) + assert((testComparisons2( + month_weekday{month{2}, weekday_indexed{Sunday, i}}, + month_weekday{month{2}, weekday_indexed{Sunday, j}}, + i == j))); + +// same month, different days + for (unsigned i = 0; i < 6; ++i) + for (unsigned j = 0; j < 6; ++j) + assert((testComparisons2( + month_weekday{month{2}, weekday_indexed{weekday{i}, 2}}, + month_weekday{month{2}, weekday_indexed{weekday{j}, 2}}, + i == j))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..be2e46a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/time.cal.mwd.nonmembers/streaming.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class month_weekday; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const month_weekday& mwd); +// +// Returns: os << mwd.month() << '/' << mwd.weekday_indexed(). + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday_indexed = std::chrono::weekday_indexed; + using weekday = std::chrono::weekday; + + std::cout << month_weekday{month{1}, weekday_indexed{weekday{3}, 3}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/types.pass.cpp new file mode 100644 index 0000000..2fcf9b0 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwd/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ctor.pass.cpp new file mode 100644 index 0000000..25cfed6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ctor.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday_last; + +// constexpr month_weekday_last(const chrono::month& m, +// const chrono::weekday_last& wdl) noexcept; +// +// Effects: Constructs an object of type month_weekday_last by +// initializing m_ with m, and wdl_ with wdl. +// +// constexpr chrono::month month() const noexcept; +// constexpr chrono::weekday_last weekday_last() const noexcept; +// constexpr bool ok() const noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using month_weekday_last = std::chrono::month_weekday_last; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + + ASSERT_NOEXCEPT(month_weekday_last{January, weekday_last{Tuesday}}); + +// bad month + constexpr month_weekday_last mwdl1{month{}, weekday_last{Tuesday}}; + static_assert( mwdl1.month() == month{}, ""); + static_assert( mwdl1.weekday_last() == weekday_last{Tuesday}, ""); + static_assert(!mwdl1.ok(), ""); + +// bad weekday_last + constexpr month_weekday_last mwdl2{January, weekday_last{weekday{16}}}; + static_assert( mwdl2.month() == January, ""); + static_assert( mwdl2.weekday_last() == weekday_last{weekday{16}}, ""); + static_assert(!mwdl2.ok(), ""); + +// Good month and weekday_last + constexpr month_weekday_last mwdl3{January, weekday_last{weekday{4}}}; + static_assert( mwdl3.month() == January, ""); + static_assert( mwdl3.weekday_last() == weekday_last{weekday{4}}, ""); + static_assert( mwdl3.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/month.pass.cpp new file mode 100644 index 0000000..fb3fa5d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/month.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday_last; + +// constexpr chrono::month month() const noexcept; +// Returns: m_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using month_weekday_last = std::chrono::month_weekday_last; + + constexpr weekday Tuesday = std::chrono::Tuesday; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( month_weekday_last{month{}, weekday_last{Tuesday}}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + month_weekday_last mdl(month{i}, weekday_last{Tuesday}); + assert( static_cast(mdl.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ok.pass.cpp new file mode 100644 index 0000000..c55a0f6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/ok.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday_last; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() && wdl_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using month_weekday_last = std::chrono::month_weekday_last; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr weekday_last lastTuesday = weekday_last{Tuesday}; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!month_weekday_last{month{}, lastTuesday}.ok(), ""); // Bad month + static_assert(!month_weekday_last{January, weekday_last{weekday{12}}}.ok(), ""); // Bad month + static_assert( month_weekday_last{January, lastTuesday}.ok(), ""); // Both OK + + for (unsigned i = 0; i <= 50; ++i) + { + month_weekday_last mwdl{month{i}, lastTuesday}; + assert( mwdl.ok() == month{i}.ok()); + } + + for (unsigned i = 0; i <= 50; ++i) + { + month_weekday_last mwdl{January, weekday_last{weekday{i}}}; + assert( mwdl.ok() == weekday_last{weekday{i}}.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/weekday_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/weekday_last.pass.cpp new file mode 100644 index 0000000..bf3a44c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.members/weekday_last.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday_last; + +// constexpr chrono::weekday_last weekday_last() const noexcept; +// Returns: wdl_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using month_weekday_last = std::chrono::month_weekday_last; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr weekday_last lastTuesday = weekday_last{Tuesday}; + + ASSERT_NOEXCEPT( std::declval().weekday_last()); + ASSERT_SAME_TYPE(weekday_last, decltype(std::declval().weekday_last())); + + static_assert( month_weekday_last{month{}, lastTuesday}.weekday_last() == lastTuesday, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + month_weekday_last mdl(January, weekday_last{weekday{i}}); + assert( static_cast(mdl.weekday_last().weekday()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..2c41534 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/comparisons.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday_last; + +// constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; +// Returns: x.month() == y.month() +// +// constexpr bool operator< (const month_weekday_last& x, const month_weekday_last& y) noexcept; +// Returns: x.month() < y.month() + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month = std::chrono::month; + using weekday_last = std::chrono::weekday_last; + using weekday = std::chrono::weekday; + using month_weekday_last = std::chrono::month_weekday_last; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr weekday Wednesday = std::chrono::Wednesday; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + static_assert( testComparisons2( + month_weekday_last{std::chrono::January, weekday_last{Tuesday}}, + month_weekday_last{std::chrono::January, weekday_last{Tuesday}}, + true), ""); + + static_assert( testComparisons2( + month_weekday_last{std::chrono::January, weekday_last{Tuesday}}, + month_weekday_last{std::chrono::January, weekday_last{Wednesday}}, + false), ""); + +// vary the months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons2( + month_weekday_last{month{i}, weekday_last{Tuesday}}, + month_weekday_last{month{j}, weekday_last{Tuesday}}, + i == j))); + +// vary the weekday + for (unsigned i = 0; i < 6; ++i) + for (unsigned j = 0; j < 6; ++j) + assert((testComparisons2( + month_weekday_last{January, weekday_last{weekday{i}}}, + month_weekday_last{January, weekday_last{weekday{j}}}, + i == j))); + +// both different + assert((testComparisons2( + month_weekday_last{month{1}, weekday_last{weekday{1}}}, + month_weekday_last{month{2}, weekday_last{weekday{2}}}, + false))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..b8c22cc8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/time.cal.mwdlast.nonmembers/streaming.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class month_weekday_last; +// +// template +// basic_ostream& +// operator<<(basic_ostream& os, const month_weekday_last& mdl); +// +// Returns: os << mdl.month() << "/last". + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday_last = std::chrono::month_weekday_last; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + + std::cout << month_weekday_last{month{1}, weekday_last{weekday{3}}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/types.pass.cpp new file mode 100644 index 0000000..b8ffe35 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.mwdlast/types.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class month_weekday_last; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month_weekday_last = std::chrono::month_weekday_last; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day.pass.cpp new file mode 100644 index 0000000..679e6c4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day; + +// constexpr month_day +// operator/(const month& m, const day& d) noexcept; +// Returns: {m, d}. +// +// constexpr month_day +// operator/(const day& d, const month& m) noexcept; +// Returns: m / d. + +// constexpr month_day +// operator/(const month& m, int d) noexcept; +// Returns: m / day(d). +// +// constexpr month_day +// operator/(int m, const day& d) noexcept; +// Returns: month(m) / d. +// +// constexpr month_day +// operator/(const day& d, int m) noexcept; +// Returns: month(m) / d. + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month_day = std::chrono::month_day; + using month = std::chrono::month; + using day = std::chrono::day; + + constexpr month February = std::chrono::February; + + { // operator/(const month& m, const day& d) (and switched) + ASSERT_NOEXCEPT ( February/day{1}); + ASSERT_SAME_TYPE(month_day, decltype(February/day{1})); + ASSERT_NOEXCEPT ( day{1}/February); + ASSERT_SAME_TYPE(month_day, decltype(day{1}/February)); + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 30; ++j) + { + month m(i); + day d{j}; + month_day md1 = m/d; + month_day md2 = d/m; + assert(md1.month() == m); + assert(md1.day() == d); + assert(md2.month() == m); + assert(md2.day() == d); + assert(md1 == md2); + } + } + + + { // operator/(const month& m, int d) (NOT switched) + ASSERT_NOEXCEPT ( February/2); + ASSERT_SAME_TYPE(month_day, decltype(February/2)); + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 30; ++j) + { + month m(i); + day d(j); + month_day md1 = m/j; + assert(md1.month() == m); + assert(md1.day() == d); + } + } + + + { // operator/(const day& d, int m) (and switched) + ASSERT_NOEXCEPT ( day{2}/2); + ASSERT_SAME_TYPE(month_day, decltype(day{2}/2)); + ASSERT_NOEXCEPT ( 2/day{2}); + ASSERT_SAME_TYPE(month_day, decltype(2/day{2})); + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 30; ++j) + { + month m(i); + day d(j); + month_day md1 = d/i; + month_day md2 = i/d; + assert(md1.month() == m); + assert(md1.day() == d); + assert(md2.month() == m); + assert(md2.day() == d); + assert(md1 == md2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day_last.pass.cpp new file mode 100644 index 0000000..fdba305 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_day_last.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_day_last; + +// constexpr month_day_last +// operator/(const month& m, last_spec) noexcept; +// Returns: month_day_last{m}. +// +// constexpr month_day_last +// operator/(int m, last_spec) noexcept; +// Returns: month(m) / last. +// +// constexpr month_day_last +// operator/(last_spec, const month& m) noexcept; +// Returns: m / last. +// +// constexpr month_day_last +// operator/(last_spec, int m) noexcept; +// Returns: month(m) / last. +// +// +// [Note: A month_day_last object can be constructed using the expression m/last or last/m, +// where m is an expression of type month. — end note] +// [Example: +// constexpr auto mdl = February/last; // mdl is the last day of February of an as yet unspecified year +// static_assert(mdl.month() == February); +// --end example] + + + + + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month = std::chrono::month; + using month_day_last = std::chrono::month_day_last; + + constexpr month February = std::chrono::February; + constexpr std::chrono::last_spec last = std::chrono::last; + + ASSERT_SAME_TYPE(month_day_last, decltype(last/February)); + ASSERT_SAME_TYPE(month_day_last, decltype(February/last)); + +// Run the example + { + constexpr auto mdl = February/std::chrono::last; + static_assert(mdl.month() == February, ""); + } + + { // operator/(const month& m, last_spec) and switched + ASSERT_NOEXCEPT ( last/February); + ASSERT_SAME_TYPE(month_day_last, decltype(last/February)); + ASSERT_NOEXCEPT ( February/last); + ASSERT_SAME_TYPE(month_day_last, decltype(February/last)); + + static_assert((last/February).month() == February, ""); + static_assert((February/last).month() == February, ""); + + for (unsigned i = 1; i < 12; ++i) + { + month m{i}; + month_day_last mdl1 = last/m; + month_day_last mdl2 = m/last; + assert(mdl1.month() == m); + assert(mdl2.month() == m); + assert(mdl1 == mdl2); + } + } + + { // operator/(int, last_spec) and switched + ASSERT_NOEXCEPT ( last/2); + ASSERT_SAME_TYPE(month_day_last, decltype(last/2)); + ASSERT_NOEXCEPT ( 2/last); + ASSERT_SAME_TYPE(month_day_last, decltype(2/last)); + + static_assert((last/2).month() == February, ""); + static_assert((2/last).month() == February, ""); + + for (unsigned i = 1; i < 12; ++i) + { + month m{i}; + month_day_last mdl1 = last/i; + month_day_last mdl2 = i/last; + assert(mdl1.month() == m); + assert(mdl2.month() == m); + assert(mdl1 == mdl2); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday.pass.cpp new file mode 100644 index 0000000..e23dfef --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday; + +// constexpr month_weekday +// operator/(const month& m, const weekday_indexed& wdi) noexcept; +// Returns: {m, wdi}. +// +// constexpr month_weekday +// operator/(int m, const weekday_indexed& wdi) noexcept; +// Returns: month(m) / wdi. +// +// constexpr month_weekday +// operator/(const weekday_indexed& wdi, const month& m) noexcept; +// Returns: m / wdi. constexpr month_weekday +// +// constexpr month_weekday +// operator/(const weekday_indexed& wdi, int m) noexcept; +// Returns: month(m) / wdi. + + +// +// [Example: +// constexpr auto mwd = February/Tuesday[3]; // mwd is the third Tuesday of February of an as yet unspecified year +// static_assert(mwd.month() == February); +// static_assert(mwd.weekday_indexed() == Tuesday[3]); +// —end example] + + + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month February = std::chrono::February; + + { // operator/(const month& m, const weekday_indexed& wdi) (and switched) + ASSERT_NOEXCEPT (February/Tuesday[2]); + ASSERT_SAME_TYPE(month_weekday, decltype(February/Tuesday[2])); + ASSERT_NOEXCEPT (Tuesday[2]/February); + ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/February)); + + // Run the example + { + constexpr month_weekday wdi = February/Tuesday[3]; + static_assert(wdi.month() == February, ""); + static_assert(wdi.weekday_indexed() == Tuesday[3], ""); + } + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 6; ++j) + for (unsigned k = 1; k <= 5; ++k) + { + month m(i); + weekday_indexed wdi = weekday{j}[k]; + month_weekday mwd1 = m/wdi; + month_weekday mwd2 = wdi/m; + assert(mwd1.month() == m); + assert(mwd1.weekday_indexed() == wdi); + assert(mwd2.month() == m); + assert(mwd2.weekday_indexed() == wdi); + assert(mwd1 == mwd2); + } + } + + + { // operator/(int m, const weekday_indexed& wdi) (and switched) + ASSERT_NOEXCEPT (2/Tuesday[2]); + ASSERT_SAME_TYPE(month_weekday, decltype(2/Tuesday[2])); + ASSERT_NOEXCEPT (Tuesday[2]/2); + ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/2)); + + // Run the example + { + constexpr month_weekday wdi = 2/Tuesday[3]; + static_assert(wdi.month() == February, ""); + static_assert(wdi.weekday_indexed() == Tuesday[3], ""); + } + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 6; ++j) + for (unsigned k = 1; k <= 5; ++k) + { + weekday_indexed wdi = weekday{j}[k]; + month_weekday mwd1 = i/wdi; + month_weekday mwd2 = wdi/i; + assert(mwd1.month() == month(i)); + assert(mwd1.weekday_indexed() == wdi); + assert(mwd2.month() == month(i)); + assert(mwd2.weekday_indexed() == wdi); + assert(mwd1 == mwd2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday_last.pass.cpp new file mode 100644 index 0000000..f3a0233 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/month_weekday_last.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class month_weekday_last; + +// constexpr month_weekday_last +// operator/(const month& m, const weekday_last& wdl) noexcept; +// Returns: {m, wdl}. +// +// constexpr month_weekday_last +// operator/(int m, const weekday_last& wdl) noexcept; +// Returns: month(m) / wdl. +// +// constexpr month_weekday_last +// operator/(const weekday_last& wdl, const month& m) noexcept; +// Returns: m / wdl. +// +// constexpr month_weekday_last +// operator/(const weekday_last& wdl, int m) noexcept; +// Returns: month(m) / wdl. + + + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using month_weekday_last = std::chrono::month_weekday_last; + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month February = std::chrono::February; + constexpr std::chrono::last_spec last = std::chrono::last; + + { // operator/(const month& m, const weekday_last& wdi) (and switched) + ASSERT_NOEXCEPT (February/Tuesday[last]); + ASSERT_SAME_TYPE(month_weekday_last, decltype(February/Tuesday[last])); + ASSERT_NOEXCEPT (Tuesday[last]/February); + ASSERT_SAME_TYPE(month_weekday_last, decltype(Tuesday[last]/February)); + + // Run the example + { + constexpr month_weekday_last wdi = February/Tuesday[last]; + static_assert(wdi.month() == February, ""); + static_assert(wdi.weekday_last() == Tuesday[last], ""); + } + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 6; ++j) + { + month m(i); + weekday_last wdi = weekday{j}[last]; + month_weekday_last mwd1 = m/wdi; + month_weekday_last mwd2 = wdi/m; + assert(mwd1.month() == m); + assert(mwd1.weekday_last() == wdi); + assert(mwd2.month() == m); + assert(mwd2.weekday_last() == wdi); + assert(mwd1 == mwd2); + } + } + + + { // operator/(int m, const weekday_last& wdi) (and switched) + ASSERT_NOEXCEPT (2/Tuesday[2]); + ASSERT_SAME_TYPE(month_weekday_last, decltype(2/Tuesday[last])); + ASSERT_NOEXCEPT (Tuesday[2]/2); + ASSERT_SAME_TYPE(month_weekday_last, decltype(Tuesday[last]/2)); + + // Run the example + { + constexpr month_weekday wdi = 2/Tuesday[3]; + static_assert(wdi.month() == February, ""); + static_assert(wdi.weekday_indexed() == Tuesday[3], ""); + } + + for (int i = 1; i <= 12; ++i) + for (unsigned j = 0; j <= 6; ++j) + { + weekday_last wdi = weekday{j}[last]; + month_weekday_last mwd1 = i/wdi; + month_weekday_last mwd2 = wdi/i; + assert(mwd1.month() == month(i)); + assert(mwd1.weekday_last() == wdi); + assert(mwd2.month() == month(i)); + assert(mwd2.weekday_last() == wdi); + assert(mwd1 == mwd2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month.pass.cpp new file mode 100644 index 0000000..3a85c1a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr year_month operator/(const year& y, const month& m) noexcept; +// Returns: {y, m}. +// +// constexpr year_month operator/(const year& y, int m) noexcept; +// Returns: y / month(m). + + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month = std::chrono::month; + using year = std::chrono::year; + using year_month = std::chrono::year_month; + + constexpr month February = std::chrono::February; + + { // operator/(const year& y, const month& m) + ASSERT_NOEXCEPT ( year{2018}/February); + ASSERT_SAME_TYPE(year_month, decltype(year{2018}/February)); + + static_assert((year{2018}/February).year() == year{2018}, ""); + static_assert((year{2018}/February).month() == month{2}, ""); + for (int i = 1000; i <= 1030; ++i) + for (unsigned j = 1; j <= 12; ++j) + { + year_month ym = year{i}/month{j}; + assert(static_cast(ym.year()) == i); + assert(static_cast(ym.month()) == j); + } + } + + + { // operator/(const year& y, const int m) + ASSERT_NOEXCEPT ( year{2018}/4); + ASSERT_SAME_TYPE(year_month, decltype(year{2018}/4)); + + static_assert((year{2018}/2).year() == year{2018}, ""); + static_assert((year{2018}/2).month() == month{2}, ""); + + for (int i = 1000; i <= 1030; ++i) + for (unsigned j = 1; j <= 12; ++j) + { + year_month ym = year{i}/j; + assert(static_cast(ym.year()) == i); + assert(static_cast(ym.month()) == j); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day.pass.cpp new file mode 100644 index 0000000..b34103a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day.pass.cpp @@ -0,0 +1,192 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr year_month_day +// operator/(const year_month& ym, const day& d) noexcept; +// Returns: {ym.year(), ym.month(), d}. +// +// constexpr year_month_day +// operator/(const year_month& ym, int d) noexcept; +// Returns: ym / day(d). +// +// constexpr year_month_day +// operator/(const year& y, const month_day& md) noexcept; +// Returns: y / md.month() / md.day(). +// +// constexpr year_month_day +// operator/(int y, const month_day& md) noexcept; +// Returns: year(y) / md. +// +// constexpr year_month_day +// operator/(const month_day& md, const year& y) noexcept; +// Returns: y / md. +// +// constexpr year_month_day +// operator/(const month_day& md, int y) noexcept; +// Returns: year(y) / md. + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month = std::chrono::year_month; + using month_day = std::chrono::month_day; + using year_month_day = std::chrono::year_month_day; + using weekday = std::chrono::weekday; + + constexpr month February = std::chrono::February; + constexpr year_month Feb2018{year{2018}, February}; + + { // operator/(const year_month& ym, const day& d) + ASSERT_NOEXCEPT ( Feb2018/day{2}); + ASSERT_SAME_TYPE(year_month_day, decltype(Feb2018/day{2})); + + static_assert((Feb2018/day{2}).month() == February, ""); + static_assert((Feb2018/day{2}).day() == day{2}, ""); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 28; ++k) + { + year y(i); + month m(j); + day d(k); + year_month ym(y, m); + year_month_day ymd = ym/d; + assert(ymd.year() == y); + assert(ymd.month() == m); + assert(ymd.day() == d); + } + } + + + { // operator/(const year_month& ym, int d) + ASSERT_NOEXCEPT ( Feb2018/2); + ASSERT_SAME_TYPE(year_month_day, decltype(Feb2018/2)); + + static_assert((Feb2018/2).month() == February, ""); + static_assert((Feb2018/2).day() == day{2}, ""); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 28; ++k) + { + year y(i); + month m(j); + day d(k); + year_month ym(y, m); + year_month_day ymd = ym/k; + assert(ymd.year() == y); + assert(ymd.month() == m); + assert(ymd.day() == d); + } + } + + + { // operator/(const year_month& ym, int d) + ASSERT_NOEXCEPT ( Feb2018/2); + ASSERT_SAME_TYPE(year_month_day, decltype(Feb2018/2)); + + static_assert((Feb2018/2).month() == February, ""); + static_assert((Feb2018/2).day() == day{2}, ""); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 28; ++k) + { + year y(i); + month m(j); + day d(k); + year_month ym(y, m); + year_month_day ymd = ym/k; + assert(ymd.year() == y); + assert(ymd.month() == m); + assert(ymd.day() == d); + } + } + + + + + { // operator/(const year& y, const month_day& md) (and switched) + ASSERT_NOEXCEPT ( year{2018}/month_day{February, day{2}}); + ASSERT_SAME_TYPE(year_month_day, decltype(year{2018}/month_day{February, day{2}})); + ASSERT_NOEXCEPT ( month_day{February, day{2}}/year{2018}); + ASSERT_SAME_TYPE(year_month_day, decltype(month_day{February, day{2}}/year{2018})); + + static_assert((year{2018}/month_day{February, day{2}}).month() == February, "" ); + static_assert((year{2018}/month_day{February, day{2}}).day() == day{2}, "" ); + static_assert((month_day{February, day{2}}/year{2018}).month() == February, "" ); + static_assert((month_day{February, day{2}}/year{2018}).day() == day{2}, "" ); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 28; ++k) + { + year y(i); + month m(j); + day d(k); + month_day md(m, d); + year_month_day ymd1 = y/md; + year_month_day ymd2 = md/y; + assert(ymd1.year() == y); + assert(ymd2.year() == y); + assert(ymd1.month() == m); + assert(ymd2.month() == m); + assert(ymd1.day() == d); + assert(ymd2.day() == d); + assert(ymd1 == ymd2); + } + } + + { // operator/(const month_day& md, int y) (and switched) + ASSERT_NOEXCEPT ( 2018/month_day{February, day{2}}); + ASSERT_SAME_TYPE(year_month_day, decltype(2018/month_day{February, day{2}})); + ASSERT_NOEXCEPT ( month_day{February, day{2}}/2018); + ASSERT_SAME_TYPE(year_month_day, decltype(month_day{February, day{2}}/2018)); + + static_assert((2018/month_day{February, day{2}}).month() == February, "" ); + static_assert((2018/month_day{February, day{2}}).day() == day{2}, "" ); + static_assert((month_day{February, day{2}}/2018).month() == February, "" ); + static_assert((month_day{February, day{2}}/2018).day() == day{2}, "" ); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 28; ++k) + { + year y(i); + month m(j); + day d(k); + month_day md(m, d); + year_month_day ymd1 = i/md; + year_month_day ymd2 = md/i; + assert(ymd1.year() == y); + assert(ymd2.year() == y); + assert(ymd1.month() == m); + assert(ymd2.month() == m); + assert(ymd1.day() == d); + assert(ymd2.day() == d); + assert(ymd1 == ymd2); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day_last.pass.cpp new file mode 100644 index 0000000..a237842 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day_last.pass.cpp @@ -0,0 +1,129 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// +// class year_month_day_last; + +// constexpr year_month_day_last +// operator/(const year_month& ym, last_spec) noexcept; +// Returns: {ym.year(), month_day_last{ym.month()}}. + + +// constexpr year_month_day_last +// operator/(const year& y, const month_day_last& mdl) noexcept; +// Returns: {y, mdl}. +// +// constexpr year_month_day_last +// operator/(int y, const month_day_last& mdl) noexcept; +// Returns: year(y) / mdl. +// +// constexpr year_month_day_last +// operator/(const month_day_last& mdl, const year& y) noexcept; +// Returns: y / mdl. +// +// constexpr year_month_day_last +// operator/(const month_day_last& mdl, int y) noexcept; +// Returns: year(y) / mdl. + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using month_weekday = std::chrono::month_weekday; + using month = std::chrono::month; + using year_month = std::chrono::year_month; + using year = std::chrono::year; + using weekday_last = std::chrono::weekday_last; + using weekday = std::chrono::weekday; + using month_weekday_last = std::chrono::month_weekday_last; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + constexpr month February = std::chrono::February; + constexpr std::chrono::last_spec last = std::chrono::last; + + { // operator/(const year_month& ym, last_spec) + constexpr year_month Feb2018{year{2018}, February}; + + ASSERT_NOEXCEPT ( Feb2018/last); + ASSERT_SAME_TYPE(year_month_day_last, decltype(Feb2018/last)); + + static_assert((Feb2018/last).year() == year{2018}, ""); + static_assert((Feb2018/last).month() == February, ""); + + for (int i = 1000; i < 1010; ++i) + for (unsigned j = 1; j <= 12; ++j) + { + year y{i}; + month m{j}; + year_month_day_last ymdl = year_month{y,m}/last; + assert(ymdl.year() == y); + assert(ymdl.month() == m); + } + } + + + { // operator/(const year& y, const month_day_last& mdl) (and switched) + ASSERT_NOEXCEPT ( year{2018}/month_day_last{February}); + ASSERT_SAME_TYPE(year_month_day_last, decltype(year{2018}/month_day_last{February})); + ASSERT_NOEXCEPT ( month_day_last{February}/year{2018}); + ASSERT_SAME_TYPE(year_month_day_last, decltype(month_day_last{February}/year{2018})); + + static_assert((year{2018}/month_day_last{February}).month() == February, ""); + static_assert((year{2018}/month_day_last{February}).year() == year{2018}, ""); + static_assert((month_day_last{February}/year{2018}).month() == February, ""); + static_assert((month_day_last{February}/year{2018}).year() == year{2018}, ""); + + for (int i = 1000; i < 1010; ++i) + for (unsigned j = 1; j <= 12; ++j) + { + year y{i}; + month m{j}; + year_month_day_last ymdl1 = y/month_day_last{m}; + year_month_day_last ymdl2 = month_day_last{m}/y; + assert(ymdl1.month() == m); + assert(ymdl2.month() == m); + assert(ymdl2.year() == y); + assert(ymdl1.year() == y); + assert(ymdl1 == ymdl2); + } + } + + { // operator/(int y, const month_day_last& mdl) (and switched) + ASSERT_NOEXCEPT ( 2018/month_day_last{February}); + ASSERT_SAME_TYPE(year_month_day_last, decltype(2018/month_day_last{February})); + ASSERT_NOEXCEPT ( month_day_last{February}/2018); + ASSERT_SAME_TYPE(year_month_day_last, decltype(month_day_last{February}/2018)); + + static_assert((2018/month_day_last{February}).month() == February, ""); + static_assert((2018/month_day_last{February}).year() == year{2018}, ""); + static_assert((month_day_last{February}/2018).month() == February, ""); + static_assert((month_day_last{February}/2018).year() == year{2018}, ""); + + for (int i = 1000; i < 1010; ++i) + for (unsigned j = 1; j <= 12; ++j) + { + year y{i}; + month m{j}; + year_month_day_last ymdl1 = i/month_day_last{m}; + year_month_day_last ymdl2 = month_day_last{m}/i; + assert(ymdl1.month() == m); + assert(ymdl2.month() == m); + assert(ymdl2.year() == y); + assert(ymdl1.year() == y); + assert(ymdl1 == ymdl2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday.pass.cpp new file mode 100644 index 0000000..5299b5b --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr year_month_weekday +// operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; +// Returns: {ym.year(), ym.month(), wdi}. +// +// constexpr year_month_weekday +// operator/(const year& y, const month_weekday& mwd) noexcept; +// Returns: {y, mwd.month(), mwd.weekday_indexed()}. +// +// constexpr year_month_weekday +// operator/(int y, const month_weekday& mwd) noexcept; +// Returns: year(y) / mwd. +// +// constexpr year_month_weekday +// operator/(const month_weekday& mwd, const year& y) noexcept; +// Returns: y / mwd. +// +// constexpr year_month_weekday +// operator/(const month_weekday& mwd, int y) noexcept; +// Returns: year(y) / mwd. + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year = std::chrono::year; + using year_month = std::chrono::year_month; + using month_weekday = std::chrono::month_weekday; + using year_month_weekday = std::chrono::year_month_weekday; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month February = std::chrono::February; + + + { // operator/(const year_month& ym, const weekday_indexed& wdi) + constexpr year_month Feb2018{year{2018}, February}; + + ASSERT_NOEXCEPT ( Feb2018/weekday_indexed{Tuesday, 2}); + ASSERT_SAME_TYPE(year_month_weekday, decltype(Feb2018/weekday_indexed{Tuesday, 2})); + + static_assert((Feb2018/weekday_indexed{Tuesday, 2}).year() == year{2018}, "" ); + static_assert((Feb2018/weekday_indexed{Tuesday, 2}).month() == February, "" ); + static_assert((Feb2018/weekday_indexed{Tuesday, 2}).weekday() == Tuesday, "" ); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 6; ++k) + for (unsigned l = 1; l <= 5; ++l) + { + year y(i); + month m(j); + weekday wd{k}; + year_month_weekday ymd = year_month{y,m}/weekday_indexed{wd,l}; + assert(ymd.year() == y); + assert(ymd.month() == m); + assert(ymd.weekday() == wd); + } + } + + { // operator/(const year& y, const month_weekday& mwd) (and switched) + constexpr month_weekday Feb1stTues{February, weekday_indexed{Tuesday, 1}}; + ASSERT_NOEXCEPT ( year{2018}/Feb1stTues); + ASSERT_SAME_TYPE(year_month_weekday, decltype(year{2018}/Feb1stTues)); + ASSERT_NOEXCEPT ( Feb1stTues/year{2018}); + ASSERT_SAME_TYPE(year_month_weekday, decltype(Feb1stTues/year{2018})); + + static_assert((year{2018}/Feb1stTues).year() == year{2018}, "" ); + static_assert((year{2018}/Feb1stTues).month() == February, "" ); + static_assert((year{2018}/Feb1stTues).weekday() == Tuesday, "" ); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 6; ++k) + for (unsigned l = 1; l <= 5; ++l) + { + year y(i); + month m(j); + weekday wd{k}; + month_weekday mwd{m, weekday_indexed{weekday{k}, l}}; + year_month_weekday ymd1 = y/mwd; + year_month_weekday ymd2 = mwd/y; + assert(ymd1.year() == y); + assert(ymd2.year() == y); + assert(ymd1.month() == m); + assert(ymd2.month() == m); + assert(ymd1.weekday() == wd); + assert(ymd2.weekday() == wd); + assert(ymd1 == ymd2); + } + } + + + { // operator/(int y, const month_weekday& mwd) (and switched) + constexpr month_weekday Feb1stTues{February, weekday_indexed{Tuesday, 1}}; + ASSERT_NOEXCEPT ( 2018/Feb1stTues); + ASSERT_SAME_TYPE(year_month_weekday, decltype(2018/Feb1stTues)); + ASSERT_NOEXCEPT ( Feb1stTues/2018); + ASSERT_SAME_TYPE(year_month_weekday, decltype(Feb1stTues/2018)); + + static_assert((2018/Feb1stTues).year() == year{2018}, "" ); + static_assert((2018/Feb1stTues).month() == February, "" ); + static_assert((2018/Feb1stTues).weekday() == Tuesday, "" ); + + for (int i = 1000; i < 1010; ++i) + for (int j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 6; ++k) + for (unsigned l = 1; l <= 5; ++l) + { + year y(i); + month m(j); + weekday wd{k}; + month_weekday mwd{m, weekday_indexed{weekday{k}, l}}; + year_month_weekday ymd1 = i/mwd; + year_month_weekday ymd2 = mwd/i; + assert(ymd1.year() == y); + assert(ymd2.year() == y); + assert(ymd1.month() == m); + assert(ymd2.month() == m); + assert(ymd1.weekday() == wd); + assert(ymd2.weekday() == wd); + assert(ymd1 == ymd2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday_last.pass.cpp new file mode 100644 index 0000000..7ceaffa --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_weekday_last.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr year_month_weekday_last +// operator/(const year_month& ym, const weekday_last& wdl) noexcept; +// Returns: {ym.year(), ym.month(), wdl}. +// +// constexpr year_month_weekday_last +// operator/(const year& y, const month_weekday_last& mwdl) noexcept; +// Returns: {y, mwdl.month(), mwdl.weekday_last()}. +// +// constexpr year_month_weekday_last +// operator/(int y, const month_weekday_last& mwdl) noexcept; +// Returns: year(y) / mwdl. +// +// constexpr year_month_weekday_last +// operator/(const month_weekday_last& mwdl, const year& y) noexcept; +// Returns: y / mwdl. +// +// constexpr year_month_weekday_last +// operator/(const month_weekday_last& mwdl, int y) noexcept; +// Returns: year(y) / mwdl. + + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year_month = std::chrono::year_month; + using month_weekday = std::chrono::month_weekday; + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using month_weekday_last = std::chrono::month_weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month February = std::chrono::February; + + { // operator/(const year_month& ym, const weekday_last& wdl) (and switched) + constexpr year_month Feb2018{year{2018}, February}; + + ASSERT_NOEXCEPT ( Feb2018/weekday_last{Tuesday}); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(Feb2018/weekday_last{Tuesday})); + + static_assert((Feb2018/weekday_last{Tuesday}).year() == year{2018}, ""); + static_assert((Feb2018/weekday_last{Tuesday}).month() == February, ""); + static_assert((Feb2018/weekday_last{Tuesday}).weekday() == Tuesday, ""); + + for (int i = 1000; i < 1010; ++i) + for (unsigned j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 6; ++k) + { + year y{i}; + month m{j}; + weekday wd{k}; + year_month_weekday_last ymwdl = year_month{y,m}/weekday_last{wd}; + assert(ymwdl.year() == y); + assert(ymwdl.month() == m); + assert(ymwdl.weekday() == wd); + } + } + + + { // operator/(const year& y, const month_weekday_last& mwdl) (and switched) + constexpr month_weekday_last FebLastTues{February, weekday_last{Tuesday}}; + + ASSERT_NOEXCEPT ( year{2018}/FebLastTues); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(year{2018}/FebLastTues)); + ASSERT_NOEXCEPT ( FebLastTues/year{2018}); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(FebLastTues/year{2018})); + + + static_assert((year{2018}/FebLastTues).year() == year{2018}, ""); + static_assert((year{2018}/FebLastTues).month() == February, ""); + static_assert((year{2018}/FebLastTues).weekday() == Tuesday, ""); + static_assert((FebLastTues/year{2018}).year() == year{2018}, ""); + static_assert((FebLastTues/year{2018}).month() == February, ""); + static_assert((FebLastTues/year{2018}).weekday() == Tuesday, ""); + + + for (int i = 1000; i < 1010; ++i) + for (unsigned j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 6; ++k) + { + year y{i}; + month m{j}; + weekday wd{k}; + year_month_weekday_last ymwdl1 = y/month_weekday_last{m, weekday_last{wd}}; + year_month_weekday_last ymwdl2 = month_weekday_last{m, weekday_last{wd}}/y; + assert(ymwdl1.year() == y); + assert(ymwdl2.year() == y); + assert(ymwdl1.month() == m); + assert(ymwdl2.month() == m); + assert(ymwdl1.weekday() == wd); + assert(ymwdl2.weekday() == wd); + assert(ymwdl1 == ymwdl2); + } + } + + + { // operator/(int y, const month_weekday_last& mwdl) (and switched) + constexpr month_weekday_last FebLastTues{February, weekday_last{Tuesday}}; + + ASSERT_NOEXCEPT ( 2018/FebLastTues); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(2018/FebLastTues)); + ASSERT_NOEXCEPT ( FebLastTues/2018); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(FebLastTues/2018)); + + + static_assert((2018/FebLastTues).year() == year{2018}, ""); + static_assert((2018/FebLastTues).month() == February, ""); + static_assert((2018/FebLastTues).weekday() == Tuesday, ""); + static_assert((FebLastTues/2018).year() == year{2018}, ""); + static_assert((FebLastTues/2018).month() == February, ""); + static_assert((FebLastTues/2018).weekday() == Tuesday, ""); + + + for (int i = 1000; i < 1010; ++i) + for (unsigned j = 1; j <= 12; ++j) + for (unsigned k = 0; k <= 6; ++k) + { + year y{i}; + month m{j}; + weekday wd{k}; + year_month_weekday_last ymwdl1 = i/month_weekday_last{m, weekday_last{wd}}; + year_month_weekday_last ymwdl2 = month_weekday_last{m, weekday_last{wd}}/i; + assert(ymwdl1.year() == y); + assert(ymwdl2.year() == y); + assert(ymwdl1.month() == m); + assert(ymwdl2.month() == m); + assert(ymwdl1.weekday() == wd); + assert(ymwdl2.weekday() == wd); + assert(ymwdl1 == ymwdl2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ctor.pass.cpp new file mode 100644 index 0000000..4c13bde --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ctor.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_indexed; + +// weekday_indexed() = default; +// constexpr weekday_indexed(const chrono::weekday& wd, unsigned index) noexcept; +// +// Effects: Constructs an object of type weekday_indexed by initializing wd_ with wd and index_ with index. +// The values held are unspecified if !wd.ok() or index is not in the range [1, 5]. +// +// constexpr chrono::weekday weekday() const noexcept; +// constexpr unsigned index() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + ASSERT_NOEXCEPT(weekday_indexed{}); + ASSERT_NOEXCEPT(weekday_indexed(weekday{1}, 1)); + + constexpr weekday_indexed wdi0{}; + static_assert( wdi0.weekday() == weekday{}, ""); + static_assert( wdi0.index() == 0, ""); + static_assert(!wdi0.ok(), ""); + + constexpr weekday_indexed wdi1{std::chrono::Sunday, 2}; + static_assert( wdi1.weekday() == std::chrono::Sunday, ""); + static_assert( wdi1.index() == 2, ""); + static_assert( wdi1.ok(), ""); + + for (unsigned i = 1; i <= 5; ++i) + { + weekday_indexed wdi(std::chrono::Tuesday, i); + assert( wdi.weekday() == std::chrono::Tuesday); + assert( wdi.index() == i); + assert( wdi.ok()); + } + + for (unsigned i = 6; i <= 20; ++i) + { + weekday_indexed wdi(std::chrono::Tuesday, i); + assert(!wdi.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/index.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/index.pass.cpp new file mode 100644 index 0000000..0d03dbb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/index.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_indexed; + +// constexpr unsigned index() const noexcept; +// Returns: index_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + ASSERT_NOEXCEPT( std::declval().index()); + ASSERT_SAME_TYPE(unsigned, decltype(std::declval().index())); + + static_assert( weekday_indexed{}.index() == 0, ""); + + for (unsigned i = 1; i <= 5; ++i) + { + weekday_indexed wdi(weekday{2}, i); + assert( static_cast(wdi.index()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ok.pass.cpp new file mode 100644 index 0000000..e0277f6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/ok.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_indexed; + +// constexpr bool ok() const noexcept; +// Returns: wd_.ok() && 1 <= index_ && index_ <= 5 + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!weekday_indexed{}.ok(), ""); + static_assert( weekday_indexed{std::chrono::Sunday, 2}.ok(), ""); + + assert(!(weekday_indexed(std::chrono::Tuesday, 0).ok())); + for (unsigned i = 1; i <= 5; ++i) + { + weekday_indexed wdi(std::chrono::Tuesday, i); + assert( wdi.ok()); + } + + for (unsigned i = 6; i <= 20; ++i) + { + weekday_indexed wdi(std::chrono::Tuesday, i); + assert(!wdi.ok()); + } + +// Not a valid weekday + assert(!(weekday_indexed(weekday{9U}, 1).ok())); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/weekday.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/weekday.pass.cpp new file mode 100644 index 0000000..484c19c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.members/weekday.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_indexed; + +// constexpr chrono::weekday weekday() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + ASSERT_NOEXCEPT( std::declval().weekday()); + ASSERT_SAME_TYPE(std::chrono::weekday, decltype(std::declval().weekday())); + + static_assert( weekday_indexed{}.weekday() == weekday{}, ""); + static_assert( weekday_indexed{std::chrono::Tuesday, 0}.weekday() == std::chrono::Tuesday, ""); + + for (unsigned i = 0; i <= 6; ++i) + { + weekday_indexed wdi(weekday{i}, 2); + assert( static_cast(wdi.weekday()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..acaca80 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/comparisons.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_indexed; + +// constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; +// Returns: x.weekday() == y.weekday() && x.index() == y.index(). +// constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; +// Returns: !(x == y) + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + static_assert( (weekday_indexed{} == weekday_indexed{}), ""); + static_assert(!(weekday_indexed{} != weekday_indexed{}), ""); + + static_assert(!(weekday_indexed{} == weekday_indexed{std::chrono::Tuesday, 1}), ""); + static_assert( (weekday_indexed{} != weekday_indexed{std::chrono::Tuesday, 1}), ""); + +// Some 'ok' values as well + static_assert( (weekday_indexed{weekday{1}, 2} == weekday_indexed{weekday{1}, 2}), ""); + static_assert(!(weekday_indexed{weekday{1}, 2} != weekday_indexed{weekday{1}, 2}), ""); + + static_assert(!(weekday_indexed{weekday{1}, 2} == weekday_indexed{weekday{1}, 1}), ""); + static_assert( (weekday_indexed{weekday{1}, 2} != weekday_indexed{weekday{1}, 1}), ""); + static_assert(!(weekday_indexed{weekday{1}, 2} == weekday_indexed{weekday{2}, 2}), ""); + static_assert( (weekday_indexed{weekday{1}, 2} != weekday_indexed{weekday{2}, 2}), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..9938b8a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/time.cal.wdidx.nonmembers/streaming.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class weekday_indexed; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const weekday_indexed& wdi); +// +// Effects: os << wdi.weekday() << '[' << wdi.index(). +// If wdi.index() is in the range [1, 5], appends with ']', +// otherwise appends with " is not a valid index]". + + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday_indexed = std::chrono::weekday_indexed; + using weekday = std::chrono::weekday; + + std::cout << weekday_indexed{weekday{3}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/types.pass.cpp new file mode 100644 index 0000000..8b2e70e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdidx/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_indexed; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday_indexed = std::chrono::weekday_indexed; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ctor.pass.cpp new file mode 100644 index 0000000..facc1dc --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ctor.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_last; + +// explicit constexpr weekday_last(const chrono::weekday& wd) noexcept; +// +// Effects: Constructs an object of type weekday_last by initializing wd_ with wd. +// +// constexpr chrono::weekday weekday() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + + ASSERT_NOEXCEPT(weekday_last{weekday{}}); + + constexpr weekday_last wdl0{weekday{}}; + static_assert( wdl0.weekday() == weekday{}, ""); + static_assert( wdl0.ok(), ""); + + constexpr weekday_last wdl1 {weekday{1}}; + static_assert( wdl1.weekday() == weekday{1}, ""); + static_assert( wdl1.ok(), ""); + + for (unsigned i = 0; i <= 255; ++i) + { + weekday_last wdl{weekday{i}}; + assert(wdl.weekday() == weekday{i}); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ok.pass.cpp new file mode 100644 index 0000000..7c842b1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/ok.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_last; + +// constexpr bool ok() const noexcept; +// Returns: wd_.ok() + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert( weekday_last{weekday{0}}.ok(), ""); + static_assert( weekday_last{weekday{1}}.ok(), ""); + static_assert(!weekday_last{weekday{7}}.ok(), ""); + + for (unsigned i = 0; i <= 255; ++i) + assert(weekday_last{weekday{i}}.ok() == weekday{i}.ok()); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/weekday.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/weekday.pass.cpp new file mode 100644 index 0000000..191f23e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.members/weekday.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_last; + +// constexpr chrono::weekday weekday() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + + ASSERT_NOEXCEPT( std::declval().weekday()); + ASSERT_SAME_TYPE(weekday, decltype(std::declval().weekday())); + + for (unsigned i = 0; i <= 255; ++i) + assert(weekday_last{weekday{i}}.weekday() == weekday{i}); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..180a0a3 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/comparisons.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_last; + +// constexpr bool operator==(const weekday& x, const weekday& y) noexcept; +// constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + static_assert(testComparisons2Values(weekday{0}, weekday{0}), ""); + static_assert(testComparisons2Values(weekday{0}, weekday{1}), ""); + +// Some 'ok' values as well + static_assert(testComparisons2Values(weekday{2}, weekday{2}), ""); + static_assert(testComparisons2Values(weekday{2}, weekday{3}), ""); + + for (unsigned i = 0; i < 6; ++i) + for (unsigned j = 0; j < 6; ++j) + assert(testComparisons2Values(weekday{i}, weekday{j})); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..6185443 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/time.cal.wdlast.nonmembers/streaming.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class weekday_last; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const weekday_last& wdl); +// +// Returns: os << wdl.weekday() << "[last]". + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday_last = std::chrono::weekday_last; + using weekday = std::chrono::weekday; + + std::cout << weekday_last{weekday{3}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/types.pass.cpp new file mode 100644 index 0000000..51bc8f9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.wdlast/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday_last; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday_last = std::chrono::weekday_last; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ctor.pass.cpp new file mode 100644 index 0000000..95e4985 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ctor.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// weekday() = default; +// explicit constexpr weekday(unsigned wd) noexcept; +// constexpr weekday(const sys_days& dp) noexcept; +// explicit constexpr weekday(const local_days& dp) noexcept; +// +// explicit constexpr operator unsigned() const noexcept; + +// Effects: Constructs an object of type weekday by initializing m_ with m. +// The value held is unspecified if d is not in the range [0, 255]. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + + ASSERT_NOEXCEPT(weekday{}); + ASSERT_NOEXCEPT(weekday(1)); + ASSERT_NOEXCEPT(static_cast(weekday(1))); + + constexpr weekday m0{}; + static_assert(static_cast(m0) == 0, ""); + + constexpr weekday m1{1}; + static_assert(static_cast(m1) == 1, ""); + + for (unsigned i = 0; i <= 255; ++i) + { + weekday m(i); + assert(static_cast(m) == i); + } + +// TODO - sys_days and local_days ctor tests +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/decrement.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/decrement.pass.cpp new file mode 100644 index 0000000..213e728 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/decrement.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr weekday& operator--() noexcept; +// constexpr weekday operator--(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "../../euclidian.h" + +template +constexpr bool testConstexpr() +{ + WD wd{1}; + if (static_cast(--wd) != 0) return false; + if (static_cast(wd--) != 0) return false; + if (static_cast(wd) != 6) return false; + return true; +} + +int main() +{ + using weekday = std::chrono::weekday; + ASSERT_NOEXCEPT(--(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())--); + + ASSERT_SAME_TYPE(weekday , decltype( std::declval()--)); + ASSERT_SAME_TYPE(weekday&, decltype(--std::declval() )); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 6; ++i) + { + weekday wd(i); + assert((static_cast(--wd) == euclidian_subtraction(i, 1))); + assert((static_cast(wd--) == euclidian_subtraction(i, 1))); + assert((static_cast(wd) == euclidian_subtraction(i, 2))); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/increment.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/increment.pass.cpp new file mode 100644 index 0000000..171053a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/increment.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr weekday& operator++() noexcept; +// constexpr weekday operator++(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "../../euclidian.h" + +template +constexpr bool testConstexpr() +{ + WD wd{5}; + if (static_cast(++wd) != 6) return false; + if (static_cast(wd++) != 6) return false; + if (static_cast(wd) != 0) return false; + return true; +} + +int main() +{ + using weekday = std::chrono::weekday; + ASSERT_NOEXCEPT(++(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())++); + + ASSERT_SAME_TYPE(weekday , decltype( std::declval()++)); + ASSERT_SAME_TYPE(weekday&, decltype(++std::declval() )); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 6; ++i) + { + weekday wd(i); + assert((static_cast(++wd) == euclidian_addition(i, 1))); + assert((static_cast(wd++) == euclidian_addition(i, 1))); + assert((static_cast(wd) == euclidian_addition(i, 2))); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ok.pass.cpp new file mode 100644 index 0000000..82ae2b3 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/ok.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr bool ok() const noexcept; +// Returns: wd_ <= 6 + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert( weekday{0}.ok(), ""); + static_assert( weekday{1}.ok(), ""); + static_assert(!weekday{7}.ok(), ""); + + for (unsigned i = 0; i <= 6; ++i) + assert(weekday{i}.ok()); + for (unsigned i = 7; i <= 255; ++i) + assert(!weekday{i}.ok()); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/operator[].pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/operator[].pass.cpp new file mode 100644 index 0000000..4b66e7a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/operator[].pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr weekday_indexed operator[](unsigned index) const noexcept; +// constexpr weekday_last operator[](last_spec) const noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "../../euclidian.h" + +int main() +{ + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using weekday_indexed = std::chrono::weekday_indexed; + + constexpr weekday Sunday = std::chrono::Sunday; + + ASSERT_NOEXCEPT( std::declval()[1U]); + ASSERT_SAME_TYPE(weekday_indexed, decltype(std::declval()[1U])); + + ASSERT_NOEXCEPT( std::declval()[std::chrono::last]); + ASSERT_SAME_TYPE(weekday_last, decltype(std::declval()[std::chrono::last])); + + static_assert(Sunday[2].weekday() == Sunday, ""); + static_assert(Sunday[2].index () == 2, ""); + + for (unsigned i = 0; i <= 6; ++i) + { + weekday wd(i); + weekday_last wdl = wd[std::chrono::last]; + assert(wdl.weekday() == wd); + assert(wdl.ok()); + } + + for (unsigned i = 0; i <= 6; ++i) + for (unsigned j = 1; j <= 5; ++j) + { + weekday wd(i); + weekday_indexed wdi = wd[j]; + assert(wdi.weekday() == wd); + assert(wdi.index() == j); + assert(wdi.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/plus_minus_equal.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/plus_minus_equal.pass.cpp new file mode 100644 index 0000000..32d2289 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.members/plus_minus_equal.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr weekday& operator+=(const days& d) noexcept; +// constexpr weekday& operator-=(const days& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" +#include "../../euclidian.h" + +template +constexpr bool testConstexpr() +{ + M m1{1}; + if (static_cast(m1 += Ms{ 1}) != 2) return false; + if (static_cast(m1 += Ms{ 2}) != 4) return false; + if (static_cast(m1 += Ms{ 4}) != 1) return false; + if (static_cast(m1 -= Ms{ 1}) != 0) return false; + if (static_cast(m1 -= Ms{ 2}) != 5) return false; + if (static_cast(m1 -= Ms{ 4}) != 1) return false; + return true; +} + +int main() +{ + using weekday = std::chrono::weekday; + using days = std::chrono::days; + + ASSERT_NOEXCEPT( std::declval() += std::declval()); + ASSERT_SAME_TYPE(weekday&, decltype(std::declval() += std::declval())); + + ASSERT_NOEXCEPT( std::declval() -= std::declval()); + ASSERT_SAME_TYPE(weekday&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 6; ++i) + { + weekday wd(i); + assert((static_cast(wd += days{3}) == euclidian_addition(i, 3))); + assert((static_cast(wd) == euclidian_addition(i, 3))); + } + + for (unsigned i = 0; i <= 6; ++i) + { + weekday wd(i); + assert((static_cast(wd -= days{4}) == euclidian_subtraction(i, 4))); + assert((static_cast(wd) == euclidian_subtraction(i, 4))); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..65df8ae --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/comparisons.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr bool operator==(const weekday& x, const weekday& y) noexcept; +// constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using weekday = std::chrono::weekday; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + static_assert(testComparisons2Values(0U ,0U), ""); + static_assert(testComparisons2Values(0U, 1U), ""); + +// Some 'ok' values as well + static_assert(testComparisons2Values(5U, 5U), ""); + static_assert(testComparisons2Values(5U, 2U), ""); + + for (unsigned i = 0; i < 6; ++i) + for (unsigned j = 0; j < 6; ++j) + assert(testComparisons2Values(i, j)); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/literals.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/literals.pass.cpp new file mode 100644 index 0000000..2bf676c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/literals.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// inline constexpr weekday Sunday{0}; +// inline constexpr weekday Monday{1}; +// inline constexpr weekday Tuesday{2}; +// inline constexpr weekday Wednesday{3}; +// inline constexpr weekday Thursday{4}; +// inline constexpr weekday Friday{5}; +// inline constexpr weekday Saturday{6}; + + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Sunday)); + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Monday)); + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Tuesday)); + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Wednesday)); + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Thursday)); + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Friday)); + ASSERT_SAME_TYPE(const std::chrono::weekday, decltype(std::chrono::Saturday)); + + static_assert( std::chrono::Sunday == std::chrono::weekday(0), ""); + static_assert( std::chrono::Monday == std::chrono::weekday(1), ""); + static_assert( std::chrono::Tuesday == std::chrono::weekday(2), ""); + static_assert( std::chrono::Wednesday == std::chrono::weekday(3), ""); + static_assert( std::chrono::Thursday == std::chrono::weekday(4), ""); + static_assert( std::chrono::Friday == std::chrono::weekday(5), ""); + static_assert( std::chrono::Saturday == std::chrono::weekday(6), ""); + + assert(std::chrono::Sunday == std::chrono::weekday(0)); + assert(std::chrono::Monday == std::chrono::weekday(1)); + assert(std::chrono::Tuesday == std::chrono::weekday(2)); + assert(std::chrono::Wednesday == std::chrono::weekday(3)); + assert(std::chrono::Thursday == std::chrono::weekday(4)); + assert(std::chrono::Friday == std::chrono::weekday(5)); + assert(std::chrono::Saturday == std::chrono::weekday(6)); + + assert(static_cast(std::chrono::Sunday) == 0); + assert(static_cast(std::chrono::Monday) == 1); + assert(static_cast(std::chrono::Tuesday) == 2); + assert(static_cast(std::chrono::Wednesday) == 3); + assert(static_cast(std::chrono::Thursday) == 4); + assert(static_cast(std::chrono::Friday) == 5); + assert(static_cast(std::chrono::Saturday) == 6); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..78734e5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/minus.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr weekday operator-(const weekday& x, const days& y) noexcept; +// Returns: x + -y. +// +// constexpr days operator-(const weekday& x, const weekday& y) noexcept; +// Returns: If x.ok() == true and y.ok() == true, returns a value d in the range +// [days{0}, days{6}] satisfying y + d == x. +// Otherwise the value returned is unspecified. +// [Example: Sunday - Monday == days{6}. —end example] + + +extern "C" int printf(const char *, ...); + +#include +#include +#include + +#include "test_macros.h" +#include "../../euclidian.h" + +template +constexpr bool testConstexpr() +{ + { + WD wd{5}; + Ds offset{3}; + if (wd - offset != WD{2}) return false; + if (wd - WD{2} != offset) return false; + } + +// Check the example + if (WD{0} - WD{1} != Ds{6}) return false; + return true; +} + +int main() +{ + using weekday = std::chrono::weekday; + using days = std::chrono::days; + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(weekday, decltype(std::declval() - std::declval())); + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(days, decltype(std::declval() - std::declval())); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 6; ++i) + for (unsigned j = 0; j <= 6; ++j) + { + weekday wd = weekday{i} - days{j}; + assert(wd + days{j} == weekday{i}); + assert((static_cast(wd) == euclidian_subtraction(i, j))); + } + + for (unsigned i = 0; i <= 6; ++i) + for (unsigned j = 0; j <= 6; ++j) + { + days d = weekday{j} - weekday{i}; + assert(weekday{i} + d == weekday{j}); + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..b7ef53f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/plus.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +// constexpr weekday operator+(const days& x, const weekday& y) noexcept; +// Returns: weekday(int{x} + y.count()). +// +// constexpr weekday operator+(const weekday& x, const days& y) noexcept; +// Returns: +// weekday{modulo(static_cast(unsigned{x}) + y.count(), 7)} +// where modulo(n, 7) computes the remainder of n divided by 7 using Euclidean division. +// [Note: Given a divisor of 12, Euclidean division truncates towards negative infinity +// and always produces a remainder in the range of [0, 6]. +// Assuming no overflow in the signed summation, this operation results in a weekday +// holding a value in the range [0, 6] even if !x.ok(). —end note] +// [Example: Monday + days{6} == Sunday. —end example] + + + +#include +#include +#include + +#include "test_macros.h" +#include "../../euclidian.h" + +template +constexpr bool testConstexpr() +{ + M m{1}; + Ms offset{4}; + if (m + offset != M{5}) return false; + if (offset + m != M{5}) return false; +// Check the example + if (M{1} + Ms{6} != M{0}) return false; + return true; +} + +int main() +{ + using weekday = std::chrono::weekday; + using days = std::chrono::days; + + ASSERT_NOEXCEPT( std::declval() + std::declval()); + ASSERT_SAME_TYPE(weekday, decltype(std::declval() + std::declval())); + + ASSERT_NOEXCEPT( std::declval() + std::declval()); + ASSERT_SAME_TYPE(weekday, decltype(std::declval() + std::declval())); + + static_assert(testConstexpr(), ""); + + for (unsigned i = 0; i <= 6; ++i) + for (unsigned j = 0; j <= 6; ++j) + { + weekday wd1 = weekday{i} + days{j}; + weekday wd2 = days{j} + weekday{i}; + assert(wd1 == wd2); + assert((static_cast(wd1) == euclidian_addition(i, j))); + assert((static_cast(wd2) == euclidian_addition(i, j))); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..39cc3b8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/time.cal.weekday.nonmembers/streaming.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class weekday; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const weekday& wd); +// +// Effects: If wd.ok() == true inserts format(os.getloc(), fmt, wd) where fmt is "%a" widened to charT. +// Otherwise inserts unsigned{wd} << " is not a valid weekday". +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const weekday& wd); +// +// Effects: Streams wd into os using the format specified by the NTCTS fmt. +// fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// weekday& wd, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the weekday wd using +// the format flags given in the NTCTS fmt as specified in 25.12. +// If the parse fails to decode a valid weekday, is.setstate(ios_- base::failbit) +// shall be called and wd shall not be modified. +// If %Z is used and successfully parsed, that value will be assigned +// to *abbrev if abbrev is non-null. +// If %z (or a modified variant) is used and successfully parsed, +// that value will be assigned to *offset if offset is non-null. + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + + std::cout << weekday{3}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/types.pass.cpp new file mode 100644 index 0000000..7fad10d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.weekday/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class weekday; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using weekday = std::chrono::weekday; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ctor.pass.cpp new file mode 100644 index 0000000..6152589 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ctor.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// year() = default; +// explicit constexpr year(int m) noexcept; +// explicit constexpr operator int() const noexcept; + +// Effects: Constructs an object of type year by initializing y_ with y. +// The value held is unspecified if d is not in the range [0, 255]. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + + ASSERT_NOEXCEPT(year{}); + ASSERT_NOEXCEPT(year(0U)); + ASSERT_NOEXCEPT(static_cast(year(0U))); + + constexpr year y0{}; + static_assert(static_cast(y0) == 0, ""); + + constexpr year y1{1}; + static_assert(static_cast(y1) == 1, ""); + + for (int i = 0; i <= 2550; i += 7) + { + year year(i); + assert(static_cast(year) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/decrement.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/decrement.pass.cpp new file mode 100644 index 0000000..61d5617e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/decrement.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr year& operator--() noexcept; +// constexpr year operator--(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + Y y1{10}; + if (static_cast(--y1) != 9) return false; + if (static_cast(y1--) != 9) return false; + if (static_cast(y1) != 8) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + ASSERT_NOEXCEPT(--(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())--); + + ASSERT_SAME_TYPE(year , decltype( std::declval()--)); + ASSERT_SAME_TYPE(year&, decltype(--std::declval() )); + + static_assert(testConstexpr(), ""); + + for (int i = 11000; i <= 11020; ++i) + { + year year(i); + assert(static_cast(--year) == i - 1); + assert(static_cast(year--) == i - 1); + assert(static_cast(year) == i - 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/increment.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/increment.pass.cpp new file mode 100644 index 0000000..ec21990 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/increment.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr year& operator++() noexcept; +// constexpr year operator++(int) noexcept; + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + Y y1{10}; + if (static_cast(++y1) != 11) return false; + if (static_cast(y1++) != 11) return false; + if (static_cast(y1) != 12) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + ASSERT_NOEXCEPT(++(std::declval()) ); + ASSERT_NOEXCEPT( (std::declval())++); + + ASSERT_SAME_TYPE(year , decltype( std::declval()++)); + ASSERT_SAME_TYPE(year&, decltype(++std::declval() )); + + static_assert(testConstexpr(), ""); + + for (int i = 11000; i <= 11020; ++i) + { + year year(i); + assert(static_cast(++year) == i + 1); + assert(static_cast(year++) == i + 1); + assert(static_cast(year) == i + 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/is_leap.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/is_leap.pass.cpp new file mode 100644 index 0000000..2cd493a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/is_leap.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr bool is_is_leap() const noexcept; +// y_ % 4 == 0 && (y_ % 100 != 0 || y_ % 400 == 0) +// + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + + ASSERT_NOEXCEPT( year(1).is_leap()); + ASSERT_SAME_TYPE(bool, decltype(year(1).is_leap())); + + static_assert(!year{1}.is_leap(), ""); + static_assert(!year{2}.is_leap(), ""); + static_assert(!year{3}.is_leap(), ""); + static_assert( year{4}.is_leap(), ""); + + assert( year{-2000}.is_leap()); + assert( year{ -400}.is_leap()); + assert(!year{ -300}.is_leap()); + assert(!year{ -200}.is_leap()); + + assert(!year{ 200}.is_leap()); + assert(!year{ 300}.is_leap()); + assert( year{ 400}.is_leap()); + assert(!year{ 1997}.is_leap()); + assert(!year{ 1998}.is_leap()); + assert(!year{ 1999}.is_leap()); + assert( year{ 2000}.is_leap()); + assert(!year{ 2001}.is_leap()); + assert(!year{ 2002}.is_leap()); + assert(!year{ 2003}.is_leap()); + assert( year{ 2004}.is_leap()); + assert(!year{ 2100}.is_leap()); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ok.pass.cpp new file mode 100644 index 0000000..98a7dec --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/ok.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr bool ok() const noexcept; +// Returns: min() <= y_ && y_ <= max(). +// +// static constexpr year min() noexcept; +// Returns year{ 32767}; +// static constexpr year max() noexcept; +// Returns year{-32767}; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + ASSERT_NOEXCEPT( year::max()); + ASSERT_SAME_TYPE(year, decltype(year::max())); + + ASSERT_NOEXCEPT( year::min()); + ASSERT_SAME_TYPE(year, decltype(year::min())); + + static_assert(static_cast(year::min()) == -32767, ""); + static_assert(static_cast(year::max()) == 32767, ""); + + assert(year{-20001}.ok()); + assert(year{ -2000}.ok()); + assert(year{ -1}.ok()); + assert(year{ 0}.ok()); + assert(year{ 1}.ok()); + assert(year{ 2000}.ok()); + assert(year{ 20001}.ok()); + + static_assert(!year{-32768}.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus.pass.cpp new file mode 100644 index 0000000..9d96b3f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr year operator+() const noexcept; +// constexpr year operator-() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + Y y1{1}; + if (static_cast(+y1) != 1) return false; + if (static_cast(-y1) != -1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using years = std::chrono::years; + + ASSERT_NOEXCEPT(+std::declval()); + ASSERT_NOEXCEPT(-std::declval()); + + ASSERT_SAME_TYPE(year, decltype(+std::declval())); + ASSERT_SAME_TYPE(year, decltype(-std::declval())); + + static_assert(testConstexpr(), ""); + + for (int i = 10000; i <= 10020; ++i) + { + year year(i); + assert(static_cast(+year) == i); + assert(static_cast(-year) == -i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus_equal.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus_equal.pass.cpp new file mode 100644 index 0000000..0ebd2d6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.members/plus_minus_equal.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr year& operator+=(const years& d) noexcept; +// constexpr year& operator-=(const years& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + Y y1{1}; + if (static_cast(y1 += Ys{ 1}) != 2) return false; + if (static_cast(y1 += Ys{ 2}) != 4) return false; + if (static_cast(y1 += Ys{ 8}) != 12) return false; + if (static_cast(y1 -= Ys{ 1}) != 11) return false; + if (static_cast(y1 -= Ys{ 2}) != 9) return false; + if (static_cast(y1 -= Ys{ 8}) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using years = std::chrono::years; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(), ""); + + for (int i = 10000; i <= 10020; ++i) + { + year year(i); + assert(static_cast(year += years{10}) == i + 10); + assert(static_cast(year) == i + 10); + assert(static_cast(year -= years{ 9}) == i + 1); + assert(static_cast(year) == i + 1); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..a158c5e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr bool operator==(const year& x, const year& y) noexcept; +// constexpr bool operator!=(const year& x, const year& y) noexcept; +// constexpr bool operator< (const year& x, const year& y) noexcept; +// constexpr bool operator> (const year& x, const year& y) noexcept; +// constexpr bool operator<=(const year& x, const year& y) noexcept; +// constexpr bool operator>=(const year& x, const year& y) noexcept; + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + + +int main() +{ + using year = std::chrono::year; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + static_assert(testComparisons6Values(0,0), ""); + static_assert(testComparisons6Values(0,1), ""); + +// Some 'ok' values as well + static_assert(testComparisons6Values( 5, 5), ""); + static_assert(testComparisons6Values( 5,10), ""); + + for (int i = 1; i < 10; ++i) + for (int j = 1; j < 10; ++j) + assert(testComparisons6Values(i, j)); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.fail.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.fail.cpp new file mode 100644 index 0000000..a8322bb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-5, clang-6 +// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9 + +// +// class year; + +// constexpr year operator""y(unsigned long long y) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using std::chrono::year; + year d1 = 1234y; // expected-error-re {{no matching literal operator for call to 'operator""y' {{.*}}}} +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.pass.cpp new file mode 100644 index 0000000..6ace293 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/literals.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-5, clang-6 +// UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8, apple-clang-9 + +// +// class year; + +// constexpr year operator""y(unsigned long long y) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + { + using namespace std::chrono; + ASSERT_NOEXCEPT(4y); + + static_assert( 2017y == year(2017), ""); + year y1 = 2018y; + assert (y1 == year(2018)); + } + + { + using namespace std::literals; + ASSERT_NOEXCEPT(4d); + + static_assert( 2017y == std::chrono::year(2017), ""); + + std::chrono::year y1 = 2020y; + assert (y1 == std::chrono::year(2020)); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..788b958 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/minus.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr year operator-(const year& x, const years& y) noexcept; +// Returns: x + -y. +// +// constexpr years operator-(const year& x, const year& y) noexcept; +// Returns: If x.ok() == true and y.ok() == true, returns a value m in the range +// [years{0}, years{11}] satisfying y + m == x. +// Otherwise the value returned is unspecified. +// [Example: January - February == years{11}. —end example] + +extern "C" int printf(const char *, ...); + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + Y y{2313}; + Ys offset{1006}; + if (y - offset != Y{1307}) return false; + if (y - Y{1307} != offset) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using years = std::chrono::years; + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year , decltype(std::declval() - std::declval())); + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(years, decltype(std::declval() - std::declval())); + + static_assert(testConstexpr(), ""); + + year y{1223}; + for (int i = 1100; i <= 1110; ++i) + { + year y1 = y - years{i}; + years ys1 = y - year{i}; + assert(static_cast(y1) == 1223 - i); + assert(ys1.count() == 1223 - i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..9d71c95 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/plus.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +// constexpr year operator+(const year& x, const years& y) noexcept; +// Returns: year(int{x} + y.count()). +// +// constexpr year operator+(const years& x, const year& y) noexcept; +// Returns: y + x + + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr() +{ + Y y{1001}; + Ys offset{23}; + if (y + offset != Y{1024}) return false; + if (offset + y != Y{1024}) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using years = std::chrono::years; + + ASSERT_NOEXCEPT( std::declval() + std::declval()); + ASSERT_SAME_TYPE(year, decltype(std::declval() + std::declval())); + + ASSERT_NOEXCEPT( std::declval() + std::declval()); + ASSERT_SAME_TYPE(year, decltype(std::declval() + std::declval())); + + static_assert(testConstexpr(), ""); + + year y{1223}; + for (int i = 1100; i <= 1110; ++i) + { + year y1 = y + years{i}; + year y2 = years{i} + y; + assert(y1 == y2); + assert(static_cast(y1) == i + 1223); + assert(static_cast(y2) == i + 1223); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..120c2a1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/time.cal.year.nonmembers/streaming.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const year& y); +// +// Effects: Inserts format(fmt, y) where fmt is "%Y" widened to charT. +// If !y.ok(), appends with " is not a valid year". +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const year& y); +// +// Effects: Streams y into os using the format specified by the NTCTS fmt. +// fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// year& y, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the year y using the format flags +// given in the NTCTS fmt as specified in 25.12. If the parse fails to decode a valid year, +// is.setstate(ios_base::failbit) shall be called and y shall not be modified. If %Z is used +// and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null. +// If %z (or a modified variant) is used and successfully parsed, that value will be +// assigned to *offset if offset is non-null. + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + + std::cout << year{2018}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.year/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.year/types.pass.cpp new file mode 100644 index 0000000..24f2d77 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.year/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ctor.pass.cpp new file mode 100644 index 0000000..bfd1f53 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ctor.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// year_month() = default; +// constexpr year_month(const chrono::year& y, const chrono::month& m) noexcept; +// +// Effects: Constructs an object of type year_month by initializing y_ with y, and m_ with m. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using year_month = std::chrono::year_month; + + ASSERT_NOEXCEPT(year_month{}); + ASSERT_NOEXCEPT(year_month{year{1}, month{1}}); + + constexpr year_month ym0{}; + static_assert( ym0.year() == year{}, ""); + static_assert( ym0.month() == month{}, ""); + static_assert(!ym0.ok(), ""); + + constexpr year_month ym1{year{2018}, std::chrono::January}; + static_assert( ym1.year() == year{2018}, ""); + static_assert( ym1.month() == std::chrono::January, ""); + static_assert( ym1.ok(), ""); + + constexpr year_month ym2{year{2018}, month{}}; + static_assert( ym2.year() == year{2018}, ""); + static_assert( ym2.month() == month{}, ""); + static_assert(!ym2.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/month.pass.cpp new file mode 100644 index 0000000..a747f52 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/month.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using year_month = std::chrono::year_month; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( year_month{}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month ym(year{1234}, month{i}); + assert( static_cast(ym.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ok.pass.cpp new file mode 100644 index 0000000..f6a9376 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/ok.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() && y_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using month = std::chrono::month; + using year = std::chrono::year; + using year_month = std::chrono::year_month; + + constexpr month January = std::chrono::January; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!year_month{year{-32768}, January}.ok(), ""); // Bad year + static_assert(!year_month{year{2019}, month{}}.ok(), ""); // Bad month + static_assert( year_month{year{2019}, January}.ok(), ""); // Both OK + + for (unsigned i = 0; i <= 50; ++i) + { + year_month ym{year{2019}, month{i}}; + assert( ym.ok() == month{i}.ok()); + } + + const int ymax = static_cast(year::max()); + for (int i = ymax - 100; i <= ymax + 100; ++i) + { + year_month ym{year{i}, January}; + assert( ym.ok() == year{i}.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_month.pass.cpp new file mode 100644 index 0000000..837eab7 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_month.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr year_month& operator+=(const months& d) noexcept; +// constexpr year_month& operator-=(const months& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).month()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).month()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).month()) != 4) return false; + if (static_cast((d1 += Ds{12}).month()) != 4) return false; + if (static_cast((d1 -= Ds{ 1}).month()) != 3) return false; + if (static_cast((d1 -= Ds{ 2}).month()) != 1) return false; + if (static_cast((d1 -= Ds{12}).month()) != 1) return false; + return true; +} + +int main() +{ + using month = std::chrono::month; + using months = std::chrono::months; + using year = std::chrono::year; + using year_month = std::chrono::year_month; + + ASSERT_NOEXCEPT( std::declval() += std::declval()); + ASSERT_SAME_TYPE(year_month&, decltype(std::declval() += std::declval())); + + ASSERT_NOEXCEPT( std::declval() -= std::declval()); + ASSERT_SAME_TYPE(year_month&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(year_month{year{1234}, month{1}}), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + year y{1234}; + year_month ym(y, month{i}); + assert(static_cast((ym += months{2}).month()) == i + 2); + assert(ym.year() == y); + assert(static_cast((ym ).month()) == i + 2); + assert(ym.year() == y); + assert(static_cast((ym -= months{1}).month()) == i + 1); + assert(ym.year() == y); + assert(static_cast((ym ).month()) == i + 1); + assert(ym.year() == y); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_year.pass.cpp new file mode 100644 index 0000000..f5d8e32 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/plus_minus_equal_year.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr year_month& operator+=(const years& d) noexcept; +// constexpr year_month& operator-=(const years& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).year()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).year()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).year()) != 4) return false; + if (static_cast((d1 += Ds{12}).year()) != 16) return false; + if (static_cast((d1 -= Ds{ 1}).year()) != 15) return false; + if (static_cast((d1 -= Ds{ 2}).year()) != 13) return false; + if (static_cast((d1 -= Ds{12}).year()) != 1) return false; + return true; +} + +int main() +{ + using month = std::chrono::month; + using year = std::chrono::year; + using years = std::chrono::years; + using year_month = std::chrono::year_month; + + + ASSERT_NOEXCEPT( std::declval() += std::declval()); + ASSERT_SAME_TYPE(year_month&, decltype(std::declval() += std::declval())); + + ASSERT_NOEXCEPT( std::declval() -= std::declval()); + ASSERT_SAME_TYPE(year_month&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(year_month{year{1}, month{1}}), ""); + + for (int i = 1000; i <= 1010; ++i) + { + month m{2}; + year_month ym(year{i}, m); + assert(static_cast((ym += years{2}).year()) == i + 2); + assert(ym.month() == m); + assert(static_cast((ym ).year()) == i + 2); + assert(ym.month() == m); + assert(static_cast((ym -= years{1}).year()) == i + 1); + assert(ym.month() == m); + assert(static_cast((ym ).year()) == i + 1); + assert(ym.month() == m); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/year.pass.cpp new file mode 100644 index 0000000..96fda27 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.members/year.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr chrono::day day() const noexcept; +// Returns: d_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using year_month = std::chrono::year_month; + + ASSERT_NOEXCEPT( std::declval().year()); + ASSERT_SAME_TYPE(year, decltype(std::declval().year())); + + static_assert( year_month{}.year() == year{}, ""); + + for (int i = 1; i <= 50; ++i) + { + year_month ym(year{i}, month{}); + assert( static_cast(ym.year()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..9761078 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr bool operator==(const year_month& x, const year_month& y) noexcept; +// Returns: x.year() == y.year() && x.month() == y.month(). +// +// constexpr bool operator< (const year_month& x, const year_month& y) noexcept; +// Returns: +// If x.year() < y.year() returns true. +// Otherwise, if x.year() > y.year() returns false. +// Otherwise, returns x.month() < y.month(). + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using year_month = std::chrono::year_month; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + static_assert( testComparisons6( + year_month{year{1234}, std::chrono::January}, + year_month{year{1234}, std::chrono::January}, + true, false), ""); + + static_assert( testComparisons6( + year_month{year{1234}, std::chrono::January}, + year_month{year{1234}, std::chrono::February}, + false, true), ""); + + static_assert( testComparisons6( + year_month{year{1234}, std::chrono::January}, + year_month{year{1235}, std::chrono::January}, + false, true), ""); + +// same year, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons6( + year_month{year{1234}, month{i}}, + year_month{year{1234}, month{j}}, + i == j, i < j ))); + +// same month, different years + for (int i = 1000; i < 20; ++i) + for (int j = 1000; j < 20; ++j) + assert((testComparisons6( + year_month{year{i}, std::chrono::January}, + year_month{year{j}, std::chrono::January}, + i == j, i < j ))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..e443c50 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/minus.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; +// Returns: ym + -dy. +// +// constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; +// Returns: ym + -dm. +// +// constexpr months operator-(const year_month& x, const year_month& y) noexcept; +// Returns: x.year() - y.year() + months{static_cast(unsigned{x.month()}) - +// static_cast(unsigned{y.month()})} + + +#include +#include +#include + +#include "test_macros.h" + +#include + +int main() +{ + using year = std::chrono::year; + using years = std::chrono::years; + using month = std::chrono::month; + using months = std::chrono::months; + using year_month = std::chrono::year_month; + + { // year_month - years + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month, decltype(std::declval() - std::declval())); + +// static_assert(testConstexprYears (year_month{year{1}, month{1}}), ""); + + year_month ym{year{1234}, std::chrono::January}; + for (int i = 0; i <= 10; ++i) + { + year_month ym1 = ym - years{i}; + assert(static_cast(ym1.year()) == 1234 - i); + assert(ym1.month() == std::chrono::January); + } + } + + { // year_month - months + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month, decltype(std::declval() - std::declval())); + +// static_assert(testConstexprMonths(year_month{year{1}, month{1}}), ""); + + year_month ym{year{1234}, std::chrono::November}; + for (int i = 0; i <= 10; ++i) // TODO test wrap-around + { + year_month ym1 = ym - months{i}; + assert(static_cast(ym1.year()) == 1234); + assert(ym1.month() == month(11 - i)); + } + } + + { // year_month - year_month + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(months, decltype(std::declval() - std::declval())); + +// static_assert(testConstexprMonths(year_month{year{1}, month{1}}), ""); + +// Same year + year y{2345}; + for (int i = 1; i <= 12; ++i) + for (int j = 1; j <= 12; ++j) + { + months diff = year_month{y, month(i)} - year_month{y, month(j)}; + std::cout << "i: " << i << " j: " << j << " -> " << diff.count() << std::endl; + assert(diff.count() == i - j); + } + +// TODO: different year + + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..acf93ef --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/plus.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +// constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; +// Returns: (ym.year() + dy) / ym.month(). +// +// constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; +// Returns: ym + dy. +// +// constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; +// Returns: A year_month value z such that z - ym == dm. +// Complexity: O(1) with respect to the value of dm. +// +// constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; +// Returns: ym + dm. + + + +#include +#include +#include + +#include "test_macros.h" + +constexpr bool testConstexprYears(std::chrono::year_month ym) +{ + std::chrono::years offset{23}; + if (static_cast((ym ).year()) != 1) return false; + if (static_cast((ym + offset).year()) != 24) return false; + if (static_cast((offset + ym).year()) != 24) return false; + return true; +} + + +constexpr bool testConstexprMonths(std::chrono::year_month ym) +{ + std::chrono::months offset{6}; + if (static_cast((ym ).month()) != 1) return false; + if (static_cast((ym + offset).month()) != 7) return false; + if (static_cast((offset + ym).month()) != 7) return false; + return true; +} + + +int main() +{ + using year = std::chrono::year; + using years = std::chrono::years; + using month = std::chrono::month; + using months = std::chrono::months; + using year_month = std::chrono::year_month; + + { // year_month + years + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month, decltype(std::declval() + std::declval())); + + static_assert(testConstexprYears (year_month{year{1}, month{1}}), ""); + + year_month ym{year{1234}, std::chrono::January}; + for (int i = 0; i <= 10; ++i) + { + year_month ym1 = ym + years{i}; + year_month ym2 = years{i} + ym; + assert(static_cast(ym1.year()) == i + 1234); + assert(static_cast(ym2.year()) == i + 1234); + assert(ym1.month() == std::chrono::January); + assert(ym2.month() == std::chrono::January); + assert(ym1 == ym2); + } + } + + { // year_month + months + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month, decltype(std::declval() + std::declval())); + + static_assert(testConstexprMonths(year_month{year{1}, month{1}}), ""); + + year_month ym{year{1234}, std::chrono::January}; + for (int i = 0; i <= 10; ++i) // TODO test wrap-around + { + year_month ym1 = ym + months{i}; + year_month ym2 = months{i} + ym; + assert(static_cast(ym1.year()) == 1234); + assert(static_cast(ym2.year()) == 1234); + assert(ym1.month() == month(1 + i)); + assert(ym2.month() == month(1 + i)); + assert(ym1 == ym2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..2a94d4f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/streaming.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const year_month& ym); +// +// Returns: os << ym.year() << '/' << ym.month(). +// +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const year_month& ym); +// +// Effects: Streams ym into os using the format specified by the NTCTS fmt. fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// year_month& ym, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the year_month ym using the format +// flags given in the NTCTS fmt as specified in 25.12. If the parse fails to decode +// a valid year_month, is.setstate(ios_- base::failbit) shall be called and ym shall +// not be modified. If %Z is used and successfully parsed, that value will be assigned +// to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and +// successfully parsed, that value will be assigned to *offset if offset is non-null. + + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month = std::chrono::year_month; + using year = std::chrono::year; + using month = std::chrono::month; + + std::cout << year_month{year{2018}, month{3}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ym/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/types.pass.cpp new file mode 100644 index 0000000..c888dd5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ym/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month = std::chrono::year_month; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.local_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.local_days.pass.cpp new file mode 100644 index 0000000..c95ba36 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.local_days.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day; + +// explicit constexpr year_month_day(const local_days& dp) noexcept; +// +// +// Effects: Constructs an object of type year_month_day that corresponds +// to the date represented by dp +// +// Remarks: Equivalent to constructing with sys_days{dp.time_since_epoch()}. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::day day() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; +// using local_days = std::chrono::local_days; + using year_month_day = std::chrono::year_month_day; + +// ASSERT_NOEXCEPT(year_month_day{std::declval()}); + assert(false); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.pass.cpp new file mode 100644 index 0000000..dd2b1e1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// year_month_day() = default; +// constexpr year_month_day(const chrono::year& y, const chrono::month& m, +// const chrono::day& d) noexcept; +// +// Effects: Constructs an object of type year_month_day by initializing +// y_ with y, m_ with m, and d_ with d. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::day day() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + + ASSERT_NOEXCEPT(year_month_day{}); + ASSERT_NOEXCEPT(year_month_day{year{1}, month{1}, day{1}}); + + constexpr month January = std::chrono::January; + + constexpr year_month_day ym0{}; + static_assert( ym0.year() == year{}, ""); + static_assert( ym0.month() == month{}, ""); + static_assert( ym0.day() == day{}, ""); + static_assert(!ym0.ok(), ""); + + constexpr year_month_day ym1{year{2019}, January, day{12}}; + static_assert( ym1.year() == year{2019}, ""); + static_assert( ym1.month() == January, ""); + static_assert( ym1.day() == day{12}, ""); + static_assert( ym1.ok(), ""); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.sys_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.sys_days.pass.cpp new file mode 100644 index 0000000..38c9d68 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.sys_days.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day; + +// constexpr year_month_day(const sys_days& dp) noexcept; +// +// Effects: Constructs an object of type year_month_day that corresponds +// to the date represented by dp +// +// Remarks: For any value ymd of type year_month_day for which ymd.ok() is true, +// ymd == year_month_day{sys_days{ymd}} is true. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; +// using sys_days = std::chrono::sys_days; + using year_month_day = std::chrono::year_month_day; + +// ASSERT_NOEXCEPT(year_month_day{std::declval()}); + assert(false); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.year_month_day_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.year_month_day_last.pass.cpp new file mode 100644 index 0000000..e1211c0 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ctor.year_month_day_last.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day; + +// constexpr year_month_day(const year_month_day_last& ymdl) noexcept; +// +// Effects: Constructs an object of type year_month_day by initializing +// y_ with ymdl.year(), m_ with ymdl.month(), and d_ with ymdl.day(). +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::day day() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; +// using year_month_day_last = std::chrono::year_month_day_last; + using year_month_day = std::chrono::year_month_day; + +// ASSERT_NOEXCEPT(year_month_day{std::declval()}); + assert(false); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/day.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/day.pass.cpp new file mode 100644 index 0000000..603a016 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/day.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr chrono::day day() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + + ASSERT_NOEXCEPT( std::declval().day()); + ASSERT_SAME_TYPE(day, decltype(std::declval().day())); + + static_assert( year_month_day{}.day() == day{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_day ymd(year{1234}, month{2}, day{i}); + assert( static_cast(ymd.day()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/month.pass.cpp new file mode 100644 index 0000000..40dd733 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/month.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( year_month_day{}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_day ymd(year{1234}, month{i}, day{12}); + assert( static_cast(ymd.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ok.pass.cpp new file mode 100644 index 0000000..c5c6e3e --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/ok.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() && y_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + + constexpr month January = std::chrono::January; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!year_month_day{year{-32768}, month{}, day{}}.ok(), ""); // All three bad + + static_assert(!year_month_day{year{-32768}, January, day{1}}.ok(), ""); // Bad year + static_assert(!year_month_day{year{2019}, month{}, day{1}}.ok(), ""); // Bad month + static_assert(!year_month_day{year{2019}, January, day{} }.ok(), ""); // Bad day + + static_assert(!year_month_day{year{-32768}, month{}, day{1}}.ok(), ""); // Bad year & month + static_assert(!year_month_day{year{2019}, month{}, day{} }.ok(), ""); // Bad month & day + static_assert(!year_month_day{year{-32768}, January, day{} }.ok(), ""); // Bad year & day + + static_assert( year_month_day{year{2019}, January, day{1}}.ok(), ""); // All OK + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_day ym{year{2019}, January, day{i}}; + assert( ym.ok() == day{i}.ok()); + } + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_day ym{year{2019}, month{i}, day{12}}; + assert( ym.ok() == month{i}.ok()); + } + + const int ymax = static_cast(year::max()); + for (int i = ymax - 100; i <= ymax + 100; ++i) + { + year_month_day ym{year{i}, January, day{12}}; + assert( ym.ok() == year{i}.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_month.pass.cpp new file mode 100644 index 0000000..2249d91 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_month.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr year_month_day& operator+=(const months& m) noexcept; +// constexpr year_month_day& operator-=(const months& m) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).month()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).month()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).month()) != 4) return false; + if (static_cast((d1 += Ds{12}).month()) != 4) return false; + if (static_cast((d1 -= Ds{ 1}).month()) != 3) return false; + if (static_cast((d1 -= Ds{ 2}).month()) != 1) return false; + if (static_cast((d1 -= Ds{12}).month()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + using months = std::chrono::months; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year_month_day&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year_month_day&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(year_month_day{year{1234}, month{1}, day{1}}), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + year y{1234}; + day d{23}; + year_month_day ym(y, month{i}, d); + assert(static_cast((ym += months{2}).month()) == i + 2); + assert(ym.year() == y); + assert(ym.day() == d); + assert(static_cast((ym ).month()) == i + 2); + assert(ym.year() == y); + assert(ym.day() == d); + assert(static_cast((ym -= months{1}).month()) == i + 1); + assert(ym.year() == y); + assert(ym.day() == d); + assert(static_cast((ym ).month()) == i + 1); + assert(ym.year() == y); + assert(ym.day() == d); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_year.pass.cpp new file mode 100644 index 0000000..f9973c1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/plus_minus_equal_year.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr year_month_day& operator+=(const years& d) noexcept; +// constexpr year_month_day& operator-=(const years& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).year()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).year()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).year()) != 4) return false; + if (static_cast((d1 += Ds{12}).year()) != 16) return false; + if (static_cast((d1 -= Ds{ 1}).year()) != 15) return false; + if (static_cast((d1 -= Ds{ 2}).year()) != 13) return false; + if (static_cast((d1 -= Ds{12}).year()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + using years = std::chrono::years; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year_month_day&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year_month_day&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(year_month_day{year{1}, month{1}, day{1}}), ""); + + for (int i = 1000; i <= 1010; ++i) + { + month m{2}; + day d{23}; + year_month_day ym(year{i}, m, d); + assert(static_cast((ym += years{2}).year()) == i + 2); + assert(ym.month() == m); + assert(ym.day() == d); + assert(static_cast((ym ).year()) == i + 2); + assert(ym.month() == m); + assert(ym.day() == d); + assert(static_cast((ym -= years{1}).year()) == i + 1); + assert(ym.month() == m); + assert(ym.day() == d); + assert(static_cast((ym ).year()) == i + 1); + assert(ym.month() == m); + assert(ym.day() == d); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/year.pass.cpp new file mode 100644 index 0000000..54dbd83 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.members/year.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr chrono::day day() const noexcept; +// Returns: d_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + + ASSERT_NOEXCEPT( std::declval().year()); + ASSERT_SAME_TYPE(year, decltype(std::declval().year())); + + static_assert( year_month_day{}.year() == year{}, ""); + + for (int i = 1; i <= 50; ++i) + { + year_month_day ym(year{i}, month{}, day{}); + assert( static_cast(ym.year()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..e686d9a --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; +// Returns: x.year() == y.year() && x.month() == y.month(). +// +// constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; +// Returns: +// If x.year() < y.year() returns true. +// Otherwise, if x.year() > y.year() returns false. +// Otherwise, if x.month() < y.month() returns true. +// Otherwise, if x.month() > y.month() returns false. +// Otherwise, returns x.day() < y.day() + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using day = std::chrono::day; + using year = std::chrono::year; + using month = std::chrono::month; + using year_month_day = std::chrono::year_month_day; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + constexpr month January = std::chrono::January; + constexpr month February = std::chrono::February; + + static_assert( testComparisons6( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1234}, January, day{1}}, + true, false), ""); + +// different day + static_assert( testComparisons6( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1234}, January, day{2}}, + false, true), ""); + +// different month + static_assert( testComparisons6( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1234}, February, day{1}}, + false, true), ""); + +// different year + static_assert( testComparisons6( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1235}, January, day{1}}, + false, true), ""); + + +// different month and day + static_assert( testComparisons6( + year_month_day{year{1234}, January, day{2}}, + year_month_day{year{1234}, February, day{1}}, + false, true), ""); + +// different year and month + static_assert( testComparisons6( + year_month_day{year{1234}, February, day{1}}, + year_month_day{year{1235}, January, day{1}}, + false, true), ""); + +// different year and day + static_assert( testComparisons6( + year_month_day{year{1234}, January, day{2}}, + year_month_day{year{1235}, January, day{1}}, + false, true), ""); + +// different year, month and day + static_assert( testComparisons6( + year_month_day{year{1234}, February, day{2}}, + year_month_day{year{1235}, January, day{1}}, + false, true), ""); + + +// same year, different days + for (unsigned i = 1; i < 28; ++i) + for (unsigned j = 1; j < 28; ++j) + assert((testComparisons6( + year_month_day{year{1234}, January, day{i}}, + year_month_day{year{1234}, January, day{j}}, + i == j, i < j ))); + +// same year, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons6( + year_month_day{year{1234}, month{i}, day{12}}, + year_month_day{year{1234}, month{j}, day{12}}, + i == j, i < j ))); + +// same month, different years + for (int i = 1000; i < 20; ++i) + for (int j = 1000; j < 20; ++j) + assert((testComparisons6( + year_month_day{year{i}, January, day{12}}, + year_month_day{year{j}, January, day{12}}, + i == j, i < j ))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..3f60120 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/minus.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; +// Returns: ymd + (-dy) + + +#include +#include +#include + +#include "test_macros.h" + +#include + +constexpr bool test_constexpr () +{ + std::chrono::year_month_day ym0{std::chrono::year{1234}, std::chrono::January, std::chrono::day{12}}; + std::chrono::year_month_day ym1 = ym0 - std::chrono::years{10}; + return + ym1.year() == std::chrono::year{1234-10} + && ym1.month() == std::chrono::January + && ym1.day() == std::chrono::day{12} + ; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_day = std::chrono::year_month_day; + using years = std::chrono::years; + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_day, decltype(std::declval() - std::declval())); + + constexpr month January = std::chrono::January; + + static_assert(test_constexpr(), ""); + + year_month_day ym{year{1234}, January, day{10}}; + for (int i = 0; i <= 10; ++i) + { + year_month_day ym1 = ym - years{i}; + assert(static_cast(ym1.year()) == 1234 - i); + assert(ym1.month() == January); + assert(ym1.day() == day{10}); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..bc7649d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/plus.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +// constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; +// Returns: (ymd.year() / ymd.month() + dm) / ymd.day(). +// +// constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; +// Returns: ymd + dm. +// +// +// constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; +// Returns: (ymd.year() + dy) / ymd.month() / ymd.day(). +// +// constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; +// Returns: ym + dm. + + + +#include +#include +#include + +#include "test_macros.h" + +constexpr bool testConstexprYears(std::chrono::year_month_day ym) +{ + std::chrono::years offset{23}; + if (static_cast((ym ).year()) != 1) return false; + if (static_cast((ym + offset).year()) != 24) return false; + if (static_cast((offset + ym).year()) != 24) return false; + return true; +} + + +constexpr bool testConstexprMonths(std::chrono::year_month_day ym) +{ + std::chrono::months offset{6}; + if (static_cast((ym ).month()) != 1) return false; + if (static_cast((ym + offset).month()) != 7) return false; + if (static_cast((offset + ym).month()) != 7) return false; + return true; +} + + +int main() +{ + using day = std::chrono::day; + using year = std::chrono::year; + using years = std::chrono::years; + using month = std::chrono::month; + using months = std::chrono::months; + using year_month_day = std::chrono::year_month_day; + + { // year_month_day + months + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_day, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_day, decltype(std::declval() + std::declval())); + + static_assert(testConstexprMonths(year_month_day{year{1}, month{1}, day{1}}), ""); + + year_month_day ym{year{1234}, std::chrono::January, day{12}}; + for (int i = 0; i <= 10; ++i) // TODO test wrap-around + { + year_month_day ym1 = ym + months{i}; + year_month_day ym2 = months{i} + ym; + assert(static_cast(ym1.year()) == 1234); + assert(static_cast(ym2.year()) == 1234); + assert(ym1.month() == month(1 + i)); + assert(ym2.month() == month(1 + i)); + assert(ym1.day() == day{12}); + assert(ym2.day() == day{12}); + assert(ym1 == ym2); + } + } + + { // year_month_day + years + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_day, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_day, decltype(std::declval() + std::declval())); + + static_assert(testConstexprYears (year_month_day{year{1}, month{1}, day{1}}), ""); + + year_month_day ym{year{1234}, std::chrono::January, day{12}}; + for (int i = 0; i <= 10; ++i) + { + year_month_day ym1 = ym + years{i}; + year_month_day ym2 = years{i} + ym; + assert(static_cast(ym1.year()) == i + 1234); + assert(static_cast(ym2.year()) == i + 1234); + assert(ym1.month() == std::chrono::January); + assert(ym2.month() == std::chrono::January); + assert(ym1.day() == day{12}); + assert(ym2.day() == day{12}); + assert(ym1 == ym2); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..063073c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/streaming.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const year_month_day& ym); +// +// Returns: os << ym.year() << '/' << ym.month(). +// +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const year_month_day& ym); +// +// Effects: Streams ym into os using the format specified by the NTCTS fmt. fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// year_month_day& ym, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the year_month_day ym using the format +// flags given in the NTCTS fmt as specified in 25.12. If the parse fails to decode +// a valid year_month_day, is.setstate(ios_- base::failbit) shall be called and ym shall +// not be modified. If %Z is used and successfully parsed, that value will be assigned +// to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and +// successfully parsed, that value will be assigned to *offset if offset is non-null. + + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month_day = std::chrono::year_month_day; + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + + std::cout << year_month_day{year{2018}, month{3}, day{12}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/types.pass.cpp new file mode 100644 index 0000000..5ad4df5 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymd/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month_day = std::chrono::year_month_day; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ctor.pass.cpp new file mode 100644 index 0000000..d61bdbe --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ctor.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr year_month_day_last(const chrono::year& y, +// const chrono::month_day_last& mdl) noexcept; +// +// Effects: Constructs an object of type year_month_day_last by initializing +// initializing y_ with y and mdl_ with mdl. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::month_day_last month_day_last() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + ASSERT_NOEXCEPT(year_month_day_last{year{1}, month_day_last{month{1}}}); + + constexpr month January = std::chrono::January; + + constexpr year_month_day_last ymdl0{year{}, month_day_last{month{}}}; + static_assert( ymdl0.year() == year{}, ""); + static_assert( ymdl0.month() == month{}, ""); + static_assert( ymdl0.month_day_last() == month_day_last{month{}}, ""); + static_assert(!ymdl0.ok(), ""); + + constexpr year_month_day_last ymdl1{year{2019}, month_day_last{January}}; + static_assert( ymdl1.year() == year{2019}, ""); + static_assert( ymdl1.month() == January, ""); + static_assert( ymdl1.month_day_last() == month_day_last{January}, ""); + static_assert( ymdl1.ok(), ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/day.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/day.pass.cpp new file mode 100644 index 0000000..202b5af --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/day.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day_last; + +// constexpr chrono::day day() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + +// TODO: wait for calendar +// ASSERT_NOEXCEPT( std::declval().day()); +// ASSERT_SAME_TYPE(day, decltype(std::declval().day())); +// +// static_assert( year_month_day_last{}.day() == day{}, ""); + + for (unsigned i = 1; i <= 12; ++i) + { + year_month_day_last ymd(year{1234}, month_day_last{month{i}}); + assert( static_cast(ymd.day()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month.pass.cpp new file mode 100644 index 0000000..36fa9f4 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_day_last ymd(year{1234}, month_day_last{month{i}}); + assert( static_cast(ymd.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month_day_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month_day_last.pass.cpp new file mode 100644 index 0000000..6121713 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/month_day_last.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr chrono::day day() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + ASSERT_NOEXCEPT( std::declval().month_day_last()); + ASSERT_SAME_TYPE(month_day_last, decltype(std::declval().month_day_last())); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_day_last ymdl(year{1234}, month_day_last{month{i}}); + assert( static_cast(ymdl.month_day_last().month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ok.pass.cpp new file mode 100644 index 0000000..8f37cd1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/ok.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() && y_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + constexpr month January = std::chrono::January; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!year_month_day_last{year{-32768}, month_day_last{month{}}}.ok(), ""); // both bad + static_assert(!year_month_day_last{year{-32768}, month_day_last{January}}.ok(), ""); // Bad year + static_assert(!year_month_day_last{year{2019}, month_day_last{month{}}}.ok(), ""); // Bad month + static_assert( year_month_day_last{year{2019}, month_day_last{January}}.ok(), ""); // All OK + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_day_last ym{year{2019}, month_day_last{month{i}}}; + assert( ym.ok() == month{i}.ok()); + } + + const int ymax = static_cast(year::max()); + for (int i = ymax - 100; i <= ymax + 100; ++i) + { + year_month_day_last ym{year{i}, month_day_last{January}}; + assert( ym.ok() == year{i}.ok()); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_local_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_local_days.pass.cpp new file mode 100644 index 0000000..845018dd --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_local_days.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day_last; + +// constexpr operator local_days() const noexcept; +// Returns: local_days{sys_days{*this}.time_since_epoch()}. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; +// using sys_days = std::chrono::local_days; + +// ASSERT_NOEXCEPT( static_cast(std::declval().year())); +// ASSERT_SAME_TYPE(year, decltype(static_cast(std::declval().year())); + assert(false); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_sys_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_sys_days.pass.cpp new file mode 100644 index 0000000..acb948f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/op_sys_days.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day_last; + +// constexpr operator sys_days() const noexcept; +// Returns: sys_days{year()/month()/day()}. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; +// using sys_days = std::chrono::sys_days; + +// ASSERT_NOEXCEPT( static_cast(std::declval().year())); +// ASSERT_SAME_TYPE(year, decltype(static_cast(std::declval().year())); + assert(false); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_month.pass.cpp new file mode 100644 index 0000000..0f89b24 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_month.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr year_month_day_last& operator+=(const months& m) noexcept; +// constexpr year_month_day_last& operator-=(const months& m) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).month()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).month()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).month()) != 4) return false; + if (static_cast((d1 += Ds{12}).month()) != 4) return false; + if (static_cast((d1 -= Ds{ 1}).month()) != 3) return false; + if (static_cast((d1 -= Ds{ 2}).month()) != 1) return false; + if (static_cast((d1 -= Ds{12}).month()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + using months = std::chrono::months; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(year_month_day_last{year{1234}, month_day_last{month{1}}}), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + year y{1234}; + month_day_last mdl{month{i}}; + year_month_day_last ym(y, mdl); + assert(static_cast((ym += months{2}).month()) == i + 2); + assert(ym.year() == y); + assert(static_cast((ym ).month()) == i + 2); + assert(ym.year() == y); + assert(static_cast((ym -= months{1}).month()) == i + 1); + assert(ym.year() == y); + assert(static_cast((ym ).month()) == i + 1); + assert(ym.year() == y); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_year.pass.cpp new file mode 100644 index 0000000..e38eb95 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/plus_minus_equal_year.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr year_month_day_last& operator+=(const years& d) noexcept; +// constexpr year_month_day_last& operator-=(const years& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).year()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).year()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).year()) != 4) return false; + if (static_cast((d1 += Ds{12}).year()) != 16) return false; + if (static_cast((d1 -= Ds{ 1}).year()) != 15) return false; + if (static_cast((d1 -= Ds{ 2}).year()) != 13) return false; + if (static_cast((d1 -= Ds{12}).year()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + using years = std::chrono::years; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval() -= std::declval())); + + static_assert(testConstexpr(year_month_day_last{year{1}, month_day_last{month{1}}}), ""); + + for (int i = 1000; i <= 1010; ++i) + { + month_day_last mdl{month{2}}; + year_month_day_last ymdl(year{i}, mdl); + assert(static_cast((ymdl += years{2}).year()) == i + 2); + assert(ymdl.month_day_last() == mdl); + assert(static_cast((ymdl ).year()) == i + 2); + assert(ymdl.month_day_last() == mdl); + assert(static_cast((ymdl -= years{1}).year()) == i + 1); + assert(ymdl.month_day_last() == mdl); + assert(static_cast((ymdl ).year()) == i + 1); + assert(ymdl.month_day_last() == mdl); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/year.pass.cpp new file mode 100644 index 0000000..0e79d78 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.members/year.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr chrono::day day() const noexcept; +// Returns: d_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + ASSERT_NOEXCEPT( std::declval().year()); + ASSERT_SAME_TYPE(year, decltype(std::declval().year())); + + for (int i = 1; i <= 50; ++i) + { + year_month_day_last ym(year{i}, month_day_last{month{}}); + assert( static_cast(ym.year()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..303f286 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept; +// Returns: x.year() == y.year() && x.month_day_last() == y.month_day_last(). +// +// constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept; +// Returns: +// If x.year() < y.year(), returns true. +// Otherwise, if x.year() > y.year(), returns false. +// Otherwise, returns x.month_day_last() < y.month_day_last() + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + + AssertComparisons6AreNoexcept(); + AssertComparisons6ReturnBool(); + + constexpr month January = std::chrono::January; + constexpr month February = std::chrono::February; + + static_assert( testComparisons6( + year_month_day_last{year{1234}, month_day_last{January}}, + year_month_day_last{year{1234}, month_day_last{January}}, + true, false), ""); + +// different month + static_assert( testComparisons6( + year_month_day_last{year{1234}, month_day_last{January}}, + year_month_day_last{year{1234}, month_day_last{February}}, + false, true), ""); + +// different year + static_assert( testComparisons6( + year_month_day_last{year{1234}, month_day_last{January}}, + year_month_day_last{year{1235}, month_day_last{January}}, + false, true), ""); + +// different month + static_assert( testComparisons6( + year_month_day_last{year{1234}, month_day_last{January}}, + year_month_day_last{year{1234}, month_day_last{February}}, + false, true), ""); + +// different year and month + static_assert( testComparisons6( + year_month_day_last{year{1234}, month_day_last{February}}, + year_month_day_last{year{1235}, month_day_last{January}}, + false, true), ""); + +// same year, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons6( + year_month_day_last{year{1234}, month_day_last{month{i}}}, + year_month_day_last{year{1234}, month_day_last{month{j}}}, + i == j, i < j ))); + +// same month, different years + for (int i = 1000; i < 20; ++i) + for (int j = 1000; j < 20; ++j) + assert((testComparisons6( + year_month_day_last{year{i}, month_day_last{January}}, + year_month_day_last{year{j}, month_day_last{January}}, + i == j, i < j ))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..950b100 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/minus.pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr year_month_day_last +// operator-(const year_month_day_last& ymdl, const months& dm) noexcept; +// +// Returns: ymdl + (-dm). +// +// constexpr year_month_day_last +// operator-(const year_month_day_last& ymdl, const years& dy) noexcept; +// +// Returns: ymdl + (-dy). + + +#include +#include +#include + +#include "test_macros.h" + +#include + +constexpr bool testConstexprYears (std::chrono::year_month_day_last ymdl) +{ + std::chrono::year_month_day_last ym1 = ymdl - std::chrono::years{10}; + return + ym1.year() == std::chrono::year{static_cast(ymdl.year()) - 10} + && ym1.month() == ymdl.month() + ; +} + +constexpr bool testConstexprMonths (std::chrono::year_month_day_last ymdl) +{ + std::chrono::year_month_day_last ym1 = ymdl - std::chrono::months{6}; + return + ym1.year() == ymdl.year() + && ym1.month() == std::chrono::month{static_cast(ymdl.month()) - 6} + ; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + using months = std::chrono::months; + using years = std::chrono::years; + + constexpr month December = std::chrono::December; + + { // year_month_day_last - years + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval() - std::declval())); + + static_assert(testConstexprYears(year_month_day_last{year{1234}, month_day_last{December}}), ""); + year_month_day_last ym{year{1234}, month_day_last{December}}; + for (int i = 0; i <= 10; ++i) + { + year_month_day_last ym1 = ym - years{i}; + assert(static_cast(ym1.year()) == 1234 - i); + assert(ym1.month() == December); + } + } + + { // year_month_day_last - months + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval() - std::declval())); + + static_assert(testConstexprMonths(year_month_day_last{year{1234}, month_day_last{December}}), ""); +// TODO test wrapping + year_month_day_last ym{year{1234}, month_day_last{December}}; + for (unsigned i = 0; i <= 10; ++i) + { + year_month_day_last ym1 = ym - months{i}; + assert(static_cast(ym1.year()) == 1234); + assert(static_cast(ym1.month()) == 12U-i); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..5cf3151 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/plus.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_day_last; + +// constexpr year_month_day_last +// operator+(const year_month_day_last& ymdl, const months& dm) noexcept; +// +// Returns: (ymdl.year() / ymdl.month() + dm) / last. +// +// constexpr year_month_day_last +// operator+(const months& dm, const year_month_day_last& ymdl) noexcept; +// +// Returns: ymdl + dm. +// +// +// constexpr year_month_day_last +// operator+(const year_month_day_last& ymdl, const years& dy) noexcept; +// +// Returns: {ymdl.year()+dy, ymdl.month_day_last()}. +// +// constexpr year_month_day_last +// operator+(const years& dy, const year_month_day_last& ymdl) noexcept; +// +// Returns: ymdl + dy + + + +#include +#include +#include + +#include "test_macros.h" + +constexpr bool testConstexprYears(std::chrono::year_month_day_last ymdl) +{ + std::chrono::years offset{23}; + if (static_cast((ymdl ).year()) != 1) return false; + if (static_cast((ymdl + offset).year()) != 24) return false; + if ( (ymdl + offset).month() != ymdl.month()) return false; + if (static_cast((offset + ymdl).year()) != 24) return false; + if ( (offset + ymdl).month() != ymdl.month()) return false; + return true; +} + + +constexpr bool testConstexprMonths(std::chrono::year_month_day_last ymdl) +{ + std::chrono::months offset{6}; + if (static_cast((ymdl ).month()) != 1) return false; + if ( (ymdl + offset).year() != ymdl.year()) return false; + if (static_cast((ymdl + offset).month()) != 7) return false; + if (static_cast((offset + ymdl).month()) != 7) return false; + if ( (offset + ymdl).year() != ymdl.year()) return false; + return true; +} + + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + using months = std::chrono::months; + using years = std::chrono::years; + + constexpr month January = std::chrono::January; + + { // year_month_day_last + months + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval() + std::declval())); + + static_assert(testConstexprMonths(year_month_day_last{year{1}, month_day_last{January}}), ""); + + year_month_day_last ym{year{1234}, month_day_last{January}}; + for (int i = 0; i <= 10; ++i) // TODO test wrap-around + { + year_month_day_last ym1 = ym + months{i}; + year_month_day_last ym2 = months{i} + ym; + assert(static_cast(ym1.year()) == 1234); + assert(static_cast(ym2.year()) == 1234); + assert(ym1.month() == month(1 + i)); + assert(ym2.month() == month(1 + i)); + assert(ym1 == ym2); + } + } + + { // year_month_day_last + years + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_day_last, decltype(std::declval() + std::declval())); + + static_assert(testConstexprYears(year_month_day_last{year{1}, month_day_last{January}}), ""); + + year_month_day_last ym{year{1234}, month_day_last{January}}; + for (int i = 0; i <= 10; ++i) + { + year_month_day_last ym1 = ym + years{i}; + year_month_day_last ym2 = years{i} + ym; + assert(static_cast(ym1.year()) == i + 1234); + assert(static_cast(ym2.year()) == i + 1234); + assert(ym1.month() == std::chrono::January); + assert(ym2.month() == std::chrono::January); + assert(ym1 == ym2); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..3d218d1 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/streaming.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day_last; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const year_month_day_last& ymdl); +// +// Returns: os << ymdl.year() << '/' << ymdl.month_day_last(). + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month_day_last = std::chrono::year_month_day_last; + using year = std::chrono::year; + using month = std::chrono::month; + using month_day_last = std::chrono::month_day_last; + + std::cout << year_month_day_last{year{2018}, month_day_last{month{3}}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.local_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.local_days.pass.cpp new file mode 100644 index 0000000..a13e7c7 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.local_days.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_weekday; + +// explicit constexpr year_month_weekday(const local_days& dp) noexcept; +// +// +// Effects: Constructs an object of type year_month_weekday that corresponds +// to the date represented by dp +// +// Remarks: Equivalent to constructing with sys_days{dp.time_since_epoch()}. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::day day() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; +// using local_days = std::chrono::local_days; + using year_month_weekday = std::chrono::year_month_weekday; + +// ASSERT_NOEXCEPT(year_month_weekday{std::declval()}); + assert(false); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.pass.cpp new file mode 100644 index 0000000..a7ee7b2 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// year_month_weekday() = default; +// constexpr year_month_weekday(const chrono::year& y, const chrono::month& m, +// const chrono::weekday_indexed& wdi) noexcept; +// +// Effects: Constructs an object of type year_month_weekday by initializing +// y_ with y, m_ with m, and wdi_ with wdi. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::weekday weekday() const noexcept; +// constexpr unsigned index() const noexcept; +// constexpr chrono::weekday_indexed weekday_indexed() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + + ASSERT_NOEXCEPT(year_month_weekday{}); + ASSERT_NOEXCEPT(year_month_weekday{year{1}, month{1}, weekday_indexed{Tuesday, 1}}); + + constexpr year_month_weekday ym0{}; + static_assert( ym0.year() == year{}, ""); + static_assert( ym0.month() == month{}, ""); + static_assert( ym0.weekday() == weekday{}, ""); + static_assert( ym0.index() == 0, ""); + static_assert( ym0.weekday_indexed() == weekday_indexed{}, ""); + static_assert(!ym0.ok(), ""); + + constexpr year_month_weekday ym1{year{2019}, January, weekday_indexed{Tuesday, 1}}; + static_assert( ym1.year() == year{2019}, ""); + static_assert( ym1.month() == January, ""); + static_assert( ym1.weekday() == Tuesday, ""); + static_assert( ym1.index() == 1, ""); + static_assert( ym1.weekday_indexed() == weekday_indexed{Tuesday, 1}, ""); + static_assert( ym1.ok(), ""); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.sys_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.sys_days.pass.cpp new file mode 100644 index 0000000..e3ae223 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.sys_days.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_weekday; + +// constexpr year_month_weekday(const sys_days& dp) noexcept; +// +// Effects: Constructs an object of type year_month_weekday that corresponds +// to the date represented by dp +// +// Remarks: For any value ymd of type year_month_weekday for which ymd.ok() is true, +// ymd == year_month_weekday{sys_days{ymd}} is true. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; +// using sys_days = std::chrono::sys_days; + using year_month_weekday = std::chrono::year_month_weekday; + +// ASSERT_NOEXCEPT(year_month_weekday{std::declval()}); + assert(false); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.year_month_day_last.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.year_month_day_last.pass.cpp new file mode 100644 index 0000000..20e48cb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.year_month_day_last.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_weekday; + +// constexpr year_month_weekday(const year_month_weekday_last& ymdl) noexcept; +// +// Effects: Constructs an object of type year_month_weekday by initializing +// y_ with ymdl.year(), m_ with ymdl.month(), and d_ with ymdl.day(). +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::day day() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + using year_month_weekday = std::chrono::year_month_weekday; + + ASSERT_NOEXCEPT(year_month_weekday{std::declval()}); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/index.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/index.pass.cpp new file mode 100644 index 0000000..6fbac7f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/index.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr unsigned index() const noexcept; +// Returns: wdi_.index() + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + ASSERT_NOEXCEPT( std::declval().index()); + ASSERT_SAME_TYPE(unsigned, decltype(std::declval().index())); + + static_assert( year_month_weekday{}.index() == 0, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_weekday ymwd0(year{1234}, month{2}, weekday_indexed{weekday{2}, i}); + assert(ymwd0.index() == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/month.pass.cpp new file mode 100644 index 0000000..67f9217 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/month.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( year_month_weekday{}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_weekday ymd(year{1234}, month{i}, weekday_indexed{}); + assert( static_cast(ymd.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ok.pass.cpp new file mode 100644 index 0000000..e2776f8 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ok.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr bool ok() const noexcept; +// Returns: m_.ok() && y_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!year_month_weekday{}.ok(), ""); + + static_assert(!year_month_weekday{year{-32768}, month{}, weekday_indexed{}}.ok(), ""); // All three bad + + static_assert(!year_month_weekday{year{-32768}, January, weekday_indexed{Tuesday, 1}}.ok(), ""); // Bad year + static_assert(!year_month_weekday{year{2019}, month{}, weekday_indexed{Tuesday, 1}}.ok(), ""); // Bad month + static_assert(!year_month_weekday{year{2019}, January, weekday_indexed{} }.ok(), ""); // Bad day + + static_assert(!year_month_weekday{year{-32768}, month{}, weekday_indexed{Tuesday, 1}}.ok(), ""); // Bad year & month + static_assert(!year_month_weekday{year{2019}, month{}, weekday_indexed{} }.ok(), ""); // Bad month & day + static_assert(!year_month_weekday{year{-32768}, January, weekday_indexed{} }.ok(), ""); // Bad year & day + + static_assert( year_month_weekday{year{2019}, January, weekday_indexed{Tuesday, 1}}.ok(), ""); // All OK + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_weekday ym{year{2019}, January, weekday_indexed{Tuesday, i}}; + assert((ym.ok() == weekday_indexed{Tuesday, i}.ok())); + } + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_weekday ym{year{2019}, January, weekday_indexed{weekday{i}, 1}}; + assert((ym.ok() == weekday_indexed{weekday{i}, 1}.ok())); + } + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_weekday ym{year{2019}, month{i}, weekday_indexed{Tuesday, 1}}; + assert((ym.ok() == month{i}.ok())); + } + + const int ymax = static_cast(year::max()); + for (int i = ymax - 100; i <= ymax + 100; ++i) + { + year_month_weekday ym{year{i}, January, weekday_indexed{Tuesday, 1}}; + assert((ym.ok() == year{i}.ok())); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_month.pass.cpp new file mode 100644 index 0000000..55aa86d --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_month.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr year_month_weekday& operator+=(const months& m) noexcept; +// constexpr year_month_weekday& operator-=(const months& m) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).month()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).month()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).month()) != 4) return false; + if (static_cast((d1 += Ds{12}).month()) != 4) return false; + if (static_cast((d1 -= Ds{ 1}).month()) != 3) return false; + if (static_cast((d1 -= Ds{ 2}).month()) != 1) return false; + if (static_cast((d1 -= Ds{12}).month()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + using years = std::chrono::years; + using months = std::chrono::months; + + + ASSERT_NOEXCEPT( std::declval() += std::declval()); + ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval() += std::declval())); + + ASSERT_NOEXCEPT( std::declval() -= std::declval()); + ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval() -= std::declval())); + + constexpr weekday Tuesday = std::chrono::Tuesday; + static_assert(testConstexpr(year_month_weekday{year{1234}, month{1}, weekday_indexed{Tuesday, 2}}), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + year y{1234}; + year_month_weekday ymwd(y, month{i}, weekday_indexed{Tuesday, 2}); + + assert(static_cast((ymwd += months{2}).month()) == i + 2); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + + assert(static_cast((ymwd ).month()) == i + 2); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + + assert(static_cast((ymwd -= months{1}).month()) == i + 1); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + + assert(static_cast((ymwd ).month()) == i + 1); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_year.pass.cpp new file mode 100644 index 0000000..10ba6c6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/plus_minus_equal_year.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr year_month_weekday& operator+=(const years& d) noexcept; +// constexpr year_month_weekday& operator-=(const years& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).year()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).year()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).year()) != 4) return false; + if (static_cast((d1 += Ds{12}).year()) != 16) return false; + if (static_cast((d1 -= Ds{ 1}).year()) != 15) return false; + if (static_cast((d1 -= Ds{ 2}).year()) != 13) return false; + if (static_cast((d1 -= Ds{12}).year()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + using years = std::chrono::years; + using months = std::chrono::months; + + ASSERT_NOEXCEPT( std::declval() += std::declval()); + ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval() += std::declval())); + + ASSERT_NOEXCEPT( std::declval() -= std::declval()); + ASSERT_SAME_TYPE(year_month_weekday&, decltype(std::declval() -= std::declval())); + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month January = std::chrono::January; + + static_assert(testConstexpr(year_month_weekday{year{1}, January, weekday_indexed{Tuesday, 2}}), ""); + + for (int i = 1000; i <= 1010; ++i) + { + year_month_weekday ymwd(year{i}, January, weekday_indexed{Tuesday, 2}); + + assert(static_cast((ymwd += years{2}).year()) == i + 2); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + + assert(static_cast((ymwd ).year()) == i + 2); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + + assert(static_cast((ymwd -= years{1}).year()) == i + 1); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + + assert(static_cast((ymwd ).year()) == i + 1); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + assert(ymwd.index() == 2); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday.pass.cpp new file mode 100644 index 0000000..6241a07 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr chrono::weekday weekday() const noexcept; +// Returns: wdi_.weekday() + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + ASSERT_NOEXCEPT( std::declval().weekday()); + ASSERT_SAME_TYPE(weekday, decltype(std::declval().weekday())); + + static_assert( year_month_weekday{}.weekday() == weekday{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_weekday ymwd0(year{1234}, month{2}, weekday_indexed{weekday{i}, 1}); + assert(static_cast(ymwd0.weekday()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday_indexed.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday_indexed.pass.cpp new file mode 100644 index 0000000..da09613 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/weekday_indexed.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr chrono::weekday_indexed weekday_indexed() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + ASSERT_NOEXCEPT( std::declval().weekday_indexed()); + ASSERT_SAME_TYPE(weekday_indexed, decltype(std::declval().weekday_indexed())); + + static_assert( year_month_weekday{}.weekday_indexed() == weekday_indexed{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_weekday ymwd0(year{1234}, month{2}, weekday_indexed{weekday{i}, 1}); + assert( static_cast(ymwd0.weekday_indexed().weekday()) == i); + assert( static_cast(ymwd0.weekday_indexed().index()) == 1); + year_month_weekday ymwd1(year{1234}, month{2}, weekday_indexed{weekday{2}, i}); + assert( static_cast(ymwd1.weekday_indexed().weekday()) == 2); + assert( static_cast(ymwd1.weekday_indexed().index()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/year.pass.cpp new file mode 100644 index 0000000..7db8439 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/year.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr chrono::year year() const noexcept; +// Returns: d_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + + ASSERT_NOEXCEPT( std::declval().year()); + ASSERT_SAME_TYPE(year, decltype(std::declval().year())); + + static_assert( year_month_weekday{}.year() == year{}, ""); + + for (int i = 1; i <= 50; ++i) + { + year_month_weekday ym(year{i}, month{1}, weekday_indexed{}); + assert( static_cast(ym.year()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..6e8f7c0 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/comparisons.pass.cpp @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr bool operator==(const year_month_weekday& x, const year_month_weekday& y) noexcept; +// Returns: x.year() == y.year() && x.month() == y.month() && x.weekday_indexed() == y.weekday_indexed() +// + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday_indexed = std::chrono::weekday_indexed; + using weekday = std::chrono::weekday; + using year_month_weekday = std::chrono::year_month_weekday; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + constexpr month January = std::chrono::January; + constexpr month February = std::chrono::February; + constexpr weekday Tuesday = std::chrono::Tuesday; + + static_assert( testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 1}}, + true), ""); + +// different day + static_assert( testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 2}}, + false), ""); + +// different month + static_assert( testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1234}, February, weekday_indexed{Tuesday, 1}}, + false), ""); + +// different year + static_assert( testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1235}, January, weekday_indexed{Tuesday, 1}}, + false), ""); + + +// different month and day + static_assert( testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1234}, February, weekday_indexed{Tuesday, 2}}, + false), ""); + +// different year and month + static_assert( testComparisons2( + year_month_weekday{year{1234}, February, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1235}, January, weekday_indexed{Tuesday, 1}}, + false), ""); + +// different year and day + static_assert( testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, 2}}, + year_month_weekday{year{1235}, January, weekday_indexed{Tuesday, 1}}, + false), ""); + +// different year, month and day + static_assert( testComparisons2( + year_month_weekday{year{1234}, February, weekday_indexed{Tuesday, 2}}, + year_month_weekday{year{1235}, January, weekday_indexed{Tuesday, 1}}, + false), ""); + + +// same year, different days + for (unsigned i = 1; i < 28; ++i) + for (unsigned j = 1; j < 28; ++j) + assert((testComparisons2( + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, i}}, + year_month_weekday{year{1234}, January, weekday_indexed{Tuesday, j}}, + i == j))); + +// same year, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons2( + year_month_weekday{year{1234}, month{i}, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{1234}, month{j}, weekday_indexed{Tuesday, 1}}, + i == j))); + +// same month, different years + for (int i = 1000; i < 20; ++i) + for (int j = 1000; j < 20; ++j) + assert((testComparisons2( + year_month_weekday{year{i}, January, weekday_indexed{Tuesday, 1}}, + year_month_weekday{year{j}, January, weekday_indexed{Tuesday, 1}}, + i == j))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..a92811c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/minus.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const months& dm) noexcept; +// Returns: ymwd + (-dm). +// +// constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const years& dy) noexcept; +// Returns: ymwd + (-dy). + + +#include +#include +#include + +#include "test_macros.h" + +#include + +constexpr bool testConstexprYears () +{ + std::chrono::year_month_weekday ym0{std::chrono::year{1234}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::Tuesday, 1}}; + std::chrono::year_month_weekday ym1 = ym0 - std::chrono::years{10}; + return + ym1.year() == std::chrono::year{1234-10} + && ym1.month() == std::chrono::January + && ym1.weekday() == std::chrono::Tuesday + && ym1.index() == 1 + ; +} + +constexpr bool testConstexprMonths () +{ + std::chrono::year_month_weekday ym0{std::chrono::year{1234}, std::chrono::November, std::chrono::weekday_indexed{std::chrono::Tuesday, 1}}; + std::chrono::year_month_weekday ym1 = ym0 - std::chrono::months{6}; + return + ym1.year() == std::chrono::year{1234} + && ym1.month() == std::chrono::May + && ym1.weekday() == std::chrono::Tuesday + && ym1.index() == 1 + ; +} + + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + using years = std::chrono::years; + using months = std::chrono::months; + + constexpr month November = std::chrono::November; + constexpr weekday Tuesday = std::chrono::Tuesday; + + { // year_month_weekday - years + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval() - std::declval())); + + static_assert(testConstexprYears(), ""); + + year_month_weekday ym{year{1234}, November, weekday_indexed{Tuesday, 1}}; + for (int i = 0; i <= 10; ++i) + { + year_month_weekday ym1 = ym - years{i}; + assert(static_cast(ym1.year()) == 1234 - i); + assert(ym1.month() == November); + assert(ym1.weekday() == Tuesday); + assert(ym1.index() == 1); + } + } + + { // year_month_weekday - months + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval() - std::declval())); + + static_assert(testConstexprMonths(), ""); + + year_month_weekday ym{year{1234}, November, weekday_indexed{Tuesday, 2}}; + for (unsigned i = 1; i <= 10; ++i) + { + year_month_weekday ym1 = ym - months{i}; + assert(ym1.year() == year{1234}); + assert(ym1.month() == month{11-i}); + assert(ym1.weekday() == Tuesday); + assert(ym1.index() == 2); + } + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..38838fb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/plus.pass.cpp @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +// constexpr year_month_weekday operator+(const year_month_weekday& ymd, const months& dm) noexcept; +// Returns: (ymd.year() / ymd.month() + dm) / ymd.day(). +// +// constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymd) noexcept; +// Returns: ymd + dm. +// +// +// constexpr year_month_weekday operator+(const year_month_weekday& ymd, const years& dy) noexcept; +// Returns: (ymd.year() + dy) / ymd.month() / ymd.day(). +// +// constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymd) noexcept; +// Returns: ym + dm. + + + +#include +#include +#include + +#include "test_macros.h" + +constexpr bool testConstexprYears(std::chrono::year_month_weekday ym) +{ + std::chrono::years offset{23}; + if (static_cast((ym ).year()) != 1) return false; + if (static_cast((ym + offset).year()) != 24) return false; + if (static_cast((offset + ym).year()) != 24) return false; + return true; +} + + +constexpr bool testConstexprMonths(std::chrono::year_month_weekday ym) +{ + std::chrono::months offset{6}; + if (static_cast((ym ).month()) != 1) return false; + if (static_cast((ym + offset).month()) != 7) return false; + if (static_cast((offset + ym).month()) != 7) return false; + return true; +} + + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using weekday = std::chrono::weekday; + using weekday_indexed = std::chrono::weekday_indexed; + using year_month_weekday = std::chrono::year_month_weekday; + using years = std::chrono::years; + using months = std::chrono::months; + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month January = std::chrono::January; + + { // year_month_weekday + months (and switched) + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval() + std::declval())); + + static_assert(testConstexprMonths(year_month_weekday{year{1}, January, weekday_indexed{Tuesday, 1}}), ""); + + year_month_weekday ym{year{1234}, January, weekday_indexed{Tuesday, 3}}; + for (int i = 0; i <= 10; ++i) // TODO test wrap-around + { + year_month_weekday ym1 = ym + months{i}; + year_month_weekday ym2 = months{i} + ym; + assert(static_cast(ym1.year()) == 1234); + assert(static_cast(ym2.year()) == 1234); + assert(ym1.month() == month(1 + i)); + assert(ym2.month() == month(1 + i)); + assert(ym1.weekday() == Tuesday); + assert(ym2.weekday() == Tuesday); + assert(ym1.index() == 3); + assert(ym2.index() == 3); + assert(ym1 == ym2); + } + } + + { // year_month_weekday + years (and switched) + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_weekday, decltype(std::declval() + std::declval())); + + static_assert(testConstexprYears (year_month_weekday{year{1}, January, weekday_indexed{Tuesday, 1}}), ""); + + year_month_weekday ym{year{1234}, std::chrono::January, weekday_indexed{Tuesday, 3}}; + for (int i = 0; i <= 10; ++i) + { + year_month_weekday ym1 = ym + years{i}; + year_month_weekday ym2 = years{i} + ym; + assert(static_cast(ym1.year()) == i + 1234); + assert(static_cast(ym2.year()) == i + 1234); + assert(ym1.month() == January); + assert(ym2.month() == January); + assert(ym1.weekday() == Tuesday); + assert(ym2.weekday() == Tuesday); + assert(ym1.index() == 3); + assert(ym2.index() == 3); + assert(ym1 == ym2); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..da00074 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/time.cal.ymwd.nonmembers/streaming.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_weekday; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const year_month_weekday& ym); +// +// Returns: os << ym.year() << '/' << ym.month(). +// +// +// template +// basic_ostream& +// to_stream(basic_ostream& os, const charT* fmt, const year_month_weekday& ym); +// +// Effects: Streams ym into os using the format specified by the NTCTS fmt. fmt encoding follows the rules specified in 25.11. +// +// template> +// basic_istream& +// from_stream(basic_istream& is, const charT* fmt, +// year_month_weekday& ym, basic_string* abbrev = nullptr, +// minutes* offset = nullptr); +// +// Effects: Attempts to parse the input stream is into the year_month_weekday ym using the format +// flags given in the NTCTS fmt as specified in 25.12. If the parse fails to decode +// a valid year_month_weekday, is.setstate(ios_- base::failbit) shall be called and ym shall +// not be modified. If %Z is used and successfully parsed, that value will be assigned +// to *abbrev if abbrev is non-null. If %z (or a modified variant) is used and +// successfully parsed, that value will be assigned to *offset if offset is non-null. + + + +#include +#include +#include +#include +#include "test_macros.h" + +int main() +{ + using year_month_weekday = std::chrono::year_month_weekday; + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + + std::cout << year_month_weekday{year{2018}, month{3}, weekday{4}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/types.pass.cpp new file mode 100644 index 0000000..cd7a0b9 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwd/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month_weekday = std::chrono::year_month_weekday; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ctor.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ctor.pass.cpp new file mode 100644 index 0000000..2bc4038 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ctor.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr year_month_weekday_last(const chrono::year& y, const chrono::month& m, +// const chrono::weekday_last& wdl) noexcept; +// +// Effects: Constructs an object of type year_month_weekday_last by initializing +// y_ with y, m_ with m, and wdl_ with wdl. +// +// constexpr chrono::year year() const noexcept; +// constexpr chrono::month month() const noexcept; +// constexpr chrono::weekday weekday() const noexcept; +// constexpr chrono::weekday_last weekday_last() const noexcept; +// constexpr bool ok() const noexcept; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + + ASSERT_NOEXCEPT(year_month_weekday_last{year{1}, month{1}, weekday_last{Tuesday}}); + + constexpr year_month_weekday_last ym1{year{2019}, January, weekday_last{Tuesday}}; + static_assert( ym1.year() == year{2019}, ""); + static_assert( ym1.month() == January, ""); + static_assert( ym1.weekday() == Tuesday, ""); + static_assert( ym1.weekday_last() == weekday_last{Tuesday}, ""); + static_assert( ym1.ok(), ""); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/month.pass.cpp new file mode 100644 index 0000000..5602d25 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/month.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr chrono::month month() const noexcept; +// Returns: wd_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + ASSERT_NOEXCEPT( std::declval().month()); + ASSERT_SAME_TYPE(month, decltype(std::declval().month())); + + static_assert( year_month_weekday_last{year{}, month{}, weekday_last{weekday{}}}.month() == month{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_weekday_last ymd(year{1234}, month{i}, weekday_last{weekday{}}); + assert( static_cast(ymd.month()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ok.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ok.pass.cpp new file mode 100644 index 0000000..2c43184 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/ok.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr bool ok() const noexcept; +// Returns: y_.ok() && m_.ok() && wdl_.ok(). + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + constexpr month January = std::chrono::January; + constexpr weekday Tuesday = std::chrono::Tuesday; + + ASSERT_NOEXCEPT( std::declval().ok()); + ASSERT_SAME_TYPE(bool, decltype(std::declval().ok())); + + static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{weekday{}}}.ok(), ""); // All three bad + + static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{Tuesday}}.ok(), ""); // Bad year + static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{Tuesday}}.ok(), ""); // Bad month + static_assert(!year_month_weekday_last{year{2019}, January, weekday_last{weekday{7}}}.ok(), ""); // Bad day + + static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{Tuesday}}.ok(), ""); // Bad year & month + static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{weekday{7}}}.ok(), ""); // Bad month & day + static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{weekday{7}}}.ok(), ""); // Bad year & day + + static_assert( year_month_weekday_last{year{2019}, January, weekday_last{Tuesday}}.ok(), ""); // All OK + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_weekday_last ym{year{2019}, January, weekday_last{Tuesday}}; + assert((ym.ok() == weekday_last{Tuesday}.ok())); + } + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_weekday_last ym{year{2019}, January, weekday_last{weekday{i}}}; + assert((ym.ok() == weekday_last{weekday{i}}.ok())); + } + + for (unsigned i = 0; i <= 50; ++i) + { + year_month_weekday_last ym{year{2019}, month{i}, weekday_last{Tuesday}}; + assert((ym.ok() == month{i}.ok())); + } + + const int ymax = static_cast(year::max()); + for (int i = ymax - 100; i <= ymax + 100; ++i) + { + year_month_weekday_last ym{year{i}, January, weekday_last{Tuesday}}; + assert((ym.ok() == year{i}.ok())); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_local_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_local_days.pass.cpp new file mode 100644 index 0000000..48b87cb --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_local_days.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day_last; + +// constexpr operator local_days() const noexcept; +// Returns: local_days{sys_days{*this}.time_since_epoch()}. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + using sys_days = std::chrono::local_days; + + ASSERT_NOEXCEPT( static_cast(std::declval().year())); + ASSERT_SAME_TYPE(year, decltype(static_cast(std::declval().year())); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_sys_days.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_sys_days.pass.cpp new file mode 100644 index 0000000..a89f71f --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/op_sys_days.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_day_last; + +// constexpr operator sys_days() const noexcept; +// Returns: sys_days{year()/month()/day()}. + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using day = std::chrono::day; + using month_day_last = std::chrono::month_day_last; + using year_month_day_last = std::chrono::year_month_day_last; + using sys_days = std::chrono::sys_days; + + ASSERT_NOEXCEPT( static_cast(std::declval().year())); + ASSERT_SAME_TYPE(year, decltype(static_cast(std::declval().year())); + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_month.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_month.pass.cpp new file mode 100644 index 0000000..0785bef --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_month.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr year_month_weekday_last& operator+=(const months& m) noexcept; +// constexpr year_month_weekday_last& operator-=(const months& m) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).month()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).month()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).month()) != 4) return false; + if (static_cast((d1 += Ds{12}).month()) != 4) return false; + if (static_cast((d1 -= Ds{ 1}).month()) != 3) return false; + if (static_cast((d1 -= Ds{ 2}).month()) != 1) return false; + if (static_cast((d1 -= Ds{12}).month()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + using months = std::chrono::months; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year_month_weekday_last&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year_month_weekday_last&, decltype(std::declval() -= std::declval())); + + constexpr weekday Tuesday = std::chrono::Tuesday; + static_assert(testConstexpr(year_month_weekday_last{year{1234}, month{1}, weekday_last{Tuesday}}), ""); + + for (unsigned i = 0; i <= 10; ++i) + { + year y{1234}; + year_month_weekday_last ymwd(y, month{i}, weekday_last{Tuesday}); + + assert(static_cast((ymwd += months{2}).month()) == i + 2); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + + assert(static_cast((ymwd ).month()) == i + 2); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + + assert(static_cast((ymwd -= months{1}).month()) == i + 1); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + + assert(static_cast((ymwd ).month()) == i + 1); + assert(ymwd.year() == y); + assert(ymwd.weekday() == Tuesday); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_year.pass.cpp new file mode 100644 index 0000000..3a2a700 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/plus_minus_equal_year.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr year_month_weekday_last& operator+=(const years& d) noexcept; +// constexpr year_month_weekday_last& operator-=(const years& d) noexcept; + +#include +#include +#include + +#include "test_macros.h" + +template +constexpr bool testConstexpr(D d1) +{ + if (static_cast((d1 ).year()) != 1) return false; + if (static_cast((d1 += Ds{ 1}).year()) != 2) return false; + if (static_cast((d1 += Ds{ 2}).year()) != 4) return false; + if (static_cast((d1 += Ds{12}).year()) != 16) return false; + if (static_cast((d1 -= Ds{ 1}).year()) != 15) return false; + if (static_cast((d1 -= Ds{ 2}).year()) != 13) return false; + if (static_cast((d1 -= Ds{12}).year()) != 1) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + using years = std::chrono::years; + + ASSERT_NOEXCEPT(std::declval() += std::declval()); + ASSERT_NOEXCEPT(std::declval() -= std::declval()); + + ASSERT_SAME_TYPE(year_month_weekday_last&, decltype(std::declval() += std::declval())); + ASSERT_SAME_TYPE(year_month_weekday_last&, decltype(std::declval() -= std::declval())); + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month January = std::chrono::January; + + static_assert(testConstexpr(year_month_weekday_last{year{1}, January, weekday_last{Tuesday}}), ""); + + for (int i = 1000; i <= 1010; ++i) + { + year_month_weekday_last ymwd(year{i}, January, weekday_last{Tuesday}); + + assert(static_cast((ymwd += years{2}).year()) == i + 2); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + + assert(static_cast((ymwd ).year()) == i + 2); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + + assert(static_cast((ymwd -= years{1}).year()) == i + 1); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + + assert(static_cast((ymwd ).year()) == i + 1); + assert(ymwd.month() == January); + assert(ymwd.weekday() == Tuesday); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/weekday.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/weekday.pass.cpp new file mode 100644 index 0000000..a882576 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/weekday.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr chrono::weekday weekday() const noexcept; +// Returns: wdi_.weekday() + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + ASSERT_NOEXCEPT( std::declval().weekday()); + ASSERT_SAME_TYPE(weekday, decltype(std::declval().weekday())); + + static_assert( year_month_weekday_last{year{}, month{}, weekday_last{weekday{}}}.weekday() == weekday{}, ""); + + for (unsigned i = 1; i <= 50; ++i) + { + year_month_weekday_last ymwdl(year{1}, month{1}, weekday_last{weekday{i}}); + assert(static_cast(ymwdl.weekday()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/year.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/year.pass.cpp new file mode 100644 index 0000000..86e2985 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.members/year.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr chrono::year year() const noexcept; +// Returns: d_ + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + ASSERT_NOEXCEPT( std::declval().year()); + ASSERT_SAME_TYPE(year, decltype(std::declval().year())); + + static_assert( year_month_weekday_last{year{}, month{}, weekday_last{weekday{}}}.year() == year{}, ""); + + for (int i = 1; i <= 50; ++i) + { + year_month_weekday_last ymwdl(year{i}, month{1}, weekday_last{weekday{}}); + assert(static_cast(ymwdl.year()) == i); + } +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/comparisons.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/comparisons.pass.cpp new file mode 100644 index 0000000..4ddfed6 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/comparisons.pass.cpp @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr bool operator==(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept; +// Returns: x.year() == y.year() && x.month() == y.month() && x.weekday_last() == y.weekday_last() +// + + +#include +#include +#include + +#include "test_macros.h" +#include "test_comparisons.h" + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + AssertComparisons2AreNoexcept(); + AssertComparisons2ReturnBool(); + + constexpr month January = std::chrono::January; + constexpr month February = std::chrono::February; + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr weekday Wednesday = std::chrono::Wednesday; + + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, + year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, + true), ""); + +// different day + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, + year_month_weekday_last{year{1234}, January, weekday_last{Wednesday}}, + false), ""); + +// different month + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, + year_month_weekday_last{year{1234}, February, weekday_last{Tuesday}}, + false), ""); + +// different year + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, + year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, + false), ""); + + +// different month and day + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{Tuesday}}, + year_month_weekday_last{year{1234}, February, weekday_last{Wednesday}}, + false), ""); + +// different year and month + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, February, weekday_last{Tuesday}}, + year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, + false), ""); + +// different year and day + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{Wednesday}}, + year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, + false), ""); + +// different year, month and day + static_assert( testComparisons2( + year_month_weekday_last{year{1234}, February, weekday_last{Wednesday}}, + year_month_weekday_last{year{1235}, January, weekday_last{Tuesday}}, + false), ""); + + +// same year, different days + for (unsigned i = 1; i < 28; ++i) + for (unsigned j = 1; j < 28; ++j) + assert((testComparisons2( + year_month_weekday_last{year{1234}, January, weekday_last{weekday{i}}}, + year_month_weekday_last{year{1234}, January, weekday_last{weekday{j}}}, + i == j))); + +// same year, different months + for (unsigned i = 1; i < 12; ++i) + for (unsigned j = 1; j < 12; ++j) + assert((testComparisons2( + year_month_weekday_last{year{1234}, month{i}, weekday_last{Tuesday}}, + year_month_weekday_last{year{1234}, month{j}, weekday_last{Tuesday}}, + i == j))); + +// same month, different years + for (int i = 1000; i < 20; ++i) + for (int j = 1000; j < 20; ++j) + assert((testComparisons2( + year_month_weekday_last{year{i}, January, weekday_last{Tuesday}}, + year_month_weekday_last{year{j}, January, weekday_last{Tuesday}}, + i == j))); +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/minus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/minus.pass.cpp new file mode 100644 index 0000000..2b58c03 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/minus.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; +// Returns: ymwdl + (-dm). +// +// constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; +// Returns: ymwdl + (-dy). + +#include +#include +#include + +#include "test_macros.h" + +#include + +constexpr bool testConstexprYears(std::chrono::year_month_weekday_last ym) +{ + std::chrono::years offset{14}; + if (static_cast((ym ).year()) != 66) return false; + if (static_cast((ym - offset).year()) != 52) return false; + return true; +} + +constexpr bool testConstexprMonths(std::chrono::year_month_weekday_last ym) +{ + std::chrono::months offset{6}; + if (static_cast((ym ).month()) != 10) return false; + if (static_cast((ym - offset).month()) != 4) return false; + return true; +} + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + using years = std::chrono::years; + using months = std::chrono::months; + + constexpr month October = std::chrono::October; + constexpr weekday Tuesday = std::chrono::Tuesday; + + { // year_month_weekday_last - years + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval() - std::declval())); + + static_assert(testConstexprYears(year_month_weekday_last{year{66}, October, weekday_last{Tuesday}}), ""); + + year_month_weekday_last ym{year{1234}, October, weekday_last{Tuesday}}; + for (int i = 0; i <= 10; ++i) + { + year_month_weekday_last ym1 = ym - years{i}; + assert(ym1.year() == year{1234 - i}); + assert(ym1.month() == October); + assert(ym1.weekday() == Tuesday); + assert(ym1.weekday_last() == weekday_last{Tuesday}); + } + } + + { // year_month_weekday_last - months + + ASSERT_NOEXCEPT( std::declval() - std::declval()); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval() - std::declval())); + + static_assert(testConstexprMonths(year_month_weekday_last{year{66}, October, weekday_last{Tuesday}}), ""); + + year_month_weekday_last ym{year{1234}, October, weekday_last{Tuesday}}; + for (unsigned i = 0; i < 10; ++i) + { + year_month_weekday_last ym1 = ym - months{i}; + assert(ym1.year() == year{1234}); + assert(ym1.month() == month{10 - i}); + assert(ym1.weekday() == Tuesday); + assert(ym1.weekday_last() == weekday_last{Tuesday}); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/plus.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/plus.pass.cpp new file mode 100644 index 0000000..59ae592 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/plus.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last; + +// constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; +// Returns: (ymwdl.year() / ymwdl.month() + dm) / ymwdl.weekday_last(). +// +// constexpr year_month_weekday_last operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; +// Returns: ymwdl + dm. +// +// constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; +// Returns: {ymwdl.year()+dy, ymwdl.month(), ymwdl.weekday_last()}. +// +// constexpr year_month_weekday_last operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; +// Returns: ymwdl + dy. + +#include +#include +#include + +#include "test_macros.h" + +constexpr bool testConstexprYears(std::chrono::year_month_weekday_last ym) +{ + std::chrono::years offset{23}; + if (static_cast((ym ).year()) != 1) return false; + if (static_cast((ym + offset).year()) != 24) return false; + if (static_cast((offset + ym).year()) != 24) return false; + return true; +} + +constexpr bool testConstexprMonths(std::chrono::year_month_weekday_last ym) +{ + std::chrono::months offset{6}; + if (static_cast((ym ).month()) != 1) return false; + if (static_cast((ym + offset).month()) != 7) return false; + if (static_cast((offset + ym).month()) != 7) return false; + return true; +} + + +int main() +{ + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + using year_month_weekday_last = std::chrono::year_month_weekday_last; + using years = std::chrono::years; + using months = std::chrono::months; + + constexpr weekday Tuesday = std::chrono::Tuesday; + constexpr month January = std::chrono::January; + + { // year_month_weekday_last + months + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval() + std::declval())); + + static_assert(testConstexprMonths(year_month_weekday_last{year{1}, January, weekday_last{Tuesday}}), ""); + + year_month_weekday_last ym{year{1234}, January, weekday_last{Tuesday}}; + for (int i = 0; i <= 10; ++i) // TODO test wrap-around + { + year_month_weekday_last ym1 = ym + months{i}; + year_month_weekday_last ym2 = months{i} + ym; + assert(ym1.year() == year(1234)); + assert(ym2.year() == year(1234)); + assert(ym1.month() == month(1 + i)); + assert(ym2.month() == month(1 + i)); + assert(ym1.weekday() == Tuesday); + assert(ym2.weekday() == Tuesday); + assert(ym1.weekday_last() == weekday_last{Tuesday}); + assert(ym2.weekday_last() == weekday_last{Tuesday}); + assert(ym1 == ym2); + } + } + + { // year_month_weekday_last + years + ASSERT_NOEXCEPT(std::declval() + std::declval()); + ASSERT_NOEXCEPT(std::declval() + std::declval()); + + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval() + std::declval())); + ASSERT_SAME_TYPE(year_month_weekday_last, decltype(std::declval() + std::declval())); + + static_assert(testConstexprYears (year_month_weekday_last{year{1}, January, weekday_last{Tuesday}}), ""); + + year_month_weekday_last ym{year{1234}, std::chrono::January, weekday_last{Tuesday}}; + for (int i = 0; i <= 10; ++i) + { + year_month_weekday_last ym1 = ym + years{i}; + year_month_weekday_last ym2 = years{i} + ym; + assert(ym1.year() == year(1234 + i)); + assert(ym2.year() == year(1234 + i)); + assert(ym1.month() == January); + assert(ym2.month() == January); + assert(ym1.weekday() == Tuesday); + assert(ym2.weekday() == Tuesday); + assert(ym1.weekday_last() == weekday_last{Tuesday}); + assert(ym2.weekday_last() == weekday_last{Tuesday}); + assert(ym1 == ym2); + } + } + +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/streaming.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/streaming.pass.cpp new file mode 100644 index 0000000..d23cb3c --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/time.cal.ymwdlast.nonmembers/streaming.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 +// XFAIL: * + +// +// class year_month_weekday_last; + +// template +// basic_ostream& +// operator<<(basic_ostream& os, const year_month_weekday_last& ymwdl); +// +// Returns: os << ymwdl.year() << '/' << ymwdl.month() << '/' << ymwdl.weekday_last(). + + +#include +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month_weekday_last = std::chrono::year_month_weekday_last; + using year = std::chrono::year; + using month = std::chrono::month; + using weekday = std::chrono::weekday; + using weekday_last = std::chrono::weekday_last; + + std::cout << year_month_weekday_last{year{2018}, month{3}, weekday_last{weekday{4}}}; +} diff --git a/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/types.pass.cpp b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/types.pass.cpp new file mode 100644 index 0000000..198af65 --- /dev/null +++ b/libcxx/test/std/utilities/time/time.cal/time.cal.ymwdlast/types.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// +// class year_month_weekday_last_last; + +#include +#include +#include + +#include "test_macros.h" + +int main() +{ + using year_month_weekday_last = std::chrono::year_month_weekday_last; + + static_assert(std::is_trivially_copyable_v, ""); + static_assert(std::is_standard_layout_v, ""); +} diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp index d5c0207..e10b35e 100644 --- a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals.pass.cpp @@ -14,6 +14,8 @@ #include #include +#include "test_macros.h" + int main() { using namespace std::literals::chrono_literals; @@ -55,4 +57,5 @@ int main() assert ( ns == std::chrono::nanoseconds(645)); auto ns2 = 645.ns; assert ( ns == ns2 ); + } diff --git a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp index 5e59e11..6e43e3a9 100644 --- a/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp +++ b/libcxx/test/std/utilities/time/time.duration/time.duration.literals/literals1.pass.cpp @@ -7,8 +7,8 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// - // UNSUPPORTED: c++98, c++03, c++11 + #include #include @@ -45,4 +45,27 @@ int main() assert ( ns == nanoseconds(645)); auto ns2 = 645.ns; assert ( ns == ns2 ); + +#if TEST_STD_VER > 17 + assert(Sunday == weekday(0)); + assert(Monday == weekday(1)); + assert(Tuesday == weekday(2)); + assert(Wednesday == weekday(3)); + assert(Thursday == weekday(4)); + assert(Friday == weekday(5)); + assert(Saturday == weekday(6)); + + assert(January == month(1)); + assert(February == month(2)); + assert(March == month(3)); + assert(April == month(4)); + assert(May == month(5)); + assert(June == month(6)); + assert(July == month(7)); + assert(August == month(8)); + assert(September == month(9)); + assert(October == month(10)); + assert(November == month(11)); + assert(December == month(12)); +#endif } diff --git a/libcxx/test/std/utilities/time/weeks.pass.cpp b/libcxx/test/std/utilities/time/weeks.pass.cpp new file mode 100644 index 0000000..6099d55 --- /dev/null +++ b/libcxx/test/std/utilities/time/weeks.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// using weeks = duration, days::period>>; + +#include +#include +#include + +int main() +{ + typedef std::chrono::weeks D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed::value, ""); + static_assert(std::is_integral::value, ""); + static_assert(std::numeric_limits::digits >= 22, ""); + static_assert(std::is_same_v, std::chrono::days::period>>, ""); +} diff --git a/libcxx/test/std/utilities/time/years.pass.cpp b/libcxx/test/std/utilities/time/years.pass.cpp new file mode 100644 index 0000000..ad68e64 --- /dev/null +++ b/libcxx/test/std/utilities/time/years.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// using years = duration, days::period>> + +#include +#include +#include + +int main() +{ + typedef std::chrono::years D; + typedef D::rep Rep; + typedef D::period Period; + static_assert(std::is_signed::value, ""); + static_assert(std::is_integral::value, ""); + static_assert(std::numeric_limits::digits >= 17, ""); + static_assert(std::is_same_v, std::chrono::days::period>>, ""); +} -- 2.7.4