├── .gitattributes ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── ci └── install_cmake.sh ├── cmake └── dateConfig.cmake ├── compile_fail.sh ├── include └── date │ ├── chrono_io.h │ ├── date.h │ ├── ios.h │ ├── islamic.h │ ├── iso_week.h │ ├── julian.h │ ├── ptz.h │ ├── solar_hijri.h │ ├── tz.h │ └── tz_private.h ├── src ├── ios.mm └── tz.cpp ├── test ├── clock_cast_test │ ├── constexpr.pass.cpp │ ├── custom_clock.pass.cpp │ ├── deprecated.pass.cpp │ ├── local_t.pass.cpp │ ├── noncastable.pass.cpp │ ├── normal_clocks.pass.cpp │ ├── to_sys_return_int.fail.cpp │ ├── to_sys_return_reference.fail.cpp │ └── to_sys_return_utc_time.fail.cpp ├── date_test │ ├── day.pass.cpp │ ├── daypday.fail.cpp │ ├── daysmday.fail.cpp │ ├── daysmweekday.fail.cpp │ ├── detail │ │ ├── decimal_format_seconds.pass.cpp │ │ ├── static_pow10.pass.cpp │ │ └── width.pass.cpp │ ├── durations.pass.cpp │ ├── durations_output.pass.cpp │ ├── format │ │ ├── century.pass.cpp │ │ ├── misc.pass.cpp │ │ ├── range.pass.cpp │ │ └── two_dight_year.pass.cpp │ ├── last.pass.cpp │ ├── make_time.pass.cpp │ ├── month.pass.cpp │ ├── month_day.pass.cpp │ ├── month_day_last.pass.cpp │ ├── month_weekday.pass.cpp │ ├── month_weekday_last.pass.cpp │ ├── month_weekday_last_less.fail.cpp │ ├── month_weekday_less.fail.cpp │ ├── monthpmonth.fail.cpp │ ├── months_m_year_month.fail.cpp │ ├── months_m_year_month_day.fail.cpp │ ├── monthsmmonth.fail.cpp │ ├── multi_year_duration_addition.pass.cpp │ ├── op_div_day_day.fail.cpp │ ├── op_div_int_month.fail.cpp │ ├── op_div_int_year.fail.cpp │ ├── op_div_last_last.fail.cpp │ ├── op_div_month_day.pass.cpp │ ├── op_div_month_day_last.pass.cpp │ ├── op_div_month_day_month_day.fail.cpp │ ├── op_div_month_month.fail.cpp │ ├── op_div_month_weekday.pass.cpp │ ├── op_div_month_weekday_last.pass.cpp │ ├── op_div_month_year.fail.cpp │ ├── op_div_survey.pass.cpp │ ├── op_div_weekday_indexed_weekday_indexed.fail.cpp │ ├── op_div_weekday_last_weekday_last.fail.cpp │ ├── op_div_year_month.pass.cpp │ ├── op_div_year_month_day.pass.cpp │ ├── op_div_year_month_day_last.pass.cpp │ ├── op_div_year_month_weekday.pass.cpp │ ├── op_div_year_month_weekday_last.pass.cpp │ ├── op_div_year_month_year_month.fail.cpp │ ├── op_div_year_year.fail.cpp │ ├── parse.pass.cpp │ ├── sizeof.pass.cpp │ ├── time_of_day_hours.pass.cpp │ ├── time_of_day_microfortnights.pass.cpp │ ├── time_of_day_milliseconds.pass.cpp │ ├── time_of_day_minutes.pass.cpp │ ├── time_of_day_nanoseconds.pass.cpp │ ├── time_of_day_seconds.pass.cpp │ ├── weekday.pass.cpp │ ├── weekday_indexed.pass.cpp │ ├── weekday_last.pass.cpp │ ├── weekday_lessthan.fail.cpp │ ├── weekday_sum.fail.cpp │ ├── year.pass.cpp │ ├── year_month.pass.cpp │ ├── year_month_day.pass.cpp │ ├── year_month_day_last.pass.cpp │ ├── year_month_day_m_year_month_day.fail.cpp │ ├── year_month_day_p_year_month_day.fail.cpp │ ├── year_month_p_year_month.fail.cpp │ ├── year_month_weekday.pass.cpp │ ├── year_month_weekday_last.pass.cpp │ ├── year_p_year.fail.cpp │ ├── years_m_year.fail.cpp │ ├── years_m_year_month.fail.cpp │ └── years_m_year_month_day.fail.cpp ├── iso_week │ ├── last.pass.cpp │ ├── lastweek_weekday.pass.cpp │ ├── op_div_survey.pass.cpp │ ├── weekday.pass.cpp │ ├── weekday_lessthan.fail.cpp │ ├── weekday_sum.fail.cpp │ ├── weeknum.pass.cpp │ ├── weeknum_p_weeknum.fail.cpp │ ├── weeknum_weekday.pass.cpp │ ├── year.pass.cpp │ ├── year_lastweek.pass.cpp │ ├── year_lastweek_weekday.pass.cpp │ ├── year_p_year.fail.cpp │ ├── year_weeknum.pass.cpp │ ├── year_weeknum_weekday.pass.cpp │ └── years_m_year.fail.cpp ├── just.pass.cpp ├── posix │ └── ptz.pass.cpp ├── solar_hijri_test │ ├── parse.pass.cpp │ └── year_month_day.pass.cpp ├── testit └── tz_test │ ├── OffsetZone.h │ ├── OffsetZone.pass.cpp │ ├── README.md │ ├── tzdata2015e.txt.zip │ ├── tzdata2015f.txt.zip │ ├── tzdata2016c.txt.zip │ ├── tzdata2016d.txt.zip │ ├── tzdata2016e.txt.zip │ ├── tzdata2016f.txt.zip │ ├── tzdb_list.pass.cpp │ ├── validate.cpp │ ├── zone.pass.cpp │ ├── zoned_time.pass.cpp │ └── zoned_time_deduction.pass.cpp └── test_fail.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Normalize EOL for all files that Git considers text files. 2 | * text=auto eol=lf 3 | *zip -text -diff 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #ignore thumbnails created by windows 2 | Thumbs.db 3 | #Ignore files build by Visual Studio 4 | *.obj 5 | *.exe 6 | *.pdb 7 | *.user 8 | *.aps 9 | *.pch 10 | *.vspscc 11 | *_i.c 12 | *_p.c 13 | *.ncb 14 | *.suo 15 | *.tlb 16 | *.tlh 17 | *.bak 18 | *.cache 19 | *.ilk 20 | *.log 21 | [Bb]in 22 | [Dd]ebug*/ 23 | *.lib 24 | *.sbr 25 | obj/ 26 | [Rr]elease*/ 27 | _ReSharper*/ 28 | [Tt]est[Rr]esult* 29 | .idea/ 30 | *.opensdf 31 | ## Ignore Visual Studio temporary files, build results, and 32 | ## files generated by popular Visual Studio add-ons. 33 | # User-specific files 34 | *.suo 35 | *.user 36 | *.userosscache 37 | *.sln.docstates 38 | # User-specific folders 39 | *.sln.ide/ 40 | # Build results 41 | [Dd]ebug/ 42 | [Dd]ebugPublic/ 43 | [Rr]elease/ 44 | [Rr]eleases/ 45 | x64/ 46 | x86/ 47 | build/ 48 | bld/ 49 | [Bb]in/ 50 | [Oo]bj/ 51 | # Roslyn cache directories 52 | *.ide/ 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | #NUNIT 57 | *.VisualState.xml 58 | TestResult.xml 59 | # Build Results of an ATL Project 60 | [Dd]ebugPS/ 61 | [Rr]eleasePS/ 62 | dlldata.c 63 | *_i.c 64 | *_p.c 65 | *_i.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.pch 70 | *.pdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | # Chutzpah Test files 88 | _Chutzpah* 89 | # Visual C++ cache files 90 | ipch/ 91 | *.aps 92 | *.ncb 93 | *.opensdf 94 | *.sdf 95 | *.cachefile 96 | # Visual Studio profiler 97 | *.psess 98 | *.vsp 99 | *.vspx 100 | # TFS 2012 Local Workspace 101 | $tf/ 102 | # Guidance Automation Toolkit 103 | *.gpState 104 | # ReSharper is a .NET coding add-in 105 | _ReSharper*/ 106 | *.[Rr]e[Ss]harper 107 | *.DotSettings.user 108 | # JustCode is a .NET coding addin-in 109 | .JustCode 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | # DotCover is a Code Coverage Tool 113 | *.dotCover 114 | # NCrunch 115 | _NCrunch_* 116 | .*crunch*.local.xml 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | # Installshield output folder 123 | [Ee]xpress/ 124 | # DocProject is a documentation generator add-in 125 | DocProject/buildhelp/ 126 | DocProject/Help/*.HxT 127 | DocProject/Help/*.HxC 128 | DocProject/Help/*.hhc 129 | DocProject/Help/*.hhk 130 | DocProject/Help/*.hhp 131 | DocProject/Help/Html2 132 | DocProject/Help/html 133 | # Click-Once directory 134 | publish/ 135 | # Publish Web Output 136 | *.[Pp]ublish.xml 137 | *.azurePubxml 138 | # TODO: Comment the next line if you want to checkin your web deploy settings 139 | # but database connection strings (with potential passwords) will be unencrypted 140 | *.pubxml 141 | *.publishproj 142 | # NuGet Packages 143 | *.nupkg 144 | # The packages folder can be ignored because of Package Restore 145 | **/packages/* 146 | # except build/, which is used as an MSBuild target. 147 | !**/packages/build/ 148 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 149 | #!**/packages/repositories.config 150 | # Windows Azure Build Output 151 | csx/ 152 | *.build.csdef 153 | # Windows Store app package directory 154 | AppPackages/ 155 | # Others 156 | sql/ 157 | *.Cache 158 | ClientBin/ 159 | [Ss]tyle[Cc]op.* 160 | ~$* 161 | *~ 162 | *.dbmdl 163 | *.dbproj.schemaview 164 | *.pfx 165 | *.publishsettings 166 | node_modules/ 167 | bower_components/ 168 | # RIA/Silverlight projects 169 | Generated_Code/ 170 | # Backup & report files from converting an old project file 171 | # to a newer Visual Studio version. Backup files are not needed, 172 | # because we have git ;-) 173 | _UpgradeReport_Files/ 174 | Backup*/ 175 | UpgradeLog*.XML 176 | UpgradeLog*.htm 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | # Business Intelligence projects 181 | *.rdl.data 182 | *.bim.layout 183 | *.bim_*.settings 184 | # Microsoft Fakes 185 | FakesAssemblies/ 186 | *.suo 187 | *.vcxproj.filters 188 | *.npp 189 | CMakeFiles/* 190 | nbproject/* 191 | *.cd 192 | *.cd 193 | a.out 194 | cmake-build-debug/* 195 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | env: 4 | global: 5 | - CMAKE_EXTRA_CONF="-DCOMPILE_WITH_C_LOCALE=ON" 6 | - CTEST_OUTPUT_ON_FAILURE=1 7 | 8 | matrix: 9 | include: 10 | 11 | - name: "Ubuntu 16.04 LTS (Xenial Xerus) GCC 7" 12 | os: linux 13 | dist: xenial 14 | addons: 15 | apt: 16 | sources: 17 | - ubuntu-toolchain-r-test 18 | packages: 19 | - g++-7 20 | env: 21 | - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" 22 | 23 | - name: "Ubuntu 16.04 LTS (Xenial Xerus) GCC 8" 24 | os: linux 25 | dist: xenial 26 | addons: 27 | apt: 28 | sources: 29 | - ubuntu-toolchain-r-test 30 | packages: 31 | - g++-8 32 | env: 33 | - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" 34 | 35 | - name: "Ubuntu 16.04 LTS (Xenial Xerus) GCC 9" 36 | os: linux 37 | dist: xenial 38 | addons: 39 | apt: 40 | sources: 41 | - ubuntu-toolchain-r-test 42 | packages: 43 | - g++-9 44 | env: 45 | - MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" 46 | 47 | - name: "Ubuntu 18.04 LTS (Bionic Beaver) GCC 7" 48 | os: linux 49 | dist: bionic 50 | addons: 51 | apt: 52 | sources: 53 | - ubuntu-toolchain-r-test 54 | packages: 55 | - g++-7 56 | env: 57 | - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" 58 | 59 | - name: "Ubuntu 18.04 LTS (Bionic Beaver) GCC 8" 60 | os: linux 61 | dist: bionic 62 | addons: 63 | apt: 64 | sources: 65 | - ubuntu-toolchain-r-test 66 | packages: 67 | - g++-8 68 | env: 69 | - MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" 70 | 71 | - name: "Ubuntu 18.04 LTS (Bionic Beaver) Clang 6" 72 | os: linux 73 | dist: bionic 74 | addons: 75 | apt: 76 | sources: 77 | - llvm-toolchain-bionic-6.0 78 | packages: 79 | - clang-6.0 80 | env: 81 | - MATRIX_EVAL="CC=clang-6.0 && CXX=clang++-6.0" 82 | 83 | - name: "Ubuntu 18.04 LTS (Bionic Beaver) Clang 7" 84 | os: linux 85 | dist: bionic 86 | addons: 87 | apt: 88 | sources: 89 | - llvm-toolchain-bionic-7 90 | packages: 91 | - clang-7 92 | env: 93 | - MATRIX_EVAL="CC=clang-7 && CXX=clang++-7" 94 | 95 | - name: "Ubuntu 18.04 LTS (Bionic Beaver) Clang 8" 96 | os: linux 97 | dist: bionic 98 | addons: 99 | apt: 100 | sources: 101 | - llvm-toolchain-bionic-8 102 | packages: 103 | - clang-8 104 | env: 105 | - MATRIX_EVAL="CC=clang-8 && CXX=clang++-8" 106 | 107 | - &macos 108 | name: xcode10 109 | os: osx 110 | osx_image: xcode10.2 111 | env: 112 | - CMAKE_EXTRA_CONF="" 113 | addons: 114 | homebrew: 115 | packages: 116 | - bash 117 | - ninja 118 | 119 | - <<: *macos 120 | name: xcode9 121 | # xcode 9 only works if we tell it to use c++14 explicitly 122 | env: 123 | - CMAKE_EXTRA_CONF="-DCMAKE_CXX_STANDARD=14" 124 | osx_image: xcode9.4 125 | 126 | - <<: *macos 127 | osx_image: xcode11 128 | name: xcode11 129 | 130 | before_install: 131 | - eval "${MATRIX_EVAL}" 132 | - ci/install_cmake.sh 3.15.2 133 | - export OPENSSL_ROOT=$(brew --prefix openssl@1.1) 134 | - if [ "$(uname)" = "Darwin" ] ; then export PATH="$HOME/cmake/CMake.app/Contents/bin:${PATH}"; fi 135 | - if [ "$(uname)" = "Linux" ] ; then export PATH="$HOME/cmake/bin:${PATH}"; fi 136 | 137 | cache: 138 | directories: 139 | - $HOME/cmake 140 | 141 | script: 142 | - mkdir -p build 143 | - cd build 144 | - eval cmake -DENABLE_DATE_TESTING=ON -DBUILD_SHARED_LIBS=ON ${CMAKE_EXTRA_CONF} .. 145 | - cmake --build . --parallel 146 | - cmake --build . --parallel --target testit 147 | 148 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The source code in this project is released using the MIT License. There is no 2 | global license for the project because each file is licensed individually with 3 | different author names and/or dates. 4 | 5 | If you contribute to this project, please add your name to the license of each 6 | file you modify. If you have already contributed to this project and forgot to 7 | add your name to the license, please feel free to submit a new P/R to add your 8 | name to the license in each file you modified. 9 | 10 | For convenience, here is a copy of the MIT license found in each file except 11 | without author names or dates: 12 | 13 | The MIT License (MIT) 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy 16 | of this software and associated documentation files (the "Software"), to deal 17 | in the Software without restriction, including without limitation the rights 18 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | copies of the Software, and to permit persons to whom the Software is 20 | furnished to do so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Date 2 | 3 | [![Build Status](https://travis-ci.org/HowardHinnant/date.svg?branch=master)](https://travis-ci.org/HowardHinnant/date) 4 | [![Join the chat at https://gitter.im/HowardHinnant/date](https://badges.gitter.im/HowardHinnant/date.svg)](https://gitter.im/HowardHinnant/date?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | 6 | --- 7 | 8 | **[Try it out on wandbox!](https://wandbox.org/permlink/oyXjibyF680HHoyS)** 9 | 10 | ## Summary 11 | 12 | This is actually several separate C++11/C++14/C++17 libraries: 13 | 14 | 1. `"date.h"` is a header-only library which builds upon ``. It adds some new `duration` types, and new `time_point` types. It also adds "field" types such as `year_month_day` which is a struct `{year, month, day}`. And it provides convenient means to convert between the "field" types and the `time_point` types. 15 | 16 | * Documentation: http://howardhinnant.github.io/date/date.html 17 | * Video: https://www.youtube.com/watch?v=tzyGjOm8AKo 18 | * Slides: http://schd.ws/hosted_files/cppcon2015/43/hinnant_dates.pdf 19 | 20 | 1. `"tz.h"` / `"tz.cpp"` are a timezone library built on top of the `"date.h"` library. This timezone library is a complete parser of the IANA timezone database. It provides for an easy way to access all of the data in this database, using the types from `"date.h"` and ``. The IANA database also includes data on leap seconds, and this library provides utilities to compute with that information as well. 21 | 22 | * Documentation: http://howardhinnant.github.io/date/tz.html 23 | * Video: https://www.youtube.com/watch?v=Vwd3pduVGKY 24 | * Slides: http://schd.ws/hosted_files/cppcon2016/0f/Welcome%20To%20The%20Time%20Zone%20-%20Howard%20Hinnant%20-%20CppCon%202016.pdf 25 | 26 | 1. `"iso_week.h"` is a header-only library built on top of the `"date.h"` library which implements the ISO week date calendar. 27 | 28 | * Documentation: http://howardhinnant.github.io/date/iso_week.html 29 | 30 | 1. `"julian.h"` is a header-only library built on top of the `"date.h"` library which implements a proleptic Julian calendar which is fully interoperable with everything above. 31 | 32 | * Documentation: http://howardhinnant.github.io/date/julian.html 33 | 34 | 1. `"islamic.h"` is a header-only library built on top of the `"date.h"` library which implements a proleptic Islamic calendar which is fully interoperable with everything above. 35 | 36 | * Documentation: http://howardhinnant.github.io/date/islamic.html 37 | 38 | ## Standardization 39 | 40 | Slightly modified versions of `"date.h"` and `"tz.h"` were voted into the C++20 working draft at the Jacksonville FL meeting on 2018-03-17: 41 | 42 | * http://howardhinnant.github.io/date/d0355r7.html 43 | 44 | ## Build & Test 45 | 46 | The recommended way to use any of these libraries besides `"tz.h"` is to just include it. These are header-only libraries (except `"tz.h"`). 47 | 48 | To use `"tz.h"`, there is a single source file (`src/tz.cpp`) that needs to be compiled. Here are the recommended directions: https://howardhinnant.github.io/date/tz.html#Installation. 49 | 50 | One can run tests by cd'ing into the `test` subdirectory and running `testit`. There are known failures on all platforms except for macOS. And even on macOS if C++11 is used. If any of these failures present problems for you, there exist workarounds. 51 | 52 | Additionally there is _unsupported_ support for [vcpkg](https://github.com/Microsoft/vcpkg) and [CMake](https://cmake.org/). I don't personally use or maintain these systems as for me they cause more problems than they solve (for this small project). If you would like to contribute to these build systems please feel free to file a PR. 53 | 54 | You can download and install Date using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager: 55 | 56 | git clone https://github.com/Microsoft/vcpkg.git 57 | cd vcpkg 58 | ./bootstrap-vcpkg.sh 59 | ./vcpkg integrate install 60 | vcpkg install date 61 | 62 | The Date port in vcpkg is updated by Microsoft team members and community contributors. If the version falls behind, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. 63 | 64 | You can optionally build using [CMake](https://cmake.org/). Here is a guide of how to build and test using the CMake Makefile generator. 65 | 66 | ```bash 67 | mkdir build 68 | cd build 69 | cmake -DENABLE_DATE_TESTING=ON -DBUILD_TZ_LIB=ON ../ 70 | cmake --build . --target testit # Consider '-- -j4' for multithreading 71 | ``` 72 | ## Projects using this library 73 | 74 | * www.safe.com 75 | * www.webtoolkit.eu/wt 76 | * https://github.com/ViewTouch/viewtouch 77 | * https://routinghub.com 78 | * https://github.com/valhalla 79 | * https://github.com/siodb/siodb 80 | * https://github.com/KomodoPlatform/atomicDEX-Pro 81 | * https://github.com/Kotlin/kotlinx-datetime 82 | * https://github.com/royalbee/jewish_date 83 | * https://github.com/apache/arrow/ 84 | * https://lottopark.com 85 | 86 | If you would like your project (or product) on this list, just let me know. 87 | -------------------------------------------------------------------------------- /ci/install_cmake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | IFS=. read cm_maj cm_min cm_rel <<<"$1" 5 | : ${cm_rel:-0} 6 | CMAKE_ROOT=${2:-"${HOME}/cmake"} 7 | 8 | function cmake_version () 9 | { 10 | if [[ -d ${CMAKE_ROOT} ]] ; then 11 | local perms=$(test $(uname) = "Linux" && echo "/111" || echo "+111") 12 | local installed=$(find ${CMAKE_ROOT} -perm ${perms} -type f -name cmake) 13 | if [[ "${installed}" != "" ]] ; then 14 | echo "$(${installed} --version | head -1)" 15 | fi 16 | fi 17 | } 18 | 19 | installed=$(cmake_version) 20 | if [[ "${installed}" != "" && ${installed} =~ ${cm_maj}.${cm_min}.${cm_rel} ]] ; then 21 | echo "cmake already installed: ${installed}" 22 | exit 23 | fi 24 | 25 | pkgname="cmake-${cm_maj}.${cm_min}.${cm_rel}-$(uname)-x86_64.tar.gz" 26 | tmppkg="/tmp/cmake.tar.gz" 27 | wget --quiet https://cmake.org/files/v${cm_maj}.${cm_min}/${pkgname} -O ${tmppkg} 28 | mkdir -p ${CMAKE_ROOT} 29 | cd ${CMAKE_ROOT} 30 | tar --strip-components 1 -xf ${tmppkg} 31 | rm -f ${tmppkg} 32 | echo "installed: $(cmake_version)" 33 | 34 | 35 | -------------------------------------------------------------------------------- /cmake/dateConfig.cmake: -------------------------------------------------------------------------------- 1 | include( CMakeFindDependencyMacro ) 2 | include( "${CMAKE_CURRENT_LIST_DIR}/dateTargets.cmake" ) 3 | if( NOT MSVC AND TARGET date::date-tz ) 4 | find_dependency( Threads REQUIRED) 5 | get_target_property( _tzill date::date-tz INTERFACE_LINK_LIBRARIES ) 6 | if( _tzill AND "${_tzill}" MATCHES "libcurl" ) 7 | find_dependency( CURL ) 8 | endif( ) 9 | endif( ) 10 | 11 | 12 | -------------------------------------------------------------------------------- /compile_fail.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export TEST_BIN_NAME=$1 3 | #echo "Building ${TEST_BIN_NAME}" 4 | shift 1 5 | export BUILD_COMMAND=$@ 6 | #echo "Build command: ${BUILD_COMMAND}" 7 | eval ${BUILD_COMMAND} >/dev/null 2>/dev/null 8 | 9 | if [ $? -eq 0 ]; then 10 | echo -ne "#!/bin/bash\nexit 1;" > ${TEST_BIN_NAME} 11 | else 12 | echo -ne "#!/bin/bash\nexit 0;" > ${TEST_BIN_NAME} 13 | fi 14 | chmod u+x ${TEST_BIN_NAME} 15 | exit 0; 16 | 17 | -------------------------------------------------------------------------------- /include/date/chrono_io.h: -------------------------------------------------------------------------------- 1 | #ifndef CHRONO_IO_H 2 | #define CHRONO_IO_H 3 | 4 | // The MIT License (MIT) 5 | // 6 | // Copyright (c) 2016, 2017 Howard Hinnant 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | // 26 | // Our apologies. When the previous paragraph was written, lowercase had not yet 27 | // been invented (that would involve another several millennia of evolution). 28 | // We did not mean to shout. 29 | 30 | // This functionality has moved to "date.h" 31 | 32 | #include "date.h" 33 | 34 | #endif // CHRONO_IO_H 35 | -------------------------------------------------------------------------------- /include/date/ios.h: -------------------------------------------------------------------------------- 1 | // 2 | // ios.h 3 | // DateTimeLib 4 | // 5 | // The MIT License (MIT) 6 | // 7 | // Copyright (c) 2016 Alexander Kormanovsky 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), to deal 11 | // in the Software without restriction, including without limitation the rights 12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the Software is 14 | // furnished to do so, subject to the following conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be included in all 17 | // copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | // SOFTWARE. 26 | 27 | #ifndef ios_hpp 28 | #define ios_hpp 29 | 30 | #if __APPLE__ 31 | # include 32 | # if TARGET_OS_IPHONE 33 | # include 34 | 35 | namespace date 36 | { 37 | namespace iOSUtils 38 | { 39 | 40 | std::string get_tzdata_path(); 41 | std::string get_current_timezone(); 42 | 43 | } // namespace iOSUtils 44 | } // namespace date 45 | 46 | # endif // TARGET_OS_IPHONE 47 | #else // !__APPLE__ 48 | # define TARGET_OS_IPHONE 0 49 | #endif // !__APPLE__ 50 | #endif // ios_hpp 51 | -------------------------------------------------------------------------------- /test/clock_cast_test/constexpr.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2019 nanoric 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | #include 25 | #include 26 | 27 | struct const_clock { 28 | using duration = 29 | typename std::common_type::type; 31 | using rep = duration::rep; 32 | using period = duration::period; 33 | using time_point = std::chrono::time_point; 34 | 35 | static constexpr date::sys_days epoch { date::days { 1000 } }; 36 | 37 | template 38 | static std::chrono::time_point::type> 40 | CONSTCD11 to_sys(std::chrono::time_point const& tp) 41 | { 42 | return epoch + tp.time_since_epoch(); 43 | } 44 | 45 | template 46 | static std::chrono::time_point::type> 48 | CONSTCD11 from_sys( 49 | std::chrono::time_point const& 50 | tp) 51 | { 52 | using res = std::chrono::time_point::type>; 54 | return res(tp - epoch); 55 | } 56 | }; 57 | 58 | int main() 59 | { 60 | using namespace date; 61 | using namespace std::chrono; 62 | using const_days = time_point; 63 | 64 | CONSTCD14 sys_days sys { days { 1024 } }; 65 | static_assert(sys.time_since_epoch().count() == 1024, ""); 66 | 67 | CONSTCD14 const_days c {clock_cast(sys)}; 68 | CONSTCD14 sys_days sys2 {clock_cast(c)}; 69 | CONSTCD14 sys_days sys3 { clock_cast(const_days(days(48))) }; 70 | #if __cplusplus >= 201402L 71 | static_assert(c.time_since_epoch().count() == 24, ""); 72 | static_assert(sys2.time_since_epoch().count() == 1024, ""); 73 | static_assert(sys3.time_since_epoch().count() == 1048, ""); 74 | #endif 75 | } 76 | -------------------------------------------------------------------------------- /test/clock_cast_test/deprecated.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Tomasz Kamiński 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | #include 25 | 26 | int 27 | main() 28 | { 29 | using namespace date; 30 | 31 | // sys <-> utc 32 | { 33 | sys_days st(1997_y/dec/12); 34 | auto ut = utc_clock::from_sys(st); 35 | 36 | assert(to_utc_time(st) == ut); 37 | assert(to_sys_time(ut) == st); 38 | } 39 | 40 | // tai <-> utc 41 | { 42 | sys_days st(1997_y/dec/12); 43 | auto ut = utc_clock::from_sys(st); 44 | auto tt = tai_clock::from_utc(ut); 45 | 46 | assert(to_tai_time(ut) == tt); 47 | assert(to_utc_time(tt) == ut); 48 | } 49 | 50 | // tai <-> sys 51 | { 52 | sys_days st(1997_y/dec/12); 53 | auto ut = utc_clock::from_sys(st); 54 | auto tt = tai_clock::from_utc(ut); 55 | 56 | assert(to_tai_time(st) == tt); 57 | assert(to_sys_time(tt) == st); 58 | } 59 | 60 | // gps <-> utc 61 | { 62 | sys_days st(1997_y/dec/12); 63 | auto ut = utc_clock::from_sys(st); 64 | auto gt = gps_clock::from_utc(ut); 65 | 66 | assert(to_gps_time(ut) == gt); 67 | assert(to_utc_time(gt) == ut); 68 | } 69 | 70 | // gps <-> sys 71 | { 72 | sys_days st(1997_y/dec/12); 73 | auto ut = utc_clock::from_sys(st); 74 | auto gt = gps_clock::from_utc(ut); 75 | 76 | assert(to_gps_time(st) == gt); 77 | assert(to_sys_time(gt) == st); 78 | } 79 | 80 | // tai <-> gps 81 | { 82 | sys_days st(1997_y/dec/12); 83 | auto ut = utc_clock::from_sys(st); 84 | auto tt = tai_clock::from_utc(ut); 85 | auto gt = gps_clock::from_utc(ut); 86 | 87 | assert(to_gps_time(tt) == gt); 88 | assert(to_tai_time(gt) == tt); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /test/clock_cast_test/local_t.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2018 Tomasz Kamiński 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include 24 | #include "date/tz.h" 25 | 26 | int 27 | main() 28 | { 29 | using namespace date; 30 | using namespace std::chrono; 31 | using date::local_days, date::local_t, date::January, date::July, date::Sunday; 32 | 33 | // self 34 | { 35 | auto ls = local_days{1970_y/January/1_d}; 36 | assert(clock_cast(ls) == ls); 37 | } 38 | 39 | /// sys epoch 40 | { 41 | auto ls = local_days{1970_y/January/1_d}; 42 | auto st = clock_cast(ls); 43 | assert(clock_cast(st) == ls); 44 | assert(st.time_since_epoch() == seconds(0)); 45 | } 46 | 47 | /// sys 2000 case 48 | { 49 | auto ls = local_days{2000_y/January/1_d}; 50 | auto st = clock_cast(ls); 51 | assert(clock_cast(st) == ls); 52 | assert(st.time_since_epoch() == seconds(946684800)); 53 | } 54 | 55 | /// utc epoch 56 | { 57 | auto lu = local_days{1970_y/January/1_d}; 58 | auto ut = clock_cast(lu); 59 | assert(clock_cast(ut) == lu); 60 | assert(ut.time_since_epoch() == seconds(0)); 61 | } 62 | 63 | // utc leap second 64 | { 65 | auto lu = local_days{2015_y/July/1_d} - milliseconds(1); 66 | auto ut = clock_cast(lu) + milliseconds(50); //into leap second 67 | 68 | assert(clock_cast(ut) == lu); 69 | } 70 | 71 | /// utc paper example 72 | { 73 | auto lu = local_days{2000_y/January/1_d}; 74 | auto ut = clock_cast(lu); 75 | assert(clock_cast(ut) == lu); 76 | assert(ut.time_since_epoch() == seconds(946684822)); 77 | } 78 | 79 | /// tai epoch 80 | { 81 | auto lt = local_days{1958_y/January/1_d}; 82 | auto tt = clock_cast(lt); 83 | assert(clock_cast(tt) == lt); 84 | assert(tt.time_since_epoch() == seconds(0)); 85 | 86 | auto lu = local_days{1958_y/January/1_d} - seconds(10); 87 | auto ut = clock_cast(lu); 88 | assert(clock_cast(ut) == tt); 89 | } 90 | 91 | // tai paper example 92 | { 93 | auto lt = local_days{2000_y/January/1_d} + seconds(32); 94 | auto tt = clock_cast(lt); 95 | assert(clock_cast(tt) == lt); 96 | 97 | auto lu = local_days{2000_y/January/1_d}; 98 | auto ut = clock_cast(lu); 99 | assert(clock_cast(ut) == tt); 100 | } 101 | 102 | /// gps epoch 103 | { 104 | auto lg = local_days{1980_y/January/Sunday[1]}; 105 | auto gt = clock_cast(lg); 106 | assert(clock_cast(gt) == lg); 107 | assert(gt.time_since_epoch() == seconds(0)); 108 | 109 | auto lu = local_days{1980_y/January/Sunday[1]}; 110 | auto ut = clock_cast(lu); 111 | assert(clock_cast(ut) == gt); 112 | 113 | auto lt = local_days{1980_y/January/Sunday[1]} + seconds(19); 114 | auto tt = clock_cast(lt); 115 | assert(clock_cast(tt) == gt); 116 | } 117 | 118 | // gps 2000 example 119 | { 120 | auto lg = local_days{2000_y/January/1_d}; 121 | auto gt = clock_cast(lg); 122 | assert(clock_cast(gt) == lg); 123 | 124 | auto lu = local_days{2000_y/January/1_d} - seconds(13); 125 | auto ut = clock_cast(lu); 126 | assert(clock_cast(ut) == gt); 127 | 128 | auto lt = local_days{2000_y/January/1_d} + seconds(19); 129 | auto tt = clock_cast(lt); 130 | assert(clock_cast(tt) == gt); 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /test/clock_cast_test/normal_clocks.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Tomasz Kamiński 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | #include 25 | 26 | int 27 | main() 28 | { 29 | using namespace date; 30 | using sys_clock = std::chrono::system_clock; 31 | 32 | // self 33 | { 34 | sys_days st(1997_y/dec/12); 35 | auto ut = utc_clock::from_sys(st); 36 | auto tt = tai_clock::from_utc(ut); 37 | 38 | assert(clock_cast(st) == st); 39 | assert(clock_cast(ut) == ut); 40 | assert(clock_cast(tt) == tt); 41 | } 42 | 43 | // sys <-> utc 44 | { 45 | sys_days st(1997_y/dec/12); 46 | auto ut = utc_clock::from_sys(st); 47 | 48 | assert(clock_cast(st) == ut); 49 | assert(clock_cast(ut) == st); 50 | } 51 | 52 | // tai <-> utc 53 | { 54 | sys_days st(1997_y/dec/12); 55 | auto ut = utc_clock::from_sys(st); 56 | auto tt = tai_clock::from_utc(ut); 57 | 58 | assert(clock_cast(ut) == tt); 59 | assert(clock_cast(tt) == ut); 60 | } 61 | 62 | // tai <-> sys 63 | { 64 | sys_days st(1997_y/dec/12); 65 | auto ut = utc_clock::from_sys(st); 66 | auto tt = tai_clock::from_utc(ut); 67 | 68 | assert(clock_cast(st) == tt); 69 | assert(clock_cast(tt) == st); 70 | } 71 | 72 | // gps <-> utc 73 | { 74 | sys_days st(1997_y/dec/12); 75 | auto ut = utc_clock::from_sys(st); 76 | auto gt = gps_clock::from_utc(ut); 77 | 78 | assert(clock_cast(ut) == gt); 79 | assert(clock_cast(gt) == ut); 80 | } 81 | 82 | // gps <-> sys 83 | { 84 | sys_days st(1997_y/dec/12); 85 | auto ut = utc_clock::from_sys(st); 86 | auto gt = gps_clock::from_utc(ut); 87 | 88 | assert(clock_cast(st) == gt); 89 | assert(clock_cast(gt) == st); 90 | } 91 | 92 | // tai <-> gps 93 | { 94 | sys_days st(1997_y/dec/12); 95 | auto ut = utc_clock::from_sys(st); 96 | auto tt = tai_clock::from_utc(ut); 97 | auto gt = gps_clock::from_utc(ut); 98 | 99 | assert(clock_cast(tt) == gt); 100 | assert(clock_cast(gt) == tt); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /test/clock_cast_test/to_sys_return_int.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Tomasz Kamiński 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | 25 | struct bad_clock 26 | { 27 | using duration = std::chrono::system_clock::duration; 28 | using rep = duration::rep; 29 | using period = duration::period; 30 | using time_point = std::chrono::time_point; 31 | 32 | template 33 | static 34 | int 35 | to_sys(std::chrono::time_point const& tp) 36 | { 37 | return tp.time_since_epoch().count(); 38 | } 39 | }; 40 | 41 | int 42 | main() 43 | { 44 | using namespace date; 45 | using sys_clock = std::chrono::system_clock; 46 | 47 | auto bt = bad_clock::time_point(); 48 | clock_cast(bt); 49 | } 50 | -------------------------------------------------------------------------------- /test/clock_cast_test/to_sys_return_reference.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Tomasz Kamiński 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | 25 | struct bad_clock 26 | { 27 | using duration = std::chrono::system_clock::duration; 28 | using rep = duration::rep; 29 | using period = duration::period; 30 | using time_point = std::chrono::time_point; 31 | 32 | template 33 | static 34 | date::sys_time const& 35 | to_sys(std::chrono::time_point const& tp) 36 | { 37 | static date::sys_time val; 38 | val = date::sys_time(tp.time_since_epoch()); 39 | return val; 40 | } 41 | }; 42 | 43 | int 44 | main() 45 | { 46 | using namespace date; 47 | using sys_clock = std::chrono::system_clock; 48 | 49 | auto bt = bad_clock::time_point(); 50 | clock_cast(bt); 51 | } 52 | -------------------------------------------------------------------------------- /test/clock_cast_test/to_sys_return_utc_time.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017, 2018 Tomasz Kamiński 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | 25 | struct bad_clock 26 | { 27 | using duration = std::chrono::system_clock::duration; 28 | using rep = duration::rep; 29 | using period = duration::period; 30 | using time_point = std::chrono::time_point; 31 | 32 | template 33 | static 34 | date::utc_time 35 | to_sys(std::chrono::time_point const& tp) 36 | { 37 | return date::utc_time(tp.time_since_epoch()); 38 | } 39 | }; 40 | 41 | int 42 | main() 43 | { 44 | using namespace date; 45 | using sys_clock = std::chrono::system_clock; 46 | 47 | auto bt = bad_clock::time_point(); 48 | clock_cast(bt); 49 | } 50 | -------------------------------------------------------------------------------- /test/date_test/daypday.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // day + day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto x = 3_d + 7_d; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/daysmday.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // days - day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto x = days{3} - 7_d; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/daysmweekday.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // days - weekday not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto b = days{1} - sun; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/detail/static_pow10.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // template 24 | // struct static_pow10 25 | // { 26 | // static constepxr std::uint64_t value = ...; 27 | // }; 28 | 29 | #include "date.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | int 36 | main() 37 | { 38 | using namespace date::detail; 39 | static_assert(static_pow10<0>::value == 1, ""); 40 | static_assert(static_pow10<1>::value == 10, ""); 41 | static_assert(static_pow10<2>::value == 100, ""); 42 | static_assert(static_pow10<3>::value == 1000, ""); 43 | static_assert(static_pow10<4>::value == 10000, ""); 44 | static_assert(static_pow10<5>::value == 100000, ""); 45 | static_assert(static_pow10<6>::value == 1000000, ""); 46 | static_assert(static_pow10<7>::value == 10000000, ""); 47 | static_assert(static_pow10<8>::value == 100000000, ""); 48 | static_assert(static_pow10<9>::value == 1000000000, ""); 49 | static_assert(static_pow10<10>::value == 10000000000, ""); 50 | } 51 | -------------------------------------------------------------------------------- /test/date_test/detail/width.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // width::value is the number of fractional decimal digits in 1/n 24 | // width<0>::value and width<1>::value are defined to be 0 25 | // If 1/n takes more than 18 fractional decimal digits, 26 | // the result is truncated to 19. 27 | // Example: width<2>::value == 1 28 | // Example: width<3>::value == 19 29 | // Example: width<4>::value == 2 30 | // Example: width<10>::value == 1 31 | // Example: width<1000>::value == 3 32 | // template 33 | // 34 | // struct width 35 | // { 36 | // static constexpr unsigned value = ...; 37 | // }; 38 | 39 | #include "date.h" 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | int 46 | main() 47 | { 48 | using namespace date::detail; 49 | static_assert(width<0, 1>::value == 0, ""); 50 | static_assert(width<1, 1>::value == 0, ""); 51 | static_assert(width<1, 2>::value == 1, ""); 52 | static_assert(width<1, 3>::value == 19, ""); 53 | static_assert(width<1, 4>::value == 2, ""); 54 | static_assert(width<1, 5>::value == 1, ""); 55 | static_assert(width<1, 6>::value == 19, ""); 56 | static_assert(width<1, 7>::value == 19, ""); 57 | static_assert(width<1, 8>::value == 3, ""); 58 | static_assert(width<1, 9>::value == 19, ""); 59 | static_assert(width<1, 10>::value == 1, ""); 60 | static_assert(width<1, 100>::value == 2, ""); 61 | static_assert(width<1, 1000>::value == 3, ""); 62 | static_assert(width<1, 10000>::value == 4, ""); 63 | static_assert(width<756, 625>::value == 4, ""); 64 | } 65 | -------------------------------------------------------------------------------- /test/date_test/durations.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // durations 24 | // 25 | // using days = std::chrono::duration 26 | // , std::chrono::hours::period>>; 27 | // 28 | // using weeks = std::chrono::duration 29 | // , days::period>>; 30 | // 31 | // using years = std::chrono::duration 32 | // , days::period>>; 33 | // 34 | // using months = std::chrono::duration 35 | // >>; 36 | // 37 | // time_point 38 | // 39 | // using sys_days = std::chrono::time_point; 40 | 41 | #include "date.h" 42 | 43 | #include 44 | 45 | static_assert(date::days{1} == std::chrono::hours{24}, ""); 46 | 47 | static_assert(date::weeks{1} == date::days{7}, ""); 48 | 49 | static_assert(date::months{12} == date::years{1}, ""); 50 | static_assert(date::days{30} < date::months{1} && date::months{1} < date::days{31}, ""); 51 | static_assert(date::weeks{4} < date::months{1} && date::months{1} < date::weeks{5}, ""); 52 | 53 | static_assert(date::years{400} == date::days{146097}, ""); 54 | static_assert(date::days{365} < date::years{1} && date::years{1} < date::days{366}, ""); 55 | static_assert(date::weeks{52} < date::years{1} && date::years{1} < date::weeks{53}, ""); 56 | 57 | static_assert(std::is_same{}, ""); 58 | 59 | int 60 | main() 61 | { 62 | } 63 | -------------------------------------------------------------------------------- /test/date_test/format/century.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "date.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | int 30 | main() 31 | { 32 | using namespace date; 33 | using namespace std::chrono; 34 | std::ostringstream os; 35 | os << date::format("%C", sys_days{jun/1/20001}); 36 | assert(os.str() == "200"); 37 | 38 | os.str(""); 39 | os << date::format("%C", sys_days{jun/1/20000}); 40 | assert(os.str() == "200"); 41 | 42 | os.str(""); 43 | os << date::format("%C", sys_days{jun/1/19999}); 44 | assert(os.str() == "199"); 45 | 46 | os.str(""); 47 | os << date::format("%C", sys_days{jun/1/2001}); 48 | assert(os.str() == "20"); 49 | 50 | os.str(""); 51 | os << date::format("%C", sys_days{jun/1/2000}); 52 | assert(os.str() == "20"); 53 | 54 | os.str(""); 55 | os << date::format("%C", sys_days{jun/1/1999}); 56 | assert(os.str() == "19"); 57 | 58 | os.str(""); 59 | os << date::format("%C", sys_days{jun/1/101}); 60 | assert(os.str() == "01"); 61 | 62 | os.str(""); 63 | os << date::format("%C", sys_days{jun/1/100}); 64 | assert(os.str() == "01"); 65 | 66 | os.str(""); 67 | os << date::format("%C", sys_days{jun/1/99}); 68 | assert(os.str() == "00"); 69 | 70 | os.str(""); 71 | os << date::format("%C", sys_days{jun/1/1}); 72 | assert(os.str() == "00"); 73 | 74 | os.str(""); 75 | os << date::format("%C", sys_days{jun/1/0}); 76 | assert(os.str() == "00"); 77 | 78 | os.str(""); 79 | os << date::format("%C", sys_days{jun/1/-1}); 80 | assert(os.str() == "-01"); 81 | 82 | os.str(""); 83 | os << date::format("%C", sys_days{jun/1/-99}); 84 | assert(os.str() == "-01"); 85 | 86 | os.str(""); 87 | os << date::format("%C", sys_days{jun/1/-100}); 88 | assert(os.str() == "-01"); 89 | 90 | os.str(""); 91 | os << date::format("%C", sys_days{jun/1/-101}); 92 | assert(os.str() == "-02"); 93 | 94 | os.str(""); 95 | os << date::format("%C", sys_days{jun/1/-1999}); 96 | assert(os.str() == "-20"); 97 | 98 | os.str(""); 99 | os << date::format("%C", sys_days{jun/1/-2000}); 100 | assert(os.str() == "-20"); 101 | 102 | os.str(""); 103 | os << date::format("%C", sys_days{jun/1/-2001}); 104 | assert(os.str() == "-21"); 105 | 106 | os.str(""); 107 | os << date::format("%C", sys_days{jun/1/-19999}); 108 | assert(os.str() == "-200"); 109 | 110 | os.str(""); 111 | os << date::format("%C", sys_days{jun/1/-20000}); 112 | assert(os.str() == "-200"); 113 | 114 | os.str(""); 115 | os << date::format("%C", sys_days{jun/1/-20001}); 116 | assert(os.str() == "-201"); 117 | } 118 | -------------------------------------------------------------------------------- /test/date_test/format/misc.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "date.h" 24 | #include 25 | #include 26 | 27 | template 28 | void 29 | test(const std::string& in_fmt, const std::string& input, 30 | const std::string& out_fmt, const std::string& output) 31 | { 32 | std::istringstream in{input}; 33 | T t; 34 | in >> parse(in_fmt, t); 35 | assert(!in.fail()); 36 | auto s = date::format(out_fmt, t); 37 | assert(s == output); 38 | } 39 | 40 | int 41 | main() 42 | { 43 | using namespace date; 44 | test("%Y", "2017", "%Y", "2017"); 45 | test("%m", "3", "%m", "03"); 46 | test("%d", "25", "%d", "25"); 47 | test("%Y-%m", "2017-03", "%Y-%m", "2017-03"); 48 | test("%y%m", "1703", "%Y-%m", "2017-03"); 49 | test("%m/%d", "3/25", "%m/%d", "03/25"); 50 | test("%w", "3", "%w", "3"); 51 | } 52 | -------------------------------------------------------------------------------- /test/date_test/format/range.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "date.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | using fortnights = std::chrono::duration, 31 | date::weeks::period>>; 32 | 33 | using microfortnights = std::chrono::duration>; 36 | 37 | int 38 | main() 39 | { 40 | using namespace date; 41 | using namespace std::chrono; 42 | std::ostringstream os; 43 | using date::year, date::last; 44 | 45 | os << date::format("%F %T", sys_days{jan/1/year::min()}); 46 | assert(os.str() == "-32767-01-01 00:00:00"); 47 | os.str(""); 48 | os << date::format("%F %T", sys_days{dec/last/year::max()}); 49 | assert(os.str() == "32767-12-31 00:00:00"); 50 | os.str(""); 51 | os << date::format("%F %T", sys_days{dec/last/year::max()} + hours{23} + minutes{59} + 52 | seconds{59} + microseconds{999999}); 53 | assert(os.str() == "32767-12-31 23:59:59.999999"); 54 | os.str(""); 55 | 56 | os << date::format("%Y-%m-%d %H:%M:%S", sys_days{jan/1/year::min()}); 57 | assert(os.str() == "-32767-01-01 00:00:00"); 58 | os.str(""); 59 | os << date::format("%Y-%m-%d %H:%M:%S", sys_days{dec/last/year::max()}); 60 | assert(os.str() == "32767-12-31 00:00:00"); 61 | os.str(""); 62 | os << date::format("%Y-%m-%d %H:%M:%S", sys_days{dec/last/year::max()} + hours{23} + 63 | minutes{59} + seconds{59} + microseconds{999999}); 64 | assert(os.str() == "32767-12-31 23:59:59.999999"); 65 | os.str(""); 66 | 67 | os << date::format("%F %T", sys_days{jan/1/year::min()} + microfortnights{1}); 68 | assert(os.str() == "-32767-01-01 00:00:01.2096"); 69 | os.str(""); 70 | os << date::format("%F %T", sys_days{dec/last/year::max()} + microfortnights{1}); 71 | assert(os.str() == "32767-12-31 00:00:01.2096"); 72 | os.str(""); 73 | 74 | os << date::format("%F", jan/1/year::min()); 75 | assert(os.str() == "-32767-01-01"); 76 | os.str(""); 77 | os << date::format("%F", dec/last/year::max()); 78 | assert(os.str() == "32767-12-31"); 79 | os.str(""); 80 | } 81 | -------------------------------------------------------------------------------- /test/date_test/format/two_dight_year.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "date.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | int 30 | main() 31 | { 32 | using namespace date; 33 | using namespace std::chrono; 34 | std::ostringstream os; 35 | os << date::format("%y", sys_days{jun/1/20001}); 36 | assert(os.str() == "01"); 37 | 38 | os.str(""); 39 | os << date::format("%y", sys_days{jun/1/20000}); 40 | assert(os.str() == "00"); 41 | 42 | os.str(""); 43 | os << date::format("%y", sys_days{jun/1/19999}); 44 | assert(os.str() == "99"); 45 | 46 | os.str(""); 47 | os << date::format("%y", sys_days{jun/1/2001}); 48 | assert(os.str() == "01"); 49 | 50 | os.str(""); 51 | os << date::format("%y", sys_days{jun/1/2000}); 52 | assert(os.str() == "00"); 53 | 54 | os.str(""); 55 | os << date::format("%y", sys_days{jun/1/1999}); 56 | assert(os.str() == "99"); 57 | 58 | os.str(""); 59 | os << date::format("%y", sys_days{jun/1/101}); 60 | assert(os.str() == "01"); 61 | 62 | os.str(""); 63 | os << date::format("%y", sys_days{jun/1/100}); 64 | assert(os.str() == "00"); 65 | 66 | os.str(""); 67 | os << date::format("%y", sys_days{jun/1/99}); 68 | assert(os.str() == "99"); 69 | 70 | os.str(""); 71 | os << date::format("%y", sys_days{jun/1/1}); 72 | assert(os.str() == "01"); 73 | 74 | os.str(""); 75 | os << date::format("%y", sys_days{jun/1/0}); 76 | assert(os.str() == "00"); 77 | 78 | os.str(""); 79 | os << date::format("%y", sys_days{jun/1/-1}); 80 | assert(os.str() == "01"); 81 | 82 | os.str(""); 83 | os << date::format("%y", sys_days{jun/1/-99}); 84 | assert(os.str() == "99"); 85 | 86 | os.str(""); 87 | os << date::format("%y", sys_days{jun/1/-100}); 88 | assert(os.str() == "00"); 89 | 90 | os.str(""); 91 | os << date::format("%y", sys_days{jun/1/-101}); 92 | assert(os.str() == "01"); 93 | 94 | os.str(""); 95 | os << date::format("%y", sys_days{jun/1/-1999}); 96 | assert(os.str() == "99"); 97 | 98 | os.str(""); 99 | os << date::format("%y", sys_days{jun/1/-2000}); 100 | assert(os.str() == "00"); 101 | 102 | os.str(""); 103 | os << date::format("%y", sys_days{jun/1/-2001}); 104 | assert(os.str() == "01"); 105 | 106 | os.str(""); 107 | os << date::format("%y", sys_days{jun/1/-19999}); 108 | assert(os.str() == "99"); 109 | 110 | os.str(""); 111 | os << date::format("%y", sys_days{jun/1/-20000}); 112 | assert(os.str() == "00"); 113 | 114 | os.str(""); 115 | os << date::format("%y", sys_days{jun/1/-20001}); 116 | assert(os.str() == "01"); 117 | 118 | os.str(""); 119 | os << date::format("%y", sys_days{jun/1/date::year::min()}); 120 | assert(os.str() == "67"); 121 | } 122 | -------------------------------------------------------------------------------- /test/date_test/last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr struct last_spec {} last{}; 24 | 25 | #include "date.h" 26 | 27 | #include 28 | 29 | static_assert(std::is_same{}, ""); 30 | 31 | int 32 | main() 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /test/date_test/make_time.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // template ::value>::type> 26 | // constexpr 27 | // time_of_day> 28 | // make_time(std::chrono::duration d) noexcept; 29 | 30 | #include "date.h" 31 | 32 | #include 33 | #include 34 | 35 | int 36 | main() 37 | { 38 | using namespace date; 39 | using namespace std; 40 | using namespace std::chrono; 41 | 42 | { 43 | static_assert(is_same>{}, ""); 45 | auto tod = make_time(nanoseconds{18429000000022}); 46 | assert(tod.hours() == hours{5}); 47 | assert(tod.minutes() == minutes{7}); 48 | assert(tod.seconds() == seconds{9}); 49 | assert(tod.subseconds() == nanoseconds{22}); 50 | } 51 | { 52 | static_assert(is_same>{}, ""); 54 | auto tod = make_time(microseconds{18429000022}); 55 | assert(tod.hours() == hours{5}); 56 | assert(tod.minutes() == minutes{7}); 57 | assert(tod.seconds() == seconds{9}); 58 | assert(tod.subseconds() == microseconds{22}); 59 | } 60 | { 61 | static_assert(is_same>{}, ""); 63 | auto tod = make_time(seconds{18429}); 64 | assert(tod.hours() == hours{5}); 65 | assert(tod.minutes() == minutes{7}); 66 | assert(tod.seconds() == seconds{9}); 67 | } 68 | { 69 | static_assert(is_same>{}, ""); 71 | auto tod = make_time(minutes{307}); 72 | assert(tod.hours() == hours{5}); 73 | assert(tod.minutes() == minutes{7}); 74 | } 75 | { 76 | static_assert(is_same>{}, ""); 78 | auto tod = make_time(hours{5}); 79 | assert(tod.hours() == hours{5}); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /test/date_test/month_day.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class month_day 24 | // { 25 | // public: 26 | // constexpr month_day(const date::month& m, const date::day& d) noexcept; 27 | // 28 | // constexpr date::month month() const noexcept; 29 | // constexpr date::day day() const noexcept; 30 | // 31 | // constexpr bool ok() const noexcept; 32 | // }; 33 | 34 | // constexpr bool operator==(const month_day& x, const month_day& y) noexcept; 35 | // constexpr bool operator!=(const month_day& x, const month_day& y) noexcept; 36 | // constexpr bool operator< (const month_day& x, const month_day& y) noexcept; 37 | // constexpr bool operator> (const month_day& x, const month_day& y) noexcept; 38 | // constexpr bool operator<=(const month_day& x, const month_day& y) noexcept; 39 | // constexpr bool operator>=(const month_day& x, const month_day& y) noexcept; 40 | 41 | // std::ostream& operator<<(std::ostream& os, const month_day& md); 42 | 43 | #include "date.h" 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | static_assert( std::is_trivially_destructible{}, ""); 50 | static_assert( std::is_default_constructible{}, ""); 51 | static_assert( std::is_trivially_copy_constructible{}, ""); 52 | static_assert( std::is_trivially_copy_assignable{}, ""); 53 | static_assert( std::is_trivially_move_constructible{}, ""); 54 | static_assert( std::is_trivially_move_assignable{}, ""); 55 | 56 | static_assert(std::is_nothrow_constructible{}, ""); 58 | 59 | int 60 | main() 61 | { 62 | using namespace date; 63 | 64 | constexpr month_day md1 = {feb, day{28}}; 65 | constexpr month_day md2 = {mar, day{1}}; 66 | #if __cplusplus >= 201402 67 | static_assert(md1.ok(), ""); 68 | static_assert(md2.ok(), ""); 69 | static_assert(!month_day{feb, day{32}}.ok(), ""); 70 | static_assert(!month_day{month{0}, day{1}}.ok(), ""); 71 | #endif 72 | static_assert(md1.month() == feb, ""); 73 | static_assert(md1.day() == day{28}, ""); 74 | static_assert(md2.month() == mar, ""); 75 | static_assert(md2.day() == day{1}, ""); 76 | static_assert(md1 == md1, ""); 77 | static_assert(md1 != md2, ""); 78 | static_assert(md1 < md2, ""); 79 | std::ostringstream os; 80 | os << md1; 81 | assert(os.str() == "Feb/28"); 82 | } 83 | -------------------------------------------------------------------------------- /test/date_test/month_day_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class month_day_last 24 | // { 25 | // public: 26 | // constexpr explicit month_day_last(const date::month& m) noexcept; 27 | // 28 | // constexpr date::month month() const noexcept; 29 | // constexpr bool ok() const noexcept; 30 | // }; 31 | 32 | // constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; 33 | // constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; 34 | // constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; 35 | // constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; 36 | // constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; 37 | // constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; 38 | 39 | // std::ostream& operator<<(std::ostream& os, const month_day_last& mdl); 40 | 41 | #include "date.h" 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | static_assert( std::is_trivially_destructible{}, ""); 48 | static_assert(!std::is_default_constructible{}, ""); 49 | static_assert( std::is_trivially_copy_constructible{}, ""); 50 | static_assert( std::is_trivially_copy_assignable{}, ""); 51 | static_assert( std::is_trivially_move_constructible{}, ""); 52 | static_assert( std::is_trivially_move_assignable{}, ""); 53 | 54 | static_assert(std::is_nothrow_constructible{}, ""); 55 | static_assert(!std::is_convertible{}, ""); 56 | 57 | int 58 | main() 59 | { 60 | using namespace date; 61 | 62 | constexpr month_day_last mdl1{feb}; 63 | constexpr month_day_last mdl2{mar}; 64 | static_assert(mdl1.ok(), ""); 65 | static_assert(mdl2.ok(), ""); 66 | static_assert(!month_day_last{month{0}}.ok(), ""); 67 | static_assert(mdl1.month() == feb, ""); 68 | static_assert(mdl2.month() == mar, ""); 69 | static_assert(mdl1 == mdl1, ""); 70 | static_assert(mdl1 != mdl2, ""); 71 | static_assert(mdl1 < mdl2, ""); 72 | std::ostringstream os; 73 | os << mdl1; 74 | assert(os.str() == "Feb/last"); 75 | } 76 | -------------------------------------------------------------------------------- /test/date_test/month_weekday.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class month_weekday 24 | // { 25 | // public: 26 | // constexpr month_weekday(const date::month& m, 27 | // const date::weekday_indexed& wdi) noexcept; 28 | // 29 | // constexpr date::month month() const noexcept; 30 | // constexpr date::weekday_indexed weekday_indexed() const noexcept; 31 | // 32 | // constexpr bool ok() const noexcept; 33 | // }; 34 | 35 | // constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; 36 | // constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; 37 | 38 | // std::ostream& operator<<(std::ostream& os, const month_weekday& mwd); 39 | 40 | #include "date.h" 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | static_assert( std::is_trivially_destructible{}, ""); 47 | static_assert(!std::is_default_constructible{}, ""); 48 | static_assert( std::is_trivially_copy_constructible{}, ""); 49 | static_assert( std::is_trivially_copy_assignable{}, ""); 50 | static_assert( std::is_trivially_move_constructible{}, ""); 51 | static_assert( std::is_trivially_move_assignable{}, ""); 52 | 53 | static_assert(std::is_nothrow_constructible{}, ""); 56 | 57 | int 58 | main() 59 | { 60 | using namespace date; 61 | 62 | constexpr month_weekday mwd1 = {feb, sat[4]}; 63 | constexpr month_weekday mwd2 = {mar, mon[1]}; 64 | static_assert(mwd1.ok(), ""); 65 | static_assert(mwd2.ok(), ""); 66 | static_assert(!month_weekday{feb, sat[0]}.ok(), ""); 67 | static_assert(!month_weekday{month{0}, sun[1]}.ok(), ""); 68 | static_assert(mwd1.month() == feb, ""); 69 | static_assert(mwd1.weekday_indexed() == sat[4], ""); 70 | static_assert(mwd2.month() == mar, ""); 71 | static_assert(mwd2.weekday_indexed() == mon[1], ""); 72 | static_assert(mwd1 == mwd1, ""); 73 | static_assert(mwd1 != mwd2, ""); 74 | std::ostringstream os; 75 | os << mwd1; 76 | assert(os.str() == "Feb/Sat[4]"); 77 | } 78 | -------------------------------------------------------------------------------- /test/date_test/month_weekday_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class month_weekday_last 24 | // { 25 | // public: 26 | // constexpr month_weekday_last(const date::month& m, 27 | // const date::weekday_last& wdl) noexcept; 28 | // 29 | // constexpr date::month month() const noexcept; 30 | // constexpr date::weekday_last weekday_last() const noexcept; 31 | // 32 | // constexpr bool ok() const noexcept; 33 | // }; 34 | 35 | // constexpr 36 | // bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; 37 | // constexpr 38 | // bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; 39 | 40 | // std::ostream& operator<<(std::ostream& os, const month_weekday_last& mwdl); 41 | 42 | #include "date.h" 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | static_assert( std::is_trivially_destructible{}, ""); 49 | static_assert(!std::is_default_constructible{}, ""); 50 | static_assert( std::is_trivially_copy_constructible{}, ""); 51 | static_assert( std::is_trivially_copy_assignable{}, ""); 52 | static_assert( std::is_trivially_move_constructible{}, ""); 53 | static_assert( std::is_trivially_move_assignable{}, ""); 54 | 55 | static_assert(std::is_nothrow_constructible{}, ""); 57 | 58 | int 59 | main() 60 | { 61 | using namespace date; 62 | 63 | constexpr month_weekday_last mwdl1 = {feb, sat[last]}; 64 | constexpr month_weekday_last mwdl2 = {mar, mon[last]}; 65 | static_assert(mwdl1.ok(), ""); 66 | static_assert(mwdl2.ok(), ""); 67 | static_assert(!month_weekday_last{month{0}, sun[last]}.ok(), ""); 68 | static_assert(mwdl1.month() == feb, ""); 69 | static_assert(mwdl1.weekday_last() == sat[last], ""); 70 | static_assert(mwdl2.month() == mar, ""); 71 | static_assert(mwdl2.weekday_last() == mon[last], ""); 72 | static_assert(mwdl1 == mwdl1, ""); 73 | static_assert(mwdl1 != mwdl2, ""); 74 | std::ostringstream os; 75 | os << mwdl1; 76 | assert(os.str() == "Feb/Sat[last]"); 77 | } 78 | -------------------------------------------------------------------------------- /test/date_test/month_weekday_last_less.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // month_weekday_last < month_weekday_last not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | month_weekday_last mwdl1 = {feb, sat[last]}; 32 | month_weekday_last mwdl2 = {mar, mon[last]}; 33 | auto b = mwdl1 < mwdl2; 34 | } 35 | -------------------------------------------------------------------------------- /test/date_test/month_weekday_less.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // month_weekday < month_weekday not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | month_weekday mwd1 = {feb, sat[4]}; 32 | month_weekday mwd2 = {mar, mon[1]}; 33 | auto b = mwd1 < mwd2; 34 | } 35 | -------------------------------------------------------------------------------- /test/date_test/monthpmonth.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // month + month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto x = mar + jul; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/months_m_year_month.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // months - year_month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = months{1} - year_month{2015_y, jan}; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/months_m_year_month_day.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // months - year_month_day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = jan - year_month_day{2015_y, aug, 9_d}; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/monthsmmonth.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // months - month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto x = months{3} - jul; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/op_div_day_day.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // day / day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = 14_d/14_d; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_int_month.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // int / month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = 8/aug; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_int_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // int / year not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = 8/2015_y; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_last_last.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // last / last not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = last/last; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_day.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr month_day operator/(const month& m, const day& d) noexcept; 24 | // constexpr month_day operator/(const month& m, int d) noexcept; 25 | // constexpr month_day operator/(int m, const day& d) noexcept; 26 | // constexpr month_day operator/(const day& d, const month& m) noexcept; 27 | // constexpr month_day operator/(const day& d, int m) noexcept; 28 | 29 | #include "date.h" 30 | 31 | int 32 | main() 33 | { 34 | using namespace date; 35 | 36 | static_assert( aug/14_d == month_day{month{8}, day{14}}, ""); 37 | static_assert( aug/14 == month_day{month{8}, day{14}}, ""); 38 | static_assert( 8/14_d == month_day{month{8}, day{14}}, ""); 39 | static_assert(14_d/aug == month_day{month{8}, day{14}}, ""); 40 | static_assert(14_d/8 == month_day{month{8}, day{14}}, ""); 41 | } 42 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_day_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr month_day_last operator/(const month& m, last_spec) noexcept; 24 | // constexpr month_day_last operator/(int m, last_spec) noexcept; 25 | // constexpr month_day_last operator/(last_spec, const month& m) noexcept; 26 | // constexpr month_day_last operator/(last_spec, int m) noexcept; 27 | 28 | #include "date.h" 29 | 30 | int 31 | main() 32 | { 33 | using namespace date; 34 | 35 | static_assert( aug/last == month_day_last{month{8}}, ""); 36 | static_assert( 8/last == month_day_last{month{8}}, ""); 37 | static_assert(last/aug == month_day_last{month{8}}, ""); 38 | static_assert(last/8 == month_day_last{month{8}}, ""); 39 | } 40 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_day_month_day.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // month_day / month_day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = (aug/14_d)/(aug/14_d); 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_month.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // month / month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = aug/aug; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_weekday.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr month_weekday operator/(const month& m, const weekday_indexed& wdi) noexcept; 24 | // constexpr month_weekday operator/(int m, const weekday_indexed& wdi) noexcept; 25 | // constexpr month_weekday operator/(const weekday_indexed& wdi, const month& m) noexcept; 26 | // constexpr month_weekday operator/(const weekday_indexed& wdi, int m) noexcept; 27 | 28 | #include "date.h" 29 | 30 | int 31 | main() 32 | { 33 | using namespace date; 34 | 35 | static_assert( aug/fri[2] == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 36 | static_assert( 8/fri[2] == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 37 | static_assert(fri[2]/aug == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 38 | static_assert(fri[2]/8 == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 39 | } 40 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_weekday_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr month_weekday_last operator/(const month& m, const weekday_last& wdl) noexcept; 24 | // constexpr month_weekday_last operator/(int m, const weekday_last& wdl) noexcept; 25 | // constexpr month_weekday_last operator/(const weekday_last& wdl, const month& m) noexcept; 26 | // constexpr month_weekday_last operator/(const weekday_last& wdl, int m) noexcept; 27 | 28 | #include "date.h" 29 | 30 | int 31 | main() 32 | { 33 | using namespace date; 34 | 35 | static_assert( aug/fri[last] == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, ""); 36 | static_assert( 8/fri[last] == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, ""); 37 | static_assert(fri[last]/aug == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, ""); 38 | static_assert(fri[last]/8 == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, ""); 39 | } 40 | -------------------------------------------------------------------------------- /test/date_test/op_div_month_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // month / year not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = aug/2015_y; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_weekday_indexed_weekday_indexed.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weekday_indexed / weekday_indexed not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = fri[2]/fri[2]; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_weekday_last_weekday_last.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weekday_last / weekday_last not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = fri[last]/fri[last]; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_month.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr year_month operator/(const year& y, const month& m) noexcept; 24 | // constexpr year_month operator/(const year& y, int m) noexcept; 25 | 26 | #include "date.h" 27 | 28 | int 29 | main() 30 | { 31 | using namespace date; 32 | 33 | static_assert(2015_y/aug == year_month{year{2015}, aug}, ""); 34 | static_assert(2015_y/8 == year_month{year{2015}, aug}, ""); 35 | } 36 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_month_day.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr year_month_day operator/(const year_month& ym, const day& d) noexcept; 24 | // constexpr year_month_day operator/(const year_month& ym, int d) noexcept; 25 | // constexpr year_month_day operator/(const year& y, const month_day& md) noexcept; 26 | // constexpr year_month_day operator/(int y, const month_day& md) noexcept; 27 | // constexpr year_month_day operator/(const month_day& md, const year& y) noexcept; 28 | // constexpr year_month_day operator/(const month_day& md, int y) noexcept; 29 | 30 | #include "date.h" 31 | 32 | int 33 | main() 34 | { 35 | using namespace date; 36 | 37 | static_assert( 2015_y/aug/14_d == year_month_day{year{2015}, month{8}, day{14}}, ""); 38 | static_assert( 2015_y/aug/14 == year_month_day{year{2015}, month{8}, day{14}}, ""); 39 | static_assert( 2015_y/(aug/14_d) == year_month_day{year{2015}, month{8}, day{14}}, ""); 40 | static_assert( 2015/(aug/14_d) == year_month_day{year{2015}, month{8}, day{14}}, ""); 41 | static_assert(aug/14_d/2015_y == year_month_day{year{2015}, month{8}, day{14}}, ""); 42 | static_assert(aug/14_d/2015 == year_month_day{year{2015}, month{8}, day{14}}, ""); 43 | } 44 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_month_day_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr year_month_day_last operator/(const year_month& ym, last_spec) noexcept; 24 | // constexpr year_month_day_last operator/(const year& y, const month_day_last& mdl) noexcept; 25 | // constexpr year_month_day_last operator/(int y, const month_day_last& mdl) noexcept; 26 | // constexpr year_month_day_last operator/(const month_day_last& mdl, const year& y) noexcept; 27 | // constexpr year_month_day_last operator/(const month_day_last& mdl, int y) noexcept; 28 | 29 | #include "date.h" 30 | 31 | int 32 | main() 33 | { 34 | using namespace date; 35 | 36 | static_assert(2015_y/aug/last == year_month_day_last{year{2015}, month_day_last{month{8}}}, ""); 37 | static_assert( 2015_y/(aug/last) == year_month_day_last{year{2015}, month_day_last{month{8}}}, ""); 38 | static_assert( 2015/(aug/last) == year_month_day_last{year{2015}, month_day_last{month{8}}}, ""); 39 | static_assert( aug/last/2015_y == year_month_day_last{year{2015}, month_day_last{month{8}}}, ""); 40 | static_assert( aug/last/2015 == year_month_day_last{year{2015}, month_day_last{month{8}}}, ""); 41 | } 42 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_month_weekday.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr year_month_weekday operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; 24 | // constexpr year_month_weekday operator/(const year& y, const month_weekday& mwd) noexcept; 25 | // constexpr year_month_weekday operator/(int y, const month_weekday& mwd) noexcept; 26 | // constexpr year_month_weekday operator/(const month_weekday& mwd, const year& y) noexcept; 27 | // constexpr year_month_weekday operator/(const month_weekday& mwd, int y) noexcept; 28 | 29 | #include "date.h" 30 | 31 | int 32 | main() 33 | { 34 | using namespace date; 35 | 36 | static_assert(2015_y/aug/fri[2] == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 37 | static_assert( 2015_y/(aug/fri[2]) == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 38 | static_assert( 2015/(aug/fri[2]) == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 39 | static_assert(aug/fri[2]/2015_y == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 40 | static_assert(aug/fri[2]/2015 == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, ""); 41 | } 42 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_month_weekday_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr year_month_weekday_last operator/(const year_month& ym, const weekday_last& wdl) noexcept; 24 | // constexpr year_month_weekday_last operator/(const year& y, const month_weekday_last& mwdl) noexcept; 25 | // constexpr year_month_weekday_last operator/(int y, const month_weekday_last& mwdl) noexcept; 26 | // constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, const year& y) noexcept; 27 | // constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, int y) noexcept; 28 | 29 | #include "date.h" 30 | 31 | int 32 | main() 33 | { 34 | using namespace date; 35 | 36 | static_assert( 2015_y/aug/fri[last] == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, ""); 37 | static_assert( 2015_y/(aug/fri[last]) == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, ""); 38 | static_assert( 2015/(aug/fri[last]) == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, ""); 39 | static_assert(aug/fri[last]/2015_y == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, ""); 40 | static_assert(aug/fri[last]/2015 == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, ""); 41 | } 42 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_month_year_month.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year_month / year_month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = (2015_y/aug)/(2015_y/aug); 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/op_div_year_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year / year not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = 2015_y/2015_y; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/sizeof.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // This test is meant to maintain a record of the sizeof each type. 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | static_assert(sizeof(days) == 4, ""); 33 | static_assert(sizeof(weeks) == 4, ""); 34 | static_assert(sizeof(months) == 4, ""); 35 | static_assert(sizeof(years) == 4, ""); 36 | 37 | static_assert(sizeof(sys_days) == 4, ""); 38 | 39 | static_assert(sizeof(last_spec) == 1, ""); 40 | 41 | static_assert(sizeof(day) == 1, ""); 42 | static_assert(sizeof(month) == 1, ""); 43 | static_assert(sizeof(year) == 2, ""); 44 | 45 | static_assert(sizeof(weekday) == 1, ""); 46 | static_assert(sizeof(weekday_indexed) == 1, ""); 47 | static_assert(sizeof(weekday_last) == 1, ""); 48 | 49 | static_assert(sizeof(month_day) == 2, ""); 50 | static_assert(sizeof(month_day_last) == 1, ""); 51 | static_assert(sizeof(month_weekday) == 2, ""); 52 | static_assert(sizeof(month_weekday_last) == 2, ""); 53 | 54 | static_assert(sizeof(year_month) == 4, ""); 55 | 56 | static_assert(sizeof(year_month_day) == 4, ""); 57 | static_assert(sizeof(year_month_day_last) == 4, ""); 58 | static_assert(sizeof(year_month_weekday) == 4, ""); 59 | static_assert(sizeof(year_month_weekday_last) == 4, ""); 60 | 61 | // sizeof time_of_day varies 62 | } 63 | -------------------------------------------------------------------------------- /test/date_test/time_of_day_hours.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // enum {am = 1, pm}; 24 | 25 | // class time_of_day 26 | // { 27 | // public: 28 | // using precision = std::chrono::hours; 29 | // 30 | // constexpr explicit time_of_day(std::chrono::hours since_midnight) noexcept; 31 | // constexpr time_of_day(std::chrono::hours h, unsigned md) noexcept; 32 | // 33 | // constexpr std::chrono::hours hours() const noexcept; 34 | // constexpr unsigned mode() const noexcept; 35 | // 36 | // constexpr explicit operator precision() const noexcept; 37 | // constexpr precision to_duration() const noexcept; 38 | // 39 | // void make24() noexcept; 40 | // void make12() noexcept; 41 | // }; 42 | 43 | // std::ostream& operator<<(std::ostream& os, const time_of_day& t); 44 | 45 | #include "date.h" 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | int 52 | main() 53 | { 54 | using namespace date; 55 | using namespace std; 56 | using namespace std::chrono; 57 | 58 | using tod = time_of_day; 59 | 60 | static_assert(is_same{}, ""); 61 | 62 | static_assert( is_trivially_destructible{}, ""); 63 | static_assert( is_default_constructible{}, ""); 64 | static_assert( is_trivially_copy_constructible{}, ""); 65 | static_assert( is_trivially_copy_assignable{}, ""); 66 | static_assert( is_trivially_move_constructible{}, ""); 67 | static_assert( is_trivially_move_assignable{}, ""); 68 | 69 | static_assert(is_nothrow_constructible{}, ""); 70 | static_assert(!is_convertible{}, ""); 71 | 72 | static_assert(is_nothrow_constructible{}, ""); 73 | static_assert(!is_convertible{}, ""); 74 | 75 | constexpr tod t1 = tod{hours{13}}; 76 | static_assert(t1.hours() == hours{13}, ""); 77 | #if __cplusplus >= 201402 78 | static_assert(static_cast(t1) == hours{13}, ""); 79 | static_assert(t1.to_duration() == hours{13}, ""); 80 | #endif 81 | 82 | const auto t2 = t1; 83 | assert(t2.hours() == t1.hours()); 84 | assert(t2.to_duration() == t1.to_duration()); 85 | ostringstream os; 86 | os << t2; 87 | assert(os.str() == "13:00:00"); 88 | auto h = date::make12(t2.hours()); 89 | os.str(""); 90 | assert(h == hours{1}); 91 | assert(t2.to_duration() == t1.to_duration()); 92 | assert(!date::is_am(t2.hours())); 93 | assert(date::is_pm(t2.hours())); 94 | } 95 | -------------------------------------------------------------------------------- /test/date_test/time_of_day_microfortnights.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // enum {am = 1, pm}; 24 | 25 | // template 26 | // class time_of_day> 27 | // { 28 | // public: 29 | // using precision = std::chrono::std::chrono::duration; 30 | // 31 | // constexpr explicit time_of_day(precision since_midnight) noexcept; 32 | // constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, 33 | // std::chrono::seconds s, precision sub_s, 34 | // unsigned md) noexcept; 35 | // 36 | // constexpr std::chrono::hours hours() const noexcept; 37 | // constexpr std::chrono::minutes minutes() const noexcept; 38 | // constexpr std::chrono::seconds seconds() const noexcept; 39 | // constexpr precision subseconds() const noexcept; 40 | // constexpr unsigned mode() const noexcept; 41 | // 42 | // constexpr explicit operator precision() const noexcept; 43 | // constexpr precision to_duration() const noexcept; 44 | // 45 | // void make24() noexcept; 46 | // void make12() noexcept; 47 | // }; 48 | 49 | // template 50 | // std::ostream& 51 | // operator<<(std::ostream& os, const time_of_day>& t); 52 | 53 | #include "date.h" 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | using fortnights = std::chrono::duration, 61 | date::weeks::period>>; 62 | 63 | using microfortnights = std::chrono::duration>; 66 | 67 | int 68 | main() 69 | { 70 | using namespace date; 71 | using namespace std; 72 | using namespace std::chrono; 73 | 74 | using tod = time_of_day::type>; 75 | 76 | static_assert(is_same>{}, ""); 77 | 78 | static_assert( is_trivially_destructible{}, ""); 79 | static_assert( is_default_constructible{}, ""); 80 | static_assert( is_trivially_copy_constructible{}, ""); 81 | static_assert( is_trivially_copy_assignable{}, ""); 82 | static_assert( is_trivially_move_constructible{}, ""); 83 | static_assert( is_trivially_move_assignable{}, ""); 84 | 85 | static_assert(is_constructible{}, ""); 86 | static_assert(!is_convertible{}, ""); 87 | 88 | static_assert(is_nothrow_constructible{}, ""); 89 | static_assert(!is_convertible{}, ""); 90 | 91 | constexpr tod t1 = tod{hours{13} + minutes{7} + microfortnights{5}}; 92 | static_assert(t1.hours() == hours{13}, ""); 93 | static_assert(t1.minutes() == minutes{7}, ""); 94 | static_assert(t1.seconds() == seconds{6}, ""); 95 | static_assert(t1.subseconds() == tod::precision{480}, ""); 96 | #if __cplusplus >= 201402 97 | static_assert(static_cast(t1) == hours{13} + minutes{7} 98 | + microfortnights{5}, ""); 99 | static_assert(t1.to_duration() == hours{13} + minutes{7} + microfortnights{5}, ""); 100 | #endif 101 | 102 | auto t2 = t1; 103 | assert(t2.hours() == t1.hours()); 104 | assert(t2.minutes() == t1.minutes()); 105 | assert(t2.seconds() == t1.seconds()); 106 | assert(t2.subseconds() == t1.subseconds()); 107 | assert(t2.to_duration() == t1.to_duration()); 108 | ostringstream os; 109 | os << t2; 110 | assert(os.str() == "13:07:06.0480"); 111 | } 112 | -------------------------------------------------------------------------------- /test/date_test/time_of_day_milliseconds.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // enum {am = 1, pm}; 24 | 25 | // template 26 | // class time_of_day> 27 | // { 28 | // public: 29 | // using precision = std::chrono::std::chrono::duration; 30 | // 31 | // constexpr explicit time_of_day(precision since_midnight) noexcept; 32 | // constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, 33 | // std::chrono::seconds s, precision sub_s, 34 | // unsigned md) noexcept; 35 | // 36 | // constexpr std::chrono::hours hours() const noexcept; 37 | // constexpr std::chrono::minutes minutes() const noexcept; 38 | // constexpr std::chrono::seconds seconds() const noexcept; 39 | // constexpr precision subseconds() const noexcept; 40 | // constexpr unsigned mode() const noexcept; 41 | // 42 | // constexpr explicit operator precision() const noexcept; 43 | // constexpr precision to_duration() const noexcept; 44 | // 45 | // void make24() noexcept; 46 | // void make12() noexcept; 47 | // }; 48 | 49 | // template 50 | // std::ostream& 51 | // operator<<(std::ostream& os, const time_of_day>& t); 52 | 53 | #include "date.h" 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | int 60 | main() 61 | { 62 | using namespace date; 63 | using namespace std; 64 | using namespace std::chrono; 65 | 66 | using tod = time_of_day; 67 | 68 | static_assert(is_same{}, ""); 69 | 70 | static_assert( is_trivially_destructible{}, ""); 71 | static_assert( is_default_constructible{}, ""); 72 | static_assert( is_trivially_copy_constructible{}, ""); 73 | static_assert( is_trivially_copy_assignable{}, ""); 74 | static_assert( is_trivially_move_constructible{}, ""); 75 | static_assert( is_trivially_move_assignable{}, ""); 76 | 77 | static_assert(is_nothrow_constructible{}, ""); 78 | static_assert(!is_convertible{}, ""); 79 | 80 | static_assert(is_nothrow_constructible{}, ""); 81 | static_assert(!is_convertible{}, ""); 82 | 83 | constexpr tod t1 = tod{hours{13} + minutes{7} + seconds{5} + milliseconds{22}}; 84 | static_assert(t1.hours() == hours{13}, ""); 85 | static_assert(t1.minutes() == minutes{7}, ""); 86 | static_assert(t1.seconds() == seconds{5}, ""); 87 | static_assert(t1.subseconds() == milliseconds{22}, ""); 88 | #if __cplusplus >= 201402 89 | static_assert(static_cast(t1) == hours{13} + minutes{7} 90 | + seconds{5} + milliseconds{22}, ""); 91 | static_assert(t1.to_duration() == hours{13} + minutes{7} + seconds{5} 92 | + milliseconds{22}, ""); 93 | #endif 94 | 95 | auto t2 = t1; 96 | assert(t2.hours() == t1.hours()); 97 | assert(t2.minutes() == t1.minutes()); 98 | assert(t2.seconds() == t1.seconds()); 99 | assert(t2.subseconds() == t1.subseconds()); 100 | assert(t2.to_duration() == t1.to_duration()); 101 | ostringstream os; 102 | os << t2; 103 | assert(os.str() == "13:07:05.022"); 104 | } 105 | -------------------------------------------------------------------------------- /test/date_test/time_of_day_minutes.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // enum {am = 1, pm}; 24 | 25 | // class time_of_day 26 | // { 27 | // public: 28 | // using precision = std::chrono::minutes; 29 | // 30 | // constexpr explicit time_of_day(std::chrono::minutes since_midnight) noexcept; 31 | // constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, 32 | // unsigned md) noexcept; 33 | // 34 | // constexpr std::chrono::hours hours() const noexcept; 35 | // constexpr std::chrono::minutes minutes() const noexcept; 36 | // constexpr unsigned mode() const noexcept; 37 | // 38 | // constexpr explicit operator precision() const noexcept; 39 | // constexpr precision to_duration() const noexcept; 40 | // 41 | // void make24() noexcept; 42 | // void make12() noexcept; 43 | // }; 44 | 45 | // std::ostream& operator<<(std::ostream& os, const time_of_day& t); 46 | 47 | #include "date.h" 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | int 54 | main() 55 | { 56 | using namespace date; 57 | using namespace std; 58 | using namespace std::chrono; 59 | 60 | using tod = time_of_day; 61 | 62 | static_assert(is_same{}, ""); 63 | 64 | static_assert( is_trivially_destructible{}, ""); 65 | static_assert( is_default_constructible{}, ""); 66 | static_assert( is_trivially_copy_constructible{}, ""); 67 | static_assert( is_trivially_copy_assignable{}, ""); 68 | static_assert( is_trivially_move_constructible{}, ""); 69 | static_assert( is_trivially_move_assignable{}, ""); 70 | 71 | static_assert(is_nothrow_constructible{}, ""); 72 | static_assert(!is_convertible{}, ""); 73 | 74 | static_assert(is_nothrow_constructible{}, ""); 75 | static_assert(!is_convertible{}, ""); 76 | 77 | constexpr tod t1 = tod{hours{13} + minutes{7}}; 78 | static_assert(t1.hours() == hours{13}, ""); 79 | static_assert(t1.minutes() == minutes{7}, ""); 80 | #if __cplusplus >= 201402 81 | static_assert(static_cast(t1) == hours{13} + minutes{7}, ""); 82 | static_assert(t1.to_duration() == hours{13} + minutes{7}, ""); 83 | #endif 84 | 85 | auto t2 = t1; 86 | assert(t2.hours() == t1.hours()); 87 | assert(t2.minutes() == t1.minutes()); 88 | assert(t2.to_duration() == t1.to_duration()); 89 | ostringstream os; 90 | os << t2; 91 | assert(os.str() == "13:07:00"); 92 | } 93 | -------------------------------------------------------------------------------- /test/date_test/time_of_day_nanoseconds.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // enum {am = 1, pm}; 24 | 25 | // template 26 | // class time_of_day> 27 | // { 28 | // public: 29 | // using precision = std::chrono::std::chrono::duration; 30 | // 31 | // constexpr explicit time_of_day(precision since_midnight) noexcept; 32 | // constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, 33 | // std::chrono::seconds s, precision sub_s, 34 | // unsigned md) noexcept; 35 | // 36 | // constexpr std::chrono::hours hours() const noexcept; 37 | // constexpr std::chrono::minutes minutes() const noexcept; 38 | // constexpr std::chrono::seconds seconds() const noexcept; 39 | // constexpr precision subseconds() const noexcept; 40 | // constexpr unsigned mode() const noexcept; 41 | // 42 | // constexpr explicit operator precision() const noexcept; 43 | // constexpr precision to_duration() const noexcept; 44 | // 45 | // void make24() noexcept; 46 | // void make12() noexcept; 47 | // }; 48 | 49 | // template 50 | // std::ostream& 51 | // operator<<(std::ostream& os, const time_of_day>& t); 52 | 53 | #include "date.h" 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | int 60 | main() 61 | { 62 | using namespace date; 63 | using namespace std; 64 | using namespace std::chrono; 65 | 66 | using tod = time_of_day; 67 | 68 | static_assert(is_same{}, ""); 69 | 70 | static_assert( is_trivially_destructible{}, ""); 71 | static_assert( is_default_constructible{}, ""); 72 | static_assert( is_trivially_copy_constructible{}, ""); 73 | static_assert( is_trivially_copy_assignable{}, ""); 74 | static_assert( is_trivially_move_constructible{}, ""); 75 | static_assert( is_trivially_move_assignable{}, ""); 76 | 77 | static_assert(is_nothrow_constructible{}, ""); 78 | static_assert(!is_convertible{}, ""); 79 | 80 | static_assert(is_nothrow_constructible{}, ""); 81 | static_assert(!is_convertible{}, ""); 82 | 83 | constexpr tod t1 = tod{hours{13} + minutes{7} + seconds{5} + nanoseconds{22}}; 84 | static_assert(t1.hours() == hours{13}, ""); 85 | static_assert(t1.minutes() == minutes{7}, ""); 86 | static_assert(t1.seconds() == seconds{5}, ""); 87 | static_assert(t1.subseconds() == nanoseconds{22}, ""); 88 | #if __cplusplus >= 201402 89 | static_assert(static_cast(t1) == hours{13} + minutes{7} 90 | + seconds{5} + nanoseconds{22}, ""); 91 | static_assert(t1.to_duration() == hours{13} + minutes{7} + seconds{5} 92 | + nanoseconds{22}, ""); 93 | #endif 94 | 95 | auto t2 = t1; 96 | assert(t2.hours() == t1.hours()); 97 | assert(t2.minutes() == t1.minutes()); 98 | assert(t2.seconds() == t1.seconds()); 99 | assert(t2.subseconds() == t1.subseconds()); 100 | assert(t2.to_duration() == t1.to_duration()); 101 | ostringstream os; 102 | os << t2; 103 | assert(os.str() == "13:07:05.000000022"); 104 | } 105 | -------------------------------------------------------------------------------- /test/date_test/time_of_day_seconds.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // enum {am = 1, pm}; 24 | 25 | // class time_of_day 26 | // { 27 | // public: 28 | // using precision = std::chrono::seconds; 29 | // 30 | // constexpr explicit time_of_day(std::chrono::seconds since_midnight) noexcept; 31 | // constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, 32 | // std::chrono::seconds s, unsigned md) noexcept; 33 | // 34 | // constexpr std::chrono::hours hours() const noexcept; 35 | // constexpr std::chrono::minutes minutes() const noexcept; 36 | // constexpr std::chrono::seconds seconds() const noexcept; 37 | // constexpr unsigned mode() const noexcept; 38 | // 39 | // constexpr explicit operator precision() const noexcept; 40 | // constexpr precision to_duration() const noexcept; 41 | // 42 | // void make24() noexcept; 43 | // void make12() noexcept; 44 | // }; 45 | 46 | // std::ostream& operator<<(std::ostream& os, const time_of_day& t); 47 | 48 | #include "date.h" 49 | 50 | #include 51 | #include 52 | #include 53 | 54 | int 55 | main() 56 | { 57 | using namespace date; 58 | using namespace std; 59 | using namespace std::chrono; 60 | 61 | using tod = time_of_day; 62 | 63 | static_assert(is_same{}, ""); 64 | 65 | static_assert( is_trivially_destructible{}, ""); 66 | static_assert( is_default_constructible{}, ""); 67 | static_assert( is_trivially_copy_constructible{}, ""); 68 | static_assert( is_trivially_copy_assignable{}, ""); 69 | static_assert( is_trivially_move_constructible{}, ""); 70 | static_assert( is_trivially_move_assignable{}, ""); 71 | 72 | static_assert(is_nothrow_constructible{}, ""); 73 | static_assert(!is_convertible{}, ""); 74 | 75 | static_assert(is_nothrow_constructible{}, ""); 76 | static_assert(!is_convertible{}, ""); 77 | 78 | constexpr tod t1 = tod{hours{13} + minutes{7} + seconds{5}}; 79 | static_assert(t1.hours() == hours{13}, ""); 80 | static_assert(t1.minutes() == minutes{7}, ""); 81 | static_assert(t1.seconds() == seconds{5}, ""); 82 | #if __cplusplus >= 201402 83 | static_assert(static_cast(t1) == hours{13} + minutes{7} 84 | + seconds{5}, ""); 85 | static_assert(t1.to_duration() == hours{13} + minutes{7} + seconds{5}, ""); 86 | #endif 87 | 88 | auto t2 = t1; 89 | assert(t2.hours() == t1.hours()); 90 | assert(t2.minutes() == t1.minutes()); 91 | assert(t2.seconds() == t1.seconds()); 92 | assert(t2.to_duration() == t1.to_duration()); 93 | ostringstream os; 94 | os << t2; 95 | assert(os.str() == "13:07:05"); 96 | } 97 | -------------------------------------------------------------------------------- /test/date_test/weekday_indexed.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class weekday_indexed 24 | // { 25 | // public: 26 | // weekday_indexed() = default; 27 | // constexpr weekday_indexed(const date::weekday& wd, unsigned index) noexcept; 28 | // 29 | // constexpr date::weekday weekday() const noexcept; 30 | // constexpr unsigned index() const noexcept; 31 | // constexpr bool ok() const noexcept; 32 | // }; 33 | // 34 | // constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; 35 | // constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; 36 | // 37 | // std::ostream& operator<<(std::ostream& os, const weekday_indexed& wdi); 38 | 39 | #include "date.h" 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | static_assert( std::is_trivially_destructible{}, ""); 46 | static_assert( std::is_default_constructible{}, ""); 47 | static_assert( std::is_trivially_copy_constructible{}, ""); 48 | static_assert( std::is_trivially_copy_assignable{}, ""); 49 | static_assert( std::is_trivially_move_constructible{}, ""); 50 | static_assert( std::is_trivially_move_assignable{}, ""); 51 | 52 | static_assert(std::is_nothrow_constructible{}, ""); 54 | 55 | int 56 | main() 57 | { 58 | using namespace date; 59 | 60 | constexpr weekday_indexed wdi = sun[1]; 61 | static_assert(wdi.weekday() == sun, ""); 62 | static_assert(wdi.index() == 1, ""); 63 | static_assert(wdi.ok(), ""); 64 | static_assert(wdi == weekday_indexed{sun, 1}, ""); 65 | static_assert(wdi != weekday_indexed{sun, 2}, ""); 66 | static_assert(wdi != weekday_indexed{mon, 1}, ""); 67 | std::ostringstream os; 68 | os << wdi; 69 | assert(os.str() == "Sun[1]"); 70 | } 71 | -------------------------------------------------------------------------------- /test/date_test/weekday_last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class weekday_last 24 | // { 25 | // public: 26 | // explicit constexpr weekday_last(const date::weekday& wd) noexcept; 27 | // 28 | // constexpr date::weekday weekday() const noexcept; 29 | // constexpr bool ok() const noexcept; 30 | // }; 31 | // 32 | // constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; 33 | // constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; 34 | // 35 | // std::ostream& operator<<(std::ostream& os, const weekday_last& wdl); 36 | 37 | #include "date.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | static_assert( std::is_trivially_destructible{}, ""); 44 | static_assert(!std::is_default_constructible{}, ""); 45 | static_assert( std::is_trivially_copy_constructible{}, ""); 46 | static_assert( std::is_trivially_copy_assignable{}, ""); 47 | static_assert( std::is_trivially_move_constructible{}, ""); 48 | static_assert( std::is_trivially_move_assignable{}, ""); 49 | 50 | static_assert(std::is_nothrow_constructible{}, ""); 51 | static_assert(!std::is_convertible{}, ""); 52 | 53 | int 54 | main() 55 | { 56 | using namespace date; 57 | 58 | constexpr weekday_last wdl = sun[last]; 59 | static_assert(wdl.weekday() == sun, ""); 60 | static_assert(wdl.ok(), ""); 61 | static_assert(wdl == weekday_last{sun}, ""); 62 | static_assert(wdl != weekday_last{mon}, ""); 63 | std::ostringstream os; 64 | os << wdl; 65 | assert(os.str() == "Sun[last]"); 66 | } 67 | -------------------------------------------------------------------------------- /test/date_test/weekday_lessthan.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weekday < weekday not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto b = sun < mon; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/weekday_sum.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weekday + weekday not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto b = sun + mon; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/year_month_day_m_year_month_day.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year_month_day - year_month_day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = year_month_day{2015_y, aug, 9_d} - year_month_day{2015_y, aug, 9_d}; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/year_month_day_p_year_month_day.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year_month_day + year_month_day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = year_month_day{2015_y, aug, 9_d} + year_month_day{2015_y, aug, 9_d}; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/year_month_p_year_month.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year_month + year_month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = year_month{2015_y, jan} + year_month{2015_y, jan}; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/year_p_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year + year not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto x = 2015_y + 2015_y; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/years_m_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // years - year not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | auto x = years{3} - 2015_y; 32 | } 33 | -------------------------------------------------------------------------------- /test/date_test/years_m_year_month.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // years - year_month not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = years{1} - year_month{2015_y, jan}; 33 | } 34 | -------------------------------------------------------------------------------- /test/date_test/years_m_year_month_day.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // years - year_month_day not allowed 24 | 25 | #include "date.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace date; 31 | 32 | auto x = 2015_y - year_month_day{2015_y, aug, 9_d}; 33 | } 34 | -------------------------------------------------------------------------------- /test/iso_week/last.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // constexpr struct last_spec {} last{}; 24 | 25 | #include "iso_week.h" 26 | 27 | #include 28 | 29 | static_assert(std::is_same{}, ""); 30 | 31 | int 32 | main() 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /test/iso_week/lastweek_weekday.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class lastweek_weekday 24 | // { 25 | // iso_week::weekday wd_; // exposition only 26 | // 27 | // public: 28 | // explicit constexpr lastweek_weekday(const iso_week::weekday& wd) noexcept; 29 | // 30 | // constexpr iso_week::weekday weekday() const noexcept; 31 | // 32 | // constexpr bool ok() const noexcept; 33 | // }; 34 | // 35 | // constexpr bool operator==(const lastweek_weekday& x, const lastweek_weekday& y) noexcept; 36 | // constexpr bool operator!=(const lastweek_weekday& x, const lastweek_weekday& y) noexcept; 37 | // constexpr bool operator< (const lastweek_weekday& x, const lastweek_weekday& y) noexcept; 38 | // constexpr bool operator> (const lastweek_weekday& x, const lastweek_weekday& y) noexcept; 39 | // constexpr bool operator<=(const lastweek_weekday& x, const lastweek_weekday& y) noexcept; 40 | // constexpr bool operator>=(const lastweek_weekday& x, const lastweek_weekday& y) noexcept; 41 | // 42 | // std::ostream& operator<<(std::ostream& os, const lastweek_weekday& md); 43 | 44 | #include "iso_week.h" 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | static_assert( std::is_trivially_destructible{}, ""); 51 | static_assert(!std::is_default_constructible{}, ""); 52 | static_assert( std::is_trivially_copy_constructible{}, ""); 53 | static_assert( std::is_trivially_copy_assignable{}, ""); 54 | static_assert( std::is_trivially_move_constructible{}, ""); 55 | static_assert( std::is_trivially_move_assignable{}, ""); 56 | 57 | static_assert(std::is_trivially_copyable{}, ""); 58 | static_assert(std::is_standard_layout{}, ""); 59 | 60 | static_assert( std::is_nothrow_constructible{}, ""); 62 | static_assert(!std::is_convertible{}, ""); 63 | 64 | int 65 | main() 66 | { 67 | using namespace iso_week; 68 | 69 | constexpr auto wn_wd = lastweek_weekday{tue}; 70 | static_assert(wn_wd.weekday() == tue, ""); 71 | 72 | static_assert(wn_wd.ok(), ""); 73 | 74 | static_assert(wn_wd == lastweek_weekday{tue}, ""); 75 | static_assert(!(wn_wd != lastweek_weekday{tue}), ""); 76 | static_assert(wn_wd < lastweek_weekday{wed}, ""); 77 | 78 | std::ostringstream os; 79 | os << wn_wd; 80 | assert(os.str() == "W last-Tue"); 81 | } 82 | -------------------------------------------------------------------------------- /test/iso_week/weekday_lessthan.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weekday < weekday not allowed 24 | 25 | #include "iso_week.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace iso_week; 31 | auto b = sun < mon; 32 | } 33 | -------------------------------------------------------------------------------- /test/iso_week/weekday_sum.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weekday + weekday not allowed 24 | 25 | #include "iso_week.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace iso_week; 31 | auto b = sun + mon; 32 | } 33 | -------------------------------------------------------------------------------- /test/iso_week/weeknum_p_weeknum.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // weeknum + weeknum not allowed 24 | 25 | #include "iso_week.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace iso_week; 31 | auto x = 3_w + 4_w; 32 | } 33 | -------------------------------------------------------------------------------- /test/iso_week/weeknum_weekday.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class weeknum_weekday 24 | // { 25 | // iso_week::weeknum wn_; // exposition only 26 | // iso_week::weekday wd_; // exposition only 27 | // 28 | // public: 29 | // constexpr weeknum_weekday(const iso_week::weeknum& wn, 30 | // const iso_week::weekday& wd) noexcept; 31 | // 32 | // constexpr iso_week::weeknum weeknum() const noexcept; 33 | // constexpr iso_week::weekday weekday() const noexcept; 34 | // 35 | // constexpr bool ok() const noexcept; 36 | // }; 37 | // 38 | // constexpr bool operator==(const weeknum_weekday& x, const weeknum_weekday& y) noexcept; 39 | // constexpr bool operator!=(const weeknum_weekday& x, const weeknum_weekday& y) noexcept; 40 | // constexpr bool operator< (const weeknum_weekday& x, const weeknum_weekday& y) noexcept; 41 | // constexpr bool operator> (const weeknum_weekday& x, const weeknum_weekday& y) noexcept; 42 | // constexpr bool operator<=(const weeknum_weekday& x, const weeknum_weekday& y) noexcept; 43 | // constexpr bool operator>=(const weeknum_weekday& x, const weeknum_weekday& y) noexcept; 44 | // 45 | // std::ostream& operator<<(std::ostream& os, const weeknum_weekday& md); 46 | 47 | #include "iso_week.h" 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | static_assert( std::is_trivially_destructible{}, ""); 54 | static_assert(!std::is_default_constructible{}, ""); 55 | static_assert( std::is_trivially_copy_constructible{}, ""); 56 | static_assert( std::is_trivially_copy_assignable{}, ""); 57 | static_assert( std::is_trivially_move_constructible{}, ""); 58 | static_assert( std::is_trivially_move_assignable{}, ""); 59 | 60 | static_assert(std::is_trivially_copyable{}, ""); 61 | static_assert(std::is_standard_layout{}, ""); 62 | 63 | static_assert( std::is_nothrow_constructible{}, ""); 66 | 67 | int 68 | main() 69 | { 70 | using namespace iso_week; 71 | 72 | constexpr auto wn_wd = weeknum_weekday{52_w, tue}; 73 | static_assert(wn_wd.weeknum() == 52_w, ""); 74 | static_assert(wn_wd.weekday() == tue, ""); 75 | 76 | static_assert(wn_wd.ok(), ""); 77 | 78 | static_assert(wn_wd == weeknum_weekday{52_w, tue}, ""); 79 | static_assert(!(wn_wd != weeknum_weekday{52_w, tue}), ""); 80 | static_assert(wn_wd < weeknum_weekday{52_w, wed}, ""); 81 | 82 | std::ostringstream os; 83 | os << wn_wd; 84 | assert(os.str() == "W52-Tue"); 85 | } 86 | -------------------------------------------------------------------------------- /test/iso_week/year_lastweek.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class year_lastweek 24 | // { 25 | // iso_week::year y_; 26 | // 27 | // public: 28 | // explicit constexpr year_lastweek(const iso_week::year& y) noexcept; 29 | // 30 | // constexpr iso_week::year year() const noexcept; 31 | // constexpr iso_week::weeknum weeknum() const noexcept; 32 | // 33 | // year_lastweek& operator+=(const years& dy) noexcept; 34 | // year_lastweek& operator-=(const years& dy) noexcept; 35 | // 36 | // constexpr bool ok() const noexcept; 37 | // }; 38 | // 39 | // constexpr bool operator==(const year_lastweek& x, const year_lastweek& y) noexcept; 40 | // constexpr bool operator!=(const year_lastweek& x, const year_lastweek& y) noexcept; 41 | // constexpr bool operator< (const year_lastweek& x, const year_lastweek& y) noexcept; 42 | // constexpr bool operator> (const year_lastweek& x, const year_lastweek& y) noexcept; 43 | // constexpr bool operator<=(const year_lastweek& x, const year_lastweek& y) noexcept; 44 | // constexpr bool operator>=(const year_lastweek& x, const year_lastweek& y) noexcept; 45 | // 46 | // constexpr year_lastweek operator+(const year_lastweek& ym, const years& dy) noexcept; 47 | // constexpr year_lastweek operator+(const years& dy, const year_lastweek& ym) noexcept; 48 | // constexpr year_lastweek operator-(const year_lastweek& ym, const years& dy) noexcept; 49 | // 50 | // std::ostream& operator<<(std::ostream& os, const year_lastweek& ym); 51 | 52 | #include "iso_week.h" 53 | 54 | #include 55 | #include 56 | #include 57 | 58 | static_assert( std::is_trivially_destructible{}, ""); 59 | static_assert(!std::is_default_constructible{}, ""); 60 | static_assert( std::is_trivially_copy_constructible{}, ""); 61 | static_assert( std::is_trivially_copy_assignable{}, ""); 62 | static_assert( std::is_trivially_move_constructible{}, ""); 63 | static_assert( std::is_trivially_move_assignable{}, ""); 64 | 65 | static_assert(std::is_trivially_copyable{}, ""); 66 | static_assert(std::is_standard_layout{}, ""); 67 | 68 | static_assert(std::is_nothrow_constructible{}, ""); 70 | static_assert(!std::is_convertible{}, ""); 71 | 72 | int 73 | main() 74 | { 75 | using namespace iso_week; 76 | 77 | constexpr auto y_wn = year_lastweek{2015_y}; 78 | static_assert(y_wn.year() == 2015_y, ""); 79 | static_assert(y_wn.weeknum() == 53_w, ""); 80 | static_assert(year_lastweek{2016_y}.weeknum() == 52_w, ""); 81 | 82 | static_assert(y_wn.ok(), ""); 83 | 84 | static_assert(y_wn == year_lastweek{2015_y}, ""); 85 | static_assert(!(y_wn != year_lastweek{2015_y}), ""); 86 | static_assert(y_wn < year_lastweek{2016_y}, ""); 87 | 88 | auto y_wn2 = y_wn + years{2}; 89 | assert(y_wn2 == year_lastweek{2017_y}); 90 | y_wn2 -= years{1}; 91 | assert(y_wn2 == year_lastweek{2016_y}); 92 | 93 | std::ostringstream os; 94 | os << y_wn; 95 | assert(os.str() == "2015-W last"); 96 | } 97 | -------------------------------------------------------------------------------- /test/iso_week/year_p_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // year + year not allowed 24 | 25 | #include "iso_week.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace iso_week; 31 | auto x = 2015_y + 2015_y; 32 | } 33 | -------------------------------------------------------------------------------- /test/iso_week/year_weeknum.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // class year_weeknum 24 | // { 25 | // iso_week::year y_; 26 | // iso_week::weeknum wn_; 27 | // 28 | // public: 29 | // constexpr year_weeknum(const iso_week::year& y, const iso_week::weeknum& wn) noexcept; 30 | // 31 | // constexpr iso_week::year year() const noexcept; 32 | // constexpr iso_week::weeknum weeknum() const noexcept; 33 | // 34 | // year_weeknum& operator+=(const years& dy) noexcept; 35 | // year_weeknum& operator-=(const years& dy) noexcept; 36 | // 37 | // constexpr bool ok() const noexcept; 38 | // }; 39 | // 40 | // constexpr bool operator==(const year_weeknum& x, const year_weeknum& y) noexcept; 41 | // constexpr bool operator!=(const year_weeknum& x, const year_weeknum& y) noexcept; 42 | // constexpr bool operator< (const year_weeknum& x, const year_weeknum& y) noexcept; 43 | // constexpr bool operator> (const year_weeknum& x, const year_weeknum& y) noexcept; 44 | // constexpr bool operator<=(const year_weeknum& x, const year_weeknum& y) noexcept; 45 | // constexpr bool operator>=(const year_weeknum& x, const year_weeknum& y) noexcept; 46 | // 47 | // constexpr year_weeknum operator+(const year_weeknum& ym, const years& dy) noexcept; 48 | // constexpr year_weeknum operator+(const years& dy, const year_weeknum& ym) noexcept; 49 | // constexpr year_weeknum operator-(const year_weeknum& ym, const years& dy) noexcept; 50 | // 51 | // std::ostream& operator<<(std::ostream& os, const year_weeknum& ym); 52 | 53 | #include "iso_week.h" 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | static_assert( std::is_trivially_destructible{}, ""); 60 | static_assert(!std::is_default_constructible{}, ""); 61 | static_assert( std::is_trivially_copy_constructible{}, ""); 62 | static_assert( std::is_trivially_copy_assignable{}, ""); 63 | static_assert( std::is_trivially_move_constructible{}, ""); 64 | static_assert( std::is_trivially_move_assignable{}, ""); 65 | 66 | static_assert(std::is_trivially_copyable{}, ""); 67 | static_assert(std::is_standard_layout{}, ""); 68 | 69 | static_assert( std::is_nothrow_constructible{}, ""); 72 | 73 | int 74 | main() 75 | { 76 | using namespace iso_week; 77 | 78 | constexpr auto y_wn = year_weeknum{2015_y, 52_w}; 79 | static_assert(y_wn.year() == 2015_y, ""); 80 | static_assert(y_wn.weeknum() == 52_w, ""); 81 | 82 | static_assert(y_wn.ok(), ""); 83 | 84 | static_assert(y_wn == year_weeknum{2015_y, 52_w}, ""); 85 | static_assert(!(y_wn != year_weeknum{2015_y, 52_w}), ""); 86 | static_assert(y_wn < year_weeknum{2015_y, 53_w}, ""); 87 | 88 | auto y_wn2 = y_wn + years{2}; 89 | assert((y_wn2 == year_weeknum{2017_y, 52_w})); 90 | y_wn2 -= years{1}; 91 | assert((y_wn2 == year_weeknum{2016_y, 52_w})); 92 | 93 | std::ostringstream os; 94 | os << y_wn; 95 | assert(os.str() == "2015-W52"); 96 | } 97 | -------------------------------------------------------------------------------- /test/iso_week/years_m_year.fail.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // years - year not allowed 24 | 25 | #include "iso_week.h" 26 | 27 | int 28 | main() 29 | { 30 | using namespace iso_week; 31 | auto x = years{3} - 2015_y; 32 | } 33 | -------------------------------------------------------------------------------- /test/just.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | int 24 | main() 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /test/posix/ptz.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2021 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // Test Posix::time_zone 24 | 25 | #include "tz.h" 26 | #include "ptz.h" 27 | #include 28 | 29 | bool 30 | is_equal(date::sys_info const& x, date::sys_info const& y) 31 | { 32 | using namespace std::chrono; 33 | return x.begin == y.begin && 34 | x.end == y.end && 35 | x.offset == y.offset && 36 | (x.save == minutes{0}) == (y.save == minutes{0}) && 37 | x.abbrev == y.abbrev; 38 | } 39 | 40 | bool 41 | is_equal(date::local_info const& x, date::local_info const& y) 42 | { 43 | return x.result == y.result && is_equal(x.first, y.first) 44 | && is_equal(x.second, y.second); 45 | } 46 | 47 | int 48 | main() 49 | { 50 | using namespace date; 51 | using namespace std; 52 | using namespace std::chrono; 53 | using date::local_days, date::Sunday, date::last; 54 | 55 | auto tzi = locate_zone("Australia/Sydney"); 56 | Posix::time_zone tzp{"AEST-10AEDT,M10.1.0,M4.1.0/3"}; 57 | auto tp = local_days{2021_y/1/1} + 0s; 58 | assert(tzp.get_info(tp).result == local_info::unique); 59 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 60 | 61 | tp = local_days{2021_y/10/Sunday[1]} + 2h + 30min; 62 | assert(tzp.get_info(tp).result == local_info::nonexistent); 63 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 64 | 65 | tp = local_days{2021_y/4/Sunday[1]} + 2h + 30min; 66 | assert(tzp.get_info(tp).result == local_info::ambiguous); 67 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 68 | 69 | tp = local_days{2021_y/7/1}; 70 | assert(tzp.get_info(tp).result == local_info::unique); 71 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 72 | 73 | 74 | tzi = locate_zone("America/New_York"); 75 | tzp = Posix::time_zone{"EST5EDT,M3.2.0,M11.1.0"}; 76 | tp = local_days{2021_y/1/1}; 77 | assert(tzp.get_info(tp).result == local_info::unique); 78 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 79 | 80 | tp = local_days{2021_y/3/Sunday[2]} + 2h + 30min; 81 | assert(tzp.get_info(tp).result == local_info::nonexistent); 82 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 83 | 84 | tp = local_days{2021_y/11/Sunday[1]} + 1h + 30min; 85 | assert(tzp.get_info(tp).result == local_info::ambiguous); 86 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 87 | 88 | tp = local_days{2021_y/7/1}; 89 | assert(tzp.get_info(tp).result == local_info::unique); 90 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 91 | 92 | 93 | tzi = locate_zone("Europe/Dublin"); 94 | tzp = Posix::time_zone{"IST-1GMT0,M10.5.0,M3.5.0/1"}; 95 | tp = local_days{2021_y/1/1}; 96 | assert(tzp.get_info(tp).result == local_info::unique); 97 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 98 | 99 | tp = local_days{2021_y/3/Sunday[last]} + 1h + 30min; 100 | assert(tzp.get_info(tp).result == local_info::nonexistent); 101 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 102 | 103 | tp = local_days{2021_y/10/Sunday[last]} + 1h + 30min; 104 | assert(tzp.get_info(tp).result == local_info::ambiguous); 105 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 106 | 107 | tp = local_days{2021_y/7/1}; 108 | assert(tzp.get_info(tp).result == local_info::unique); 109 | assert(is_equal(tzi->get_info(tp), tzp.get_info(tp))); 110 | } 111 | -------------------------------------------------------------------------------- /test/tz_test/OffsetZone.h: -------------------------------------------------------------------------------- 1 | #ifndef OFFSET_ZONE_H 2 | #define OFFSET_ZONE_H 3 | 4 | // The MIT License (MIT) 5 | // 6 | // Copyright (c) 2017 Howard Hinnant 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | 26 | // Test custom time zone support 27 | 28 | #include "tz.h" 29 | 30 | class OffsetZone 31 | { 32 | std::chrono::minutes offset_; 33 | 34 | public: 35 | explicit OffsetZone(std::chrono::minutes offset) 36 | : offset_{offset} 37 | {} 38 | 39 | template 40 | auto 41 | to_local(date::sys_time tp) const 42 | { 43 | using namespace date; 44 | using namespace std::chrono; 45 | using LT = date::local_time>; 46 | return LT{(tp + offset_).time_since_epoch()}; 47 | } 48 | 49 | template 50 | auto 51 | to_sys(date::local_time tp, date::choose = date::choose::earliest) const 52 | { 53 | using namespace date; 54 | using namespace std::chrono; 55 | using ST = date::sys_time>; 56 | return ST{(tp - offset_).time_since_epoch()}; 57 | } 58 | 59 | template 60 | date::sys_info 61 | get_info(date::sys_time st) const 62 | { 63 | using namespace date; 64 | using namespace std::chrono; 65 | return {sys_seconds::min(), sys_seconds::max(), offset_, 66 | minutes{0}, offset_ >= minutes{0} ? "+" + date::format("%H%M", offset_) 67 | : "-" + date::format("%H%M", -offset_)}; 68 | } 69 | 70 | const OffsetZone* operator->() const {return this;} 71 | }; 72 | 73 | #endif // OFFSET_ZONE_H 74 | -------------------------------------------------------------------------------- /test/tz_test/OffsetZone.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2017 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | // Test custom time zone support 24 | 25 | #include "tz.h" 26 | #include "OffsetZone.h" 27 | #include 28 | 29 | int 30 | main() 31 | { 32 | using namespace date; 33 | using namespace std::chrono; 34 | auto now = system_clock::now(); 35 | auto offset = hours{-4}; 36 | zoned_time zt{OffsetZone{offset}, now}; 37 | assert(zt.get_local_time().time_since_epoch() == now.time_since_epoch() + offset); 38 | } 39 | -------------------------------------------------------------------------------- /test/tz_test/README.md: -------------------------------------------------------------------------------- 1 | # TZ Test 2 | 3 | ## How to Test 4 | 5 | * Install tz.cpp by downloading the IANA timezone database at: http://www.iana.org/time-zones You only need the data, not the code. 6 | * Change the string `install` in tz.cpp to point to your downloaded IANA database. 7 | * Compile validate.cpp along with tz.cpp. 8 | * Run the binary and direct the terminal output to a temporary file. 9 | * Unzip the tzdata file that has the version corresponding to the IANA database you downloaded (e.g. tzdata2015f.txt.zip). 10 | * Compare the unzipped txt file with the output of your validate test program. If they are identical, the test passes, else it fails. 11 | 12 | ## Miscellaneous 13 | 14 | You can also compare one version of the tzdatabase with another using 15 | these uncompressed text files. The text files contain for each 16 | timezone its initial state, and each {offset, abbreviation} change 17 | contained in the database up through the year 2035. As the database 18 | versions change, minor updates to the set of these transitions are 19 | typically made, typically due to changes in government policies. 20 | 21 | The tests in this section will run much faster with optimizations 22 | cranked up. 23 | -------------------------------------------------------------------------------- /test/tz_test/tzdata2015e.txt.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HowardHinnant/date/f94b8f36c6180be0021876c4a397a054fe50c6f2/test/tz_test/tzdata2015e.txt.zip -------------------------------------------------------------------------------- /test/tz_test/tzdata2015f.txt.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HowardHinnant/date/f94b8f36c6180be0021876c4a397a054fe50c6f2/test/tz_test/tzdata2015f.txt.zip -------------------------------------------------------------------------------- /test/tz_test/tzdata2016c.txt.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HowardHinnant/date/f94b8f36c6180be0021876c4a397a054fe50c6f2/test/tz_test/tzdata2016c.txt.zip -------------------------------------------------------------------------------- /test/tz_test/tzdata2016d.txt.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HowardHinnant/date/f94b8f36c6180be0021876c4a397a054fe50c6f2/test/tz_test/tzdata2016d.txt.zip -------------------------------------------------------------------------------- /test/tz_test/tzdata2016e.txt.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HowardHinnant/date/f94b8f36c6180be0021876c4a397a054fe50c6f2/test/tz_test/tzdata2016e.txt.zip -------------------------------------------------------------------------------- /test/tz_test/tzdata2016f.txt.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HowardHinnant/date/f94b8f36c6180be0021876c4a397a054fe50c6f2/test/tz_test/tzdata2016f.txt.zip -------------------------------------------------------------------------------- /test/tz_test/tzdb_list.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2020 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | #include 25 | 26 | int 27 | main() 28 | { 29 | using namespace date; 30 | static_assert( std::is_nothrow_destructible{}, ""); 31 | static_assert( std::is_nothrow_default_constructible{}, ""); 32 | static_assert(!std::is_copy_constructible{}, ""); 33 | static_assert(!std::is_copy_assignable{}, ""); 34 | static_assert( std::is_nothrow_move_constructible{}, ""); 35 | static_assert(!std::is_move_assignable{}, ""); 36 | } 37 | -------------------------------------------------------------------------------- /test/tz_test/zone.pass.cpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | // 3 | // Copyright (c) 2015, 2016 Howard Hinnant 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | #include "tz.h" 24 | #include 25 | 26 | int 27 | main() 28 | { 29 | using namespace std; 30 | using namespace date; 31 | static_assert( is_nothrow_destructible{}, ""); 32 | static_assert(!is_default_constructible{}, ""); 33 | static_assert(!is_copy_constructible{}, ""); 34 | static_assert(!is_copy_assignable{}, ""); 35 | static_assert( is_nothrow_move_constructible{}, ""); 36 | static_assert( is_nothrow_move_assignable{}, ""); 37 | } 38 | -------------------------------------------------------------------------------- /test_fail.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # show what is to be run 4 | echo $1 5 | # run the command 6 | eval $1 || exit 1 # if fails, return 1 7 | --------------------------------------------------------------------------------