├── .appveyor.yml ├── .codecov.yml ├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .ubsan-ignorelist ├── CMakeLists.txt ├── Jamfile ├── LICENSE ├── README.md ├── build └── Jamfile.v2 ├── data ├── README.zone_spec_csv_file └── date_time_zonespec.csv ├── doc ├── build.jam ├── index.html └── time_duration_inherit.png ├── example ├── Jamfile ├── gregorian │ ├── Jamfile.v2 │ ├── date_serialization_demo.cpp │ ├── dates_as_strings.cpp │ ├── days_alive.cpp │ ├── days_between_new_years.cpp │ ├── days_since_year_start.cpp │ ├── days_till_new_year.cpp │ ├── end_of_month_day.cpp │ ├── find_last_day_of_months.cpp │ ├── localization.cpp │ ├── month_add.cpp │ ├── period_calc.cpp │ ├── print_holidays.cpp │ └── print_month.cpp ├── local_time │ ├── calc_rules.cpp │ ├── flight.cpp │ ├── local_date_time.cpp │ ├── seconds_since_epoch.cpp │ └── simple_time_zone.cpp ├── posix_time │ ├── Jamfile.v2 │ ├── local_utc_conversion.cpp │ ├── print_hours.cpp │ ├── time_math.cpp │ └── time_periods.cpp └── tutorial │ └── io_tutorial.cpp ├── include └── boost │ ├── date_time.hpp │ └── date_time │ ├── adjust_functors.hpp │ ├── c_local_time_adjustor.hpp │ ├── c_time.hpp │ ├── compiler_config.hpp │ ├── constrained_value.hpp │ ├── date.hpp │ ├── date_clock_device.hpp │ ├── date_defs.hpp │ ├── date_duration.hpp │ ├── date_duration_types.hpp │ ├── date_facet.hpp │ ├── date_format_simple.hpp │ ├── date_formatting.hpp │ ├── date_formatting_limited.hpp │ ├── date_formatting_locales.hpp │ ├── date_generator_formatter.hpp │ ├── date_generator_parser.hpp │ ├── date_generators.hpp │ ├── date_iterator.hpp │ ├── date_names_put.hpp │ ├── date_parsing.hpp │ ├── dst_rules.hpp │ ├── dst_transition_generators.hpp │ ├── filetime_functions.hpp │ ├── find_match.hpp │ ├── format_date_parser.hpp │ ├── gregorian │ ├── conversion.hpp │ ├── formatters.hpp │ ├── formatters_limited.hpp │ ├── greg_calendar.hpp │ ├── greg_date.hpp │ ├── greg_day.hpp │ ├── greg_day_of_year.hpp │ ├── greg_duration.hpp │ ├── greg_duration_types.hpp │ ├── greg_facet.hpp │ ├── greg_month.hpp │ ├── greg_serialize.hpp │ ├── greg_weekday.hpp │ ├── greg_year.hpp │ ├── greg_ymd.hpp │ ├── gregorian.hpp │ ├── gregorian_io.hpp │ ├── gregorian_types.hpp │ └── parsers.hpp │ ├── gregorian_calendar.hpp │ ├── gregorian_calendar.ipp │ ├── int_adapter.hpp │ ├── iso_format.hpp │ ├── local_time │ ├── conversion.hpp │ ├── custom_time_zone.hpp │ ├── date_duration_operators.hpp │ ├── dst_transition_day_rules.hpp │ ├── local_date_time.hpp │ ├── local_time.hpp │ ├── local_time_io.hpp │ ├── local_time_types.hpp │ ├── posix_time_zone.hpp │ └── tz_database.hpp │ ├── local_time_adjustor.hpp │ ├── local_timezone_defs.hpp │ ├── locale_config.hpp │ ├── microsec_time_clock.hpp │ ├── parse_format_base.hpp │ ├── period.hpp │ ├── period_formatter.hpp │ ├── period_parser.hpp │ ├── posix_time │ ├── conversion.hpp │ ├── date_duration_operators.hpp │ ├── posix_time.hpp │ ├── posix_time_config.hpp │ ├── posix_time_duration.hpp │ ├── posix_time_io.hpp │ ├── posix_time_legacy_io.hpp │ ├── posix_time_system.hpp │ ├── posix_time_types.hpp │ ├── ptime.hpp │ ├── time_formatters.hpp │ ├── time_formatters_limited.hpp │ ├── time_parsers.hpp │ ├── time_period.hpp │ └── time_serialize.hpp │ ├── special_defs.hpp │ ├── special_values_formatter.hpp │ ├── special_values_parser.hpp │ ├── string_convert.hpp │ ├── string_parse_tree.hpp │ ├── strings_from_facet.hpp │ ├── time.hpp │ ├── time_clock.hpp │ ├── time_defs.hpp │ ├── time_duration.hpp │ ├── time_facet.hpp │ ├── time_formatting_streams.hpp │ ├── time_iterator.hpp │ ├── time_parsing.hpp │ ├── time_resolution_traits.hpp │ ├── time_system_counted.hpp │ ├── time_system_split.hpp │ ├── time_zone_base.hpp │ ├── time_zone_names.hpp │ ├── tz_db_base.hpp │ ├── wrapping_int.hpp │ └── year_month_day.hpp ├── index.html ├── meta └── libraries.json ├── src ├── date_time.doc ├── gregorian │ ├── date_generators.cpp │ ├── greg_month.cpp │ ├── greg_names.hpp │ ├── greg_weekday.cpp │ └── gregorian_types.cpp └── posix_time │ └── posix_time_types.cpp ├── test ├── Jamfile.v2 ├── gregorian │ ├── testcurrent_day.cpp │ ├── testdate.cpp │ ├── testdate_duration.cpp │ ├── testdate_facet_new.cpp │ ├── testdate_input_facet.cpp │ ├── testdate_iterator.cpp │ ├── testfacet.cpp │ ├── testformat_date_parser.cpp │ ├── testformatters.cpp │ ├── testgenerators.cpp │ ├── testgreg_cal.cpp │ ├── testgreg_day.cpp │ ├── testgreg_durations.cpp │ ├── testgreg_month.cpp │ ├── testgreg_serialize.cpp │ ├── testgreg_wstream.cpp │ ├── testgreg_year.cpp │ ├── testparse_date.cpp │ └── testperiod.cpp ├── local_time │ ├── README.poorly_formed_zonespec │ ├── poorly_formed_zonespec.csv │ ├── testclocks.cpp │ ├── testcustom_time_zone.cpp │ ├── testdst_transition_day_rule.cpp │ ├── testlocal_time.cpp │ ├── testlocal_time_facet.cpp │ ├── testlocal_time_input_facet.cpp │ ├── testlocal_time_iterator.cpp │ ├── testlocal_time_period.cpp │ ├── testposix_time_zone.cpp │ ├── testtz_database.cpp │ ├── testwcustom_time_zone.cpp │ └── testwposix_time_zone.cpp ├── posix_time │ ├── compile_fail │ │ ├── hours_special_value.cpp │ │ ├── millisec_special_value.cpp │ │ ├── minutes_special_value.cpp │ │ └── seconds_special_value.cpp │ ├── testc_local_adjustor.cpp │ ├── testclock.cpp │ ├── testdst_rules.cpp │ ├── testduration.cpp │ ├── testfiletime_functions.cpp │ ├── testformatters.cpp │ ├── testgreg_duration_operators.cpp │ ├── testiterator.cpp │ ├── testlocal_adjustor.cpp │ ├── testmicrosec_time_clock.cpp │ ├── testparse_time.cpp │ ├── testperiod.cpp │ ├── teststreams.cpp │ ├── testtime.cpp │ ├── testtime_facet.cpp │ ├── testtime_formatters.cpp │ ├── testtime_input_facet.cpp │ ├── testtime_period.cpp │ ├── testtime_serialize.cpp │ ├── testtime_serialize_versioning.cpp │ └── testtime_wstream.cpp ├── self_contained_header.cpp ├── testconstrained_value.cpp ├── testfrmwk.hpp ├── testfrom_facet.cpp ├── testgeneric_period.cpp ├── testgregorian_calendar.cpp ├── testint64_range.cpp ├── testint_adapter.cpp ├── testmisc.cpp ├── testtime_resolution_traits.cpp └── testwrapping_int.cpp └── xmldoc ├── Jamfile.v2 ├── README ├── acknowledgements.xml ├── buildinfo.xml ├── calculations.xml ├── changes.xml ├── conceptual.xml ├── custom_time_zone.xml ├── date_algorithms.xml ├── date_class.xml ├── date_duration.xml ├── date_facet.xml ├── date_input_facet.xml ├── date_iterators.xml ├── date_period.xml ├── date_time.xml ├── date_time_docs_howto.html ├── date_time_fo_stylesheet.xsl ├── date_time_io.xml ├── design_concepts.xml ├── design_goals.xml ├── details.xml ├── domain_concepts.xml ├── doxy.xml ├── ex_calc_rules.xml ├── ex_date_period_calc.xml ├── ex_dates_as_strings.xml ├── ex_days_alive.xml ├── ex_days_between_new_years.xml ├── ex_end_of_month_day.xml ├── ex_find_last_day_of_months.xml ├── ex_flight.xml ├── ex_local_utc_conversion.xml ├── ex_localization.xml ├── ex_meeting_planner.xml ├── ex_month_add.xml ├── ex_print_holidays.xml ├── ex_print_hours.xml ├── ex_print_month.xml ├── ex_seconds_since_epoch.xml ├── ex_simple_time_zone.xml ├── ex_time_math.xml ├── ex_time_periods.xml ├── examples.xml ├── exclusive_date_time.xml ├── format_flags.xml ├── gregorian.xml ├── gregorian_calendar.xml ├── io_objects.xml ├── io_tutorial.xml ├── license.xml ├── local_date_time.xml ├── local_time.xml ├── local_time_period.xml ├── motivation.xml ├── posix_time.xml ├── posix_time_zone.xml ├── ptime_class.xml ├── ref_tag_fix.pl ├── references.xml ├── serialization.xml ├── snap_to_details.xml ├── table_template.xml ├── terminology.xml ├── tests.xml ├── time_duration.xml ├── time_facet.xml ├── time_input_facet.xml ├── time_iterators.xml ├── time_period.xml ├── time_zone_base.xml ├── tradeoffs.xml ├── tz_database.xml └── usage_examples.xml /.codecov.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 - 2021 Alexander Grund 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | # 5 | # Sample codecov configuration file. Edit as required 6 | 7 | codecov: 8 | max_report_age: off 9 | require_ci_to_pass: yes 10 | notify: 11 | # Increase this if you have multiple coverage collection jobs 12 | after_n_builds: 2 13 | wait_for_ci: yes 14 | 15 | # Change how pull request comments look 16 | comment: 17 | layout: "reach,diff,flags,files,footer" 18 | 19 | # Ignore specific files or folders. Glob patterns are supported. 20 | # See https://docs.codecov.com/docs/ignoring-paths 21 | ignore: 22 | - libs/date_time/test/ 23 | - test 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/test_facet_file.out 2 | **/time_duration_serialization.* 3 | -------------------------------------------------------------------------------- /.ubsan-ignorelist: -------------------------------------------------------------------------------- 1 | # https://github.com/boostorg/serialization/issues/122 2 | vptr:/usr/include/c++/*/bits/ios_base.h 3 | # https://github.com/boostorg/serialization/issues/193 4 | # could not figure out how to suppress it 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake date_time` 2 | # Copyright 2020 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.5...3.16) 7 | 8 | project(boost_date_time VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_date_time 11 | src/gregorian/greg_month.cpp 12 | ) 13 | 14 | add_library(Boost::date_time ALIAS boost_date_time) 15 | 16 | target_include_directories(boost_date_time PUBLIC include) 17 | 18 | target_link_libraries(boost_date_time 19 | PUBLIC 20 | Boost::algorithm 21 | Boost::assert 22 | Boost::config 23 | Boost::core 24 | Boost::io 25 | Boost::lexical_cast 26 | Boost::numeric_conversion 27 | Boost::range 28 | Boost::smart_ptr 29 | Boost::static_assert 30 | Boost::throw_exception 31 | Boost::tokenizer 32 | Boost::type_traits 33 | Boost::utility 34 | Boost::winapi 35 | ) 36 | 37 | target_compile_definitions(boost_date_time 38 | PUBLIC BOOST_DATE_TIME_NO_LIB 39 | PRIVATE BOOST_DATE_TIME_SOURCE 40 | ) 41 | 42 | if(BUILD_SHARED_LIBS) 43 | target_compile_definitions(boost_date_time PUBLIC BOOST_DATE_TIME_DYN_LINK) 44 | else() 45 | target_compile_definitions(boost_date_time PUBLIC BOOST_DATE_TIME_STATIC_LINK) 46 | endif() 47 | 48 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 49 | 50 | add_subdirectory(test) 51 | 52 | endif() 53 | 54 | -------------------------------------------------------------------------------- /Jamfile: -------------------------------------------------------------------------------- 1 | # Boost.DateTime Library Jamfile 2 | # 3 | # Copyright (c) 2018 James E. King III 4 | # 5 | # Use, modification, and distribution are subject to the 6 | # Boost Software License, Version 1.0. (See accompanying file 7 | # LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | # please order by name to ease maintenance 10 | build-project example ; 11 | build-project test ; 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /build/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2002-2005 CrystalClear Software, Inc. 2 | # Use, modification and distribution is subject to the 3 | # Boost Software License, Version 1.0. (See accompanying 4 | # file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | # 6 | # date_time is now header only -- this file provides a stub for backward compatibility 7 | # 8 | 9 | 10 | project boost/date_time 11 | : requirements 12 | DATE_TIME_INLINE 13 | shared:BOOST_ALL_DYN_LINK=1 14 | : usage-requirements 15 | DATE_TIME_INLINE 16 | shared:BOOST_DATE_TIME_DYN_LINK=1 17 | : source-location ../src 18 | ; 19 | 20 | # greg_month.cpp is now just a stub so that there is 21 | # still a boost_date_time library to link for backward compatibility 22 | lib boost_date_time : gregorian/greg_month.cpp ; 23 | 24 | boost-install boost_date_time ; 25 | -------------------------------------------------------------------------------- /doc/build.jam: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 Rene Rivera 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | ############################################################################### 8 | alias boostdoc 9 | : ../xmldoc/date_time.xml 10 | : 11 | : ../xmldoc//date_time_autodoc ../xmldoc//gregorian_autodoc 12 | ../xmldoc//posix_time_autodoc ../xmldoc//local_time_autodoc 13 | : ; 14 | explicit boostdoc ; 15 | alias boostrelease ; 16 | explicit boostrelease ; 17 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/date_time/39714907b7d32ed8f005b5a01d1c2b885b5717b3/doc/index.html -------------------------------------------------------------------------------- /doc/time_duration_inherit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/date_time/39714907b7d32ed8f005b5a01d1c2b885b5717b3/doc/time_duration_inherit.png -------------------------------------------------------------------------------- /example/Jamfile: -------------------------------------------------------------------------------- 1 | project libs/date_time/example ; 2 | 3 | exe dates_as_strings : gregorian/dates_as_strings.cpp ; 4 | exe days_alive : gregorian/days_alive.cpp ; 5 | exe days_till_new_year : gregorian/days_till_new_year.cpp ; 6 | 7 | exe days_between_new_years : gregorian/days_between_new_years.cpp ; 8 | exe find_last_day_of_months : gregorian/find_last_day_of_months.cpp ; 9 | 10 | exe month_add : gregorian/month_add.cpp ; 11 | 12 | exe localization : gregorian/localization.cpp ; 13 | exe print_holidays : gregorian/print_holidays.cpp ; 14 | exe print_month : gregorian/print_month.cpp ; 15 | exe period_calc : gregorian/period_calc.cpp ; 16 | 17 | exe days_since_year_start : gregorian/days_since_year_start.cpp ; 18 | 19 | 20 | exe local_utc_conversion : posix_time/local_utc_conversion.cpp 21 | : BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 22 | ; 23 | 24 | exe print_hours : posix_time/print_hours.cpp 25 | : BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 26 | ; 27 | 28 | exe time_math : posix_time/time_math.cpp 29 | : BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 30 | ; 31 | 32 | exe time_periods : posix_time/time_periods.cpp 33 | : BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 34 | ; 35 | 36 | exe simple_time_zone : local_time/simple_time_zone.cpp ; 37 | exe calc_rules : local_time/calc_rules.cpp ; 38 | exe seconds_since_epoch : local_time/seconds_since_epoch.cpp ; 39 | exe flight : local_time/flight.cpp ; 40 | exe io_tutorial : tutorial/io_tutorial.cpp ; 41 | 42 | # Copyright (c) 2002-2005 43 | # CrystalClear Software, Inc. 44 | # Subject to the Boost Software License, Version 1.0. 45 | # (See accompanying file LICENSE_1_0.txt or 46 | # http://www.boost.org/LICENSE_1_0.txt) 47 | 48 | -------------------------------------------------------------------------------- /example/gregorian/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2002-2006 CrystalClear Software, Inc. 2 | # Use, modification and distribution is subject to the 3 | # Boost Software License, Version 1.0. (See accompanying 4 | # file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | # 6 | 7 | project 8 | : requirements ../../build/boost_date_time 9 | ; 10 | 11 | exe dates_as_strings : dates_as_strings.cpp ; 12 | exe end_of_month_day : end_of_month_day.cpp ; 13 | exe period_calc : period_calc.cpp ; 14 | exe days_alive : days_alive.cpp ; 15 | exe print_holidays : print_holidays.cpp ; 16 | exe days_since_year_start : days_since_year_start.cpp ; 17 | exe print_month : print_month.cpp ; 18 | exe days_till_new_year : days_till_new_year.cpp ; 19 | exe date_localization : localization.cpp ; 20 | -------------------------------------------------------------------------------- /example/gregorian/dates_as_strings.cpp: -------------------------------------------------------------------------------- 1 | /* The following is a simple example that shows conversion of dates 2 | * to and from a std::string. 3 | * 4 | * Expected output: 5 | * 2001-Oct-09 6 | * 2001-10-09 7 | * Tuesday October 9, 2001 8 | * An expected exception is next: 9 | * Exception: Month number is out of range 1..12 10 | */ 11 | 12 | #include "boost/date_time/gregorian/gregorian.hpp" 13 | #include 14 | #include 15 | 16 | int 17 | main() 18 | { 19 | 20 | using namespace boost::gregorian; 21 | 22 | try { 23 | // The following date is in ISO 8601 extended format (CCYY-MM-DD) 24 | std::string s("2001-10-9"); //2001-October-09 25 | date d(from_simple_string(s)); 26 | std::cout << to_simple_string(d) << std::endl; 27 | 28 | //Read ISO 8601 Standard(CCYYMMDD) and output ISO 8601 Extended 29 | std::string ud("20011009"); //2001-Oct-09 30 | date d1(from_undelimited_string(ud)); 31 | std::cout << to_iso_extended_string(d1) << std::endl; 32 | 33 | //Output the parts of the date - Tuesday October 9, 2001 34 | date::ymd_type ymd = d1.year_month_day(); 35 | greg_weekday wd = d1.day_of_week(); 36 | std::cout << wd.as_long_string() << " " 37 | << ymd.month.as_long_string() << " " 38 | << ymd.day << ", " << ymd.year 39 | << std::endl; 40 | 41 | //Let's send in month 25 by accident and create an exception 42 | std::string bad_date("20012509"); //2001-??-09 43 | std::cout << "An expected exception is next: " << std::endl; 44 | date wont_construct(from_undelimited_string(bad_date)); 45 | //use wont_construct so compiler doesn't complain, but you wont get here! 46 | std::cout << "oh oh, you shouldn't reach this line: " 47 | << to_iso_string(wont_construct) << std::endl; 48 | } 49 | catch(std::exception& e) { 50 | std::cout << " Exception: " << e.what() << std::endl; 51 | } 52 | 53 | 54 | return 0; 55 | } 56 | 57 | /* Copyright 2001-2004: CrystalClear Software, Inc 58 | * http://www.crystalclearsoftware.com 59 | * 60 | * Subject to the Boost Software License, Version 1.0. 61 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 62 | */ 63 | 64 | -------------------------------------------------------------------------------- /example/gregorian/days_alive.cpp: -------------------------------------------------------------------------------- 1 | /* Short example that calculates the number of days since user was born. 2 | * Demonstrates comparisons of durations, use of the day_clock, 3 | * and parsing a date from a string. 4 | */ 5 | 6 | #include "boost/date_time/gregorian/gregorian.hpp" 7 | #include 8 | 9 | int 10 | main() 11 | { 12 | 13 | using namespace boost::gregorian; 14 | std::string s; 15 | std::cout << "Enter birth day YYYY-MM-DD (eg: 2002-02-01): "; 16 | std::cin >> s; 17 | try { 18 | date birthday(from_simple_string(s)); 19 | date today = day_clock::local_day(); 20 | days days_alive = today - birthday; 21 | days one_day(1); 22 | if (days_alive == one_day) { 23 | std::cout << "Born yesterday, very funny" << std::endl; 24 | } 25 | else if (days_alive < days(0)) { 26 | std::cout << "Not born yet, hmm: " << days_alive.days() 27 | << " days" < 11 | 12 | int 13 | main() 14 | { 15 | 16 | using namespace boost::gregorian; 17 | 18 | date today = day_clock::local_day(); 19 | partial_date new_years_day(1,Jan); 20 | //Subtract two dates to get a duration 21 | days days_since_year_start = today - new_years_day.get_date(today.year()); 22 | std::cout << "Days since Jan 1: " << days_since_year_start.days() 23 | << std::endl; 24 | 25 | days days_until_year_start = new_years_day.get_date(today.year()+1) - today; 26 | std::cout << "Days until next Jan 1: " << days_until_year_start.days() 27 | << std::endl; 28 | return 0; 29 | } 30 | 31 | 32 | /* Copyright 2001-2004: CrystalClear Software, Inc 33 | * http://www.crystalclearsoftware.com 34 | * 35 | * Subject to the Boost Software License, Version 1.0. 36 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 37 | */ 38 | 39 | -------------------------------------------------------------------------------- /example/gregorian/days_since_year_start.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "boost/date_time/gregorian/gregorian.hpp" 3 | #include 4 | 5 | int 6 | main() 7 | { 8 | 9 | using namespace boost::gregorian; 10 | 11 | date today = day_clock::local_day(); 12 | //Subtract two dates to get a duration 13 | date_duration days_since_year_start = today - date(today.year(),Jan,1); 14 | std::cout << "Days since Jan 1: " << days_since_year_start.days() 15 | << std::endl; 16 | return 0; 17 | } 18 | 19 | /* Copyright 2001-2004: CrystalClear Software, Inc 20 | * http://www.crystalclearsoftware.com 21 | * 22 | * Subject to the Boost Software License, Version 1.0. 23 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 24 | */ 25 | 26 | -------------------------------------------------------------------------------- /example/gregorian/days_till_new_year.cpp: -------------------------------------------------------------------------------- 1 | // This example displays the amount of time until new year's in days 2 | 3 | #include "boost/date_time/gregorian/gregorian.hpp" 4 | #include 5 | 6 | int 7 | main() 8 | { 9 | 10 | using namespace boost::gregorian; 11 | 12 | date::ymd_type today = day_clock::local_day_ymd(); 13 | date new_years_day(today.year + 1,1,1); 14 | date_duration dd = new_years_day - date(today); 15 | 16 | std::cout << "Days till new year: " << dd.days() << std::endl; 17 | return 0; 18 | } 19 | 20 | /* Copyright 2001-2004: CrystalClear Software, Inc 21 | * http://www.crystalclearsoftware.com 22 | * 23 | * Subject to the Boost Software License, Version 1.0. 24 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 25 | */ 26 | 27 | -------------------------------------------------------------------------------- /example/gregorian/end_of_month_day.cpp: -------------------------------------------------------------------------------- 1 | /* Simple program that uses the gregorian calendar to find the last 2 | * day of the month and then display the last day of every month left 3 | * in the year. 4 | */ 5 | 6 | #include "boost/date_time/gregorian/gregorian.hpp" 7 | #include 8 | 9 | int 10 | main() 11 | { 12 | using namespace boost::gregorian; 13 | 14 | std::cout << " Enter Year(ex: 2002): "; 15 | int year, month; 16 | std::cin >> year; 17 | std::cout << " Enter Month(1..12): "; 18 | std::cin >> month; 19 | try { 20 | int day = gregorian_calendar::end_of_month_day(year,month); 21 | date end_of_month(year,month,day); 22 | 23 | //Iterate thru by months -- 24 | month_iterator mitr(end_of_month,1); 25 | date start_of_next_year(year+1, Jan, 1); 26 | //loop thru the days and print each one 27 | while (mitr < start_of_next_year){ 28 | std::cout << to_simple_string(*mitr) << std::endl; 29 | ++mitr; 30 | } 31 | 32 | } 33 | catch(...) { 34 | std::cout << "Invalid Date Entered" << std::endl; 35 | } 36 | return 0; 37 | 38 | } 39 | 40 | /* Copyright 2001-2004: CrystalClear Software, Inc 41 | * http://www.crystalclearsoftware.com 42 | * 43 | * Subject to the Boost Software License, Version 1.0. 44 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 45 | */ 46 | 47 | -------------------------------------------------------------------------------- /example/gregorian/find_last_day_of_months.cpp: -------------------------------------------------------------------------------- 1 | /* Simple program that finds the last day of the given month, 2 | * then displays the last day of every month left in the given year. 3 | */ 4 | 5 | #include "boost/date_time/gregorian/gregorian.hpp" 6 | #include 7 | 8 | int 9 | main() 10 | { 11 | using namespace boost::gregorian; 12 | 13 | greg_year year(1400); 14 | greg_month month(1); 15 | 16 | // get a month and a year from the user 17 | try { 18 | greg_year::value_type y; 19 | greg_month::value_type m; 20 | std::cout << " Enter Year(ex: 2002): "; 21 | std::cin >> y; 22 | year = greg_year(y); 23 | std::cout << " Enter Month(1..12): "; 24 | std::cin >> m; 25 | month = greg_month(m); 26 | } 27 | catch(const bad_year& by) { 28 | std::cout << "Invalid Year Entered: " << by.what() << '\n' 29 | << "Using minimum values for month and year." << std::endl; 30 | } 31 | catch(const bad_month& bm) { 32 | std::cout << "Invalid Month Entered" << bm.what() << '\n' 33 | << "Using minimum value for month. " << std::endl; 34 | } 35 | 36 | date start_of_next_year(year+1, Jan, 1); 37 | date d(year, month, 1); 38 | 39 | // add another month to d until we enter the next year. 40 | while (d < start_of_next_year){ 41 | std::cout << to_simple_string(d.end_of_month()) << std::endl; 42 | d += months(1); 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | /* Copyright 2001-2005: CrystalClear Software, Inc 49 | * http://www.crystalclearsoftware.com 50 | * 51 | * Subject to the Boost Software License, Version 1.0. 52 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 53 | */ 54 | 55 | -------------------------------------------------------------------------------- /example/gregorian/month_add.cpp: -------------------------------------------------------------------------------- 1 | /* Simple program that uses the gregorian calendar to progress by exactly 2 | * one month, regardless of how many days are in that month. 3 | * 4 | * This method can be used as an alternative to iterators 5 | */ 6 | 7 | #include "boost/date_time/gregorian/gregorian.hpp" 8 | #include 9 | 10 | int 11 | main() 12 | { 13 | 14 | using namespace boost::gregorian; 15 | 16 | date d = day_clock::local_day(); 17 | date d2 = d + months(1); 18 | date d3 = d - months(1); 19 | std::cout << "Today is: " << to_simple_string(d) << ".\n" 20 | << "One month from today will be: " << to_simple_string(d2) << ".\n" 21 | << "One month ago was: " << to_simple_string(d3) 22 | << std::endl; 23 | std::cout << "******** Warning read this ***********************\n"; 24 | std::cout << "Be aware that adding a month is not exactly like regular numeric math.\n" 25 | << "Addition/Subtraction of months will 'snap to the end' of a month that\n" 26 | << "is shorter than the current month. For example consider " 27 | << "Jan 31, 2004 + (1 month)\n"; 28 | date d4(2004, Jan, 31); 29 | date d5 = d4 + months(1); 30 | std::cout << "Result is: " << to_simple_string(d5) 31 | << std::endl; 32 | 33 | std::cout << "\nSo what does this mean? It means the result of adding months is order\n" 34 | << "dependent, non-commutative, and may create problems for applications.\n" 35 | << "Consider: \n" 36 | << "Jan 30, 2004 + (1 month) + (1 month) != Jan 30, 2004 + (2 months)\n" 37 | << "Why not? Because Jan 30, 2004 + 1 month is Feb 29 + 1 month is Mar 31st.\n" 38 | << "while Jan 30, 2004 + 2 months is Mar 30th.\n" 39 | << "All of this clears up as long as all the starting dates before the 28th of\n" 40 | << "the month -- then all the behavior follows classical mathematical rules.\n"; 41 | 42 | date d6(2004, Jan, 30); 43 | date d7 = d6 + months(1) + months(1); 44 | date d8 = d6 + months(2); 45 | std::cout << "2004-01-30 + (1 month) + (1 month) is: " << to_simple_string(d7) << ".\n" 46 | << "2004-01-30 + (2 months) is: " << to_simple_string(d8) 47 | << std::endl; 48 | 49 | return 0; 50 | } 51 | 52 | /* Copyright 2001-2005: CrystalClear Software, Inc 53 | * http://www.crystalclearsoftware.com 54 | * 55 | * Subject to the Boost Software License, Version 1.0. 56 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 57 | */ 58 | 59 | -------------------------------------------------------------------------------- /example/gregorian/period_calc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This example demonstrates a simple use of periods for the calculation 3 | of date information. 4 | 5 | The example calculates if a given date is a weekend or holiday 6 | given an exclusion set. That is, each weekend or holiday is 7 | entered into the set as a time interval. Then if a given date 8 | is contained within any of the intervals it is considered to 9 | be within the exclusion set and hence is a offtime. 10 | 11 | Output: 12 | Number Excluded Periods: 5 13 | 20020202/20020203 14 | 20020209/20020210 15 | 20020212/20020212 16 | 20020216/20020217 17 | In Exclusion Period: 20020216 --> 20020216/20020217 18 | 20020223/20020224 19 | 20 | */ 21 | 22 | 23 | #include "boost/date_time/gregorian/gregorian.hpp" 24 | #include 25 | #include 26 | #include 27 | 28 | typedef std::set date_period_set; 29 | 30 | //Simple population of the exclusion set 31 | date_period_set 32 | generateExclusion() 33 | { 34 | using namespace boost::gregorian; 35 | date_period periods_array[] = 36 | { date_period(date(2002,Feb,2), date(2002,Feb,4)),//weekend of 2nd-3rd 37 | date_period(date(2002,Feb,9), date(2002,Feb,11)), 38 | date_period(date(2002,Feb,16), date(2002,Feb,18)), 39 | date_period(date(2002,Feb,23), date(2002,Feb,25)), 40 | date_period(date(2002,Feb,12), date(2002,Feb,13))//a random holiday 2-12 41 | }; 42 | const int num_periods = sizeof(periods_array)/sizeof(date_period); 43 | 44 | date_period_set ps; 45 | //insert the periods in the set 46 | std::insert_iterator itr(ps, ps.begin()); 47 | std::copy(periods_array, periods_array+num_periods, itr ); 48 | return ps; 49 | 50 | } 51 | 52 | 53 | int main() 54 | { 55 | using namespace boost::gregorian; 56 | 57 | date_period_set ps = generateExclusion(); 58 | std::cout << "Number Excluded Periods: " << ps.size() << std::endl; 59 | 60 | date d(2002,Feb,16); 61 | date_period_set::const_iterator i = ps.begin(); 62 | //print the periods, check for containment 63 | for (;i != ps.end(); i++) { 64 | std::cout << to_iso_string(*i) << std::endl; 65 | //if date is in exclusion period then print it 66 | if (i->contains(d)) { 67 | std::cout << "In Exclusion Period: " 68 | << to_iso_string(d) << " --> " << to_iso_string(*i) 69 | << std::endl; 70 | } 71 | } 72 | 73 | return 0; 74 | 75 | } 76 | 77 | 78 | 79 | 80 | /* Copyright 2001-2004: CrystalClear Software, Inc 81 | * http://www.crystalclearsoftware.com 82 | * 83 | * Subject to the Boost Software License, Version 1.0. 84 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 85 | */ 86 | 87 | -------------------------------------------------------------------------------- /example/gregorian/print_holidays.cpp: -------------------------------------------------------------------------------- 1 | /* Generate a set of dates using a collection of date generators 2 | * Output looks like: 3 | * Enter Year: 2002 4 | * 2002-Jan-01 [Tue] 5 | * 2002-Jan-21 [Mon] 6 | * 2002-Feb-12 [Tue] 7 | * 2002-Jul-04 [Thu] 8 | * 2002-Sep-02 [Mon] 9 | * 2002-Nov-28 [Thu] 10 | * 2002-Dec-25 [Wed] 11 | * Number Holidays: 7 12 | */ 13 | 14 | #include "boost/date_time/gregorian/gregorian.hpp" 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | void 22 | print_date(boost::gregorian::date d) 23 | { 24 | using namespace boost::gregorian; 25 | #if defined(BOOST_DATE_TIME_NO_LOCALE) 26 | std::cout << to_simple_string(d) << " [" << d.day_of_week() << "]\n"; 27 | #else 28 | std::cout << d << " [" << d.day_of_week() << "]\n"; 29 | #endif 30 | } 31 | 32 | 33 | int 34 | main() { 35 | 36 | using namespace boost::gregorian; 37 | 38 | std::cout << "Enter Year: "; 39 | greg_year::value_type year; 40 | std::cin >> year; 41 | 42 | //define a collection of holidays fixed by month and day 43 | std::vector holidays; 44 | holidays.push_back(new partial_date(1,Jan)); //Western New Year 45 | holidays.push_back(new partial_date(4,Jul)); //US Independence Day 46 | holidays.push_back(new partial_date(25, Dec));//Christmas day 47 | 48 | 49 | //define a shorthand for the nth_day_of_the_week_in_month function object 50 | typedef nth_day_of_the_week_in_month nth_dow; 51 | 52 | //US labor day 53 | holidays.push_back(new nth_dow(nth_dow::first, Monday, Sep)); 54 | //MLK Day 55 | holidays.push_back(new nth_dow(nth_dow::third, Monday, Jan)); 56 | //Pres day 57 | holidays.push_back(new nth_dow(nth_dow::second, Tuesday, Feb)); 58 | //Thanksgiving 59 | holidays.push_back(new nth_dow(nth_dow::fourth, Thursday, Nov)); 60 | 61 | typedef std::set date_set; 62 | date_set all_holidays; 63 | 64 | for(std::vector::iterator it = holidays.begin(); 65 | it != holidays.end(); ++it) 66 | { 67 | all_holidays.insert((*it)->get_date(year)); 68 | } 69 | 70 | //print the holidays to the screen 71 | std::for_each(all_holidays.begin(), all_holidays.end(), print_date); 72 | std::cout << "Number Holidays: " << all_holidays.size() << std::endl; 73 | 74 | return 0; 75 | } 76 | 77 | /* Copyright 2001-2004: CrystalClear Software, Inc 78 | * http://www.crystalclearsoftware.com 79 | * 80 | * Subject to the Boost Software License, Version 1.0. 81 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 82 | */ 83 | 84 | -------------------------------------------------------------------------------- /example/gregorian/print_month.cpp: -------------------------------------------------------------------------------- 1 | /* This example prints all the dates in a month. It demonstrates 2 | * the use of iterators as well as functions of the gregorian_calendar 3 | * 4 | * Output: 5 | * Enter Year: 2002 6 | * Enter Month(1..12): 2 7 | * 2002-Feb-01 [Fri] 8 | * 2002-Feb-02 [Sat] 9 | * 2002-Feb-03 [Sun] 10 | * 2002-Feb-04 [Mon] 11 | * 2002-Feb-05 [Tue] 12 | * 2002-Feb-06 [Wed] 13 | * 2002-Feb-07 [Thu] 14 | */ 15 | 16 | #include "boost/date_time/gregorian/gregorian.hpp" 17 | #include 18 | 19 | int 20 | main() 21 | { 22 | using namespace boost::gregorian; 23 | 24 | std::cout << "Enter Year: "; 25 | greg_year::value_type year; 26 | greg_month::value_type month; 27 | std::cin >> year; 28 | std::cout << "Enter Month(1..12): "; 29 | std::cin >> month; 30 | 31 | try { 32 | //Use the calendar to get the last day of the month 33 | greg_day::value_type eom_day = gregorian_calendar::end_of_month_day(year,month); 34 | date endOfMonth(year,month,eom_day); 35 | 36 | //construct an iterator starting with firt day of the month 37 | day_iterator ditr(date(year,month,1)); 38 | //loop thru the days and print each one 39 | for (; ditr <= endOfMonth; ++ditr) { 40 | #if defined(BOOST_DATE_TIME_NO_LOCALE) 41 | std::cout << to_simple_string(*ditr) << " [" 42 | #else 43 | std::cout << *ditr << " [" 44 | #endif 45 | << ditr->day_of_week() << " week: " 46 | << ditr->week_number() << "]" 47 | << std::endl; 48 | } 49 | } 50 | catch(std::exception& e) { 51 | 52 | std::cout << "Error bad date, check your entry: \n" 53 | << " Details: " << e.what() << std::endl; 54 | } 55 | return 0; 56 | } 57 | 58 | /* Copyright 2001-2004: CrystalClear Software, Inc 59 | * http://www.crystalclearsoftware.com 60 | * 61 | * Subject to the Boost Software License, Version 1.0. 62 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 63 | */ 64 | 65 | -------------------------------------------------------------------------------- /example/local_time/calc_rules.cpp: -------------------------------------------------------------------------------- 1 | /* A simple example for creating various dst_calc_rule instances 2 | */ 3 | 4 | #include "boost/date_time/gregorian/gregorian.hpp" 5 | #include "boost/date_time/local_time/local_time.hpp" 6 | #include 7 | 8 | int 9 | main() 10 | { 11 | using namespace boost; 12 | using namespace local_time; 13 | using namespace gregorian; 14 | 15 | /***** create the necessary date_generator objects *****/ 16 | // starting generators 17 | first_day_of_the_week_in_month fd_start(Sunday, May); 18 | last_day_of_the_week_in_month ld_start(Sunday, May); 19 | nth_day_of_the_week_in_month nkd_start(nth_day_of_the_week_in_month::third, 20 | Sunday, May); 21 | partial_date pd_start(1, May); 22 | // ending generators 23 | first_day_of_the_week_in_month fd_end(Sunday, Oct); 24 | last_day_of_the_week_in_month ld_end(Sunday, Oct); 25 | nth_day_of_the_week_in_month nkd_end(nth_day_of_the_week_in_month::third, 26 | Sunday, Oct); 27 | partial_date pd_end(31, Oct); 28 | 29 | /***** create the various dst_calc_rule objects *****/ 30 | dst_calc_rule_ptr pdr(new partial_date_dst_rule(pd_start, pd_end)); 31 | dst_calc_rule_ptr flr(new first_last_dst_rule(fd_start, ld_end)); 32 | dst_calc_rule_ptr llr(new last_last_dst_rule(ld_start, ld_end)); 33 | dst_calc_rule_ptr nlr(new nth_last_dst_rule(nkd_start, ld_end)); 34 | dst_calc_rule_ptr ndr(new nth_day_of_the_week_in_month_dst_rule(nkd_start, nkd_end)); 35 | 36 | std::cout << "Program run successfully" << std::endl; 37 | 38 | return 0; 39 | } 40 | 41 | /* Copyright 2001-2005: CrystalClear Software, Inc 42 | * http://www.crystalclearsoftware.com 43 | * 44 | * Subject to the Boost Software License, Version 1.0. 45 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 46 | */ 47 | 48 | -------------------------------------------------------------------------------- /example/local_time/flight.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "boost/date_time/local_time/local_time.hpp" 3 | #include 4 | 5 | /* This example shows a program that calculates the arrival time of a plane 6 | * that flys from Phoenix to New York. During the flight New York shifts 7 | * into daylight savings time (Phoenix doesn't because Arizona doesn't use 8 | * DST). 9 | * 10 | * 11 | */ 12 | 13 | int main() 14 | { 15 | using namespace boost::gregorian; 16 | using namespace boost::local_time; 17 | using namespace boost::posix_time; 18 | 19 | 20 | //setup some timezones for creating and adjusting local times 21 | //This user editable file can be found in libs/date_time/data. 22 | tz_database tz_db; 23 | try { 24 | tz_db.load_from_file("../../data/date_time_zonespec.csv"); 25 | }catch(const data_not_accessible& dna) { 26 | std::cerr << "Error with time zone data file: " << dna.what() << std::endl; 27 | exit(EXIT_FAILURE); 28 | }catch(const bad_field_count& bfc) { 29 | std::cerr << "Error with time zone data file: " << bfc.what() << std::endl; 30 | exit(EXIT_FAILURE); 31 | } 32 | time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York"); 33 | //Use a newly created time zone rule 34 | time_zone_ptr phx_tz(new posix_time_zone("MST-07:00:00")); 35 | 36 | //local departure time in Phoenix is 11 pm on March 13 2010 37 | // (NY changes to DST on March 14 at 2 am) 38 | local_date_time phx_departure(date(2010, Mar, 13), hours(23), 39 | phx_tz, 40 | local_date_time::NOT_DATE_TIME_ON_ERROR); 41 | local_date_time nyc_departure = phx_departure.local_time_in(nyc_tz); 42 | 43 | time_duration flight_length = hours(4) + minutes(30); 44 | local_date_time phx_arrival = phx_departure + flight_length; 45 | local_date_time nyc_arrival = phx_arrival.local_time_in(nyc_tz); 46 | 47 | std::cout << "departure PHX time: " << phx_departure << std::endl; 48 | std::cout << "departure NYC time: " << nyc_departure << std::endl; 49 | std::cout << "arrival PHX time: " << phx_arrival << std::endl; 50 | std::cout << "arrival NYC time: " << nyc_arrival << std::endl; 51 | 52 | } 53 | 54 | 55 | /* Copyright 2005: CrystalClear Software, Inc 56 | * http://www.crystalclearsoftware.com 57 | * 58 | * Subject to the Boost Software License, Version 1.0. 59 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 60 | */ 61 | -------------------------------------------------------------------------------- /example/local_time/local_date_time.cpp: -------------------------------------------------------------------------------- 1 | #include "boost/date_time/gregorian/gregorian.hpp" 2 | #include "boost/date_time/posix_time/posix_time.hpp" 3 | #include "boost/date_time/local_time/local_time.hpp" 4 | #include 5 | #include 6 | 7 | int main() { 8 | using namespace boost::gregorian; 9 | using namespace boost::posix_time; 10 | using namespace boost::local_time; 11 | 12 | tz_database tz_db; 13 | try { 14 | tz_db.load_from_file("../../data/date_time_zonespec.csv"); 15 | }catch(data_not_accessible dna) { 16 | std::cerr << "Error with time zone data file: " << dna.what() << std::endl; 17 | exit(EXIT_FAILURE); 18 | }catch(bad_field_count bfc) { 19 | std::cerr << "Error with time zone data file: " << bfc.what() << std::endl; 20 | exit(EXIT_FAILURE); 21 | } 22 | 23 | time_zone_ptr nyc = tz_db.time_zone_from_region("America/New_York"); 24 | local_date_time ny_time(date(2004, Aug, 30), hours(10), nyc, true); 25 | 26 | typedef boost::date_time::time_facet ldt_facet; 27 | ldt_facet* timefacet = new ldt_facet("%Y-%b-%d %H:%M:%S""%F %Z"); 28 | std::locale loc(std::locale::classic(), timefacet); 29 | 30 | std::cout << ny_time << std::endl; 31 | // 2004-Aug-30 10:00:00 EDT 32 | std::cout.imbue(loc); 33 | std::cout << ny_time << std::endl; 34 | // 2004-Aug-30 10:00:00 Eastern Daylight Time 35 | 36 | return 0; 37 | } 38 | 39 | 40 | /* Copyright 2004-2005: CrystalClear Software, Inc 41 | * http://www.crystalclearsoftware.com 42 | * 43 | * Subject to the Boost Software License, Version 1.0. 44 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 45 | */ 46 | -------------------------------------------------------------------------------- /example/local_time/seconds_since_epoch.cpp: -------------------------------------------------------------------------------- 1 | /* This example demonstrates the use of the time zone database and 2 | * local time to calculate the number of seconds since the UTC 3 | * time_t epoch 1970-01-01 00:00:00. Note that the selected timezone 4 | * could be any timezone supported in the time zone database file which 5 | * can be modified and updated as needed by the user. 6 | * 7 | * To solve this problem the following steps are required: 8 | * 1) Get a timezone from the tz database for the local time 9 | * 2) Construct a local time using the timezone 10 | * 3) Construct a posix_time::ptime for the time_t epoch time 11 | * 4) Convert the local_time to utc and subtract the epoch time 12 | * 13 | */ 14 | 15 | #include "boost/date_time/local_time/local_time.hpp" 16 | #include 17 | 18 | int main() 19 | { 20 | using namespace boost::gregorian; 21 | using namespace boost::local_time; 22 | using namespace boost::posix_time; 23 | 24 | tz_database tz_db; 25 | try { 26 | tz_db.load_from_file("../data/date_time_zonespec.csv"); 27 | }catch(const data_not_accessible& dna) { 28 | std::cerr << "Error with time zone data file: " << dna.what() << std::endl; 29 | exit(EXIT_FAILURE); 30 | }catch(const bad_field_count& bfc) { 31 | std::cerr << "Error with time zone data file: " << bfc.what() << std::endl; 32 | exit(EXIT_FAILURE); 33 | } 34 | 35 | time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York"); 36 | date in_date(2004,10,04); 37 | time_duration td(12,14,32); 38 | // construct with local time value 39 | // create not-a-date-time if invalid (eg: in dst transition) 40 | local_date_time nyc_time(in_date, 41 | td, 42 | nyc_tz, 43 | local_date_time::NOT_DATE_TIME_ON_ERROR); 44 | 45 | std::cout << nyc_time << std::endl; 46 | 47 | ptime time_t_epoch(date(1970,1,1)); 48 | std::cout << time_t_epoch << std::endl; 49 | 50 | // first convert nyc_time to utc via the utc_time() 51 | // call and subtract the ptime. 52 | time_duration diff = nyc_time.utc_time() - time_t_epoch; 53 | 54 | //Expected 1096906472 55 | std::cout << "Seconds diff: " << diff.total_seconds() << std::endl; 56 | 57 | } 58 | 59 | 60 | /* Copyright 2005: CrystalClear Software, Inc 61 | * http://www.crystalclearsoftware.com 62 | * 63 | * Subject to the Boost Software License, Version 1.0. 64 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 65 | */ 66 | -------------------------------------------------------------------------------- /example/posix_time/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2002-2005 CrystalClear Software, Inc. 2 | # Use, modification and distribution is subject to the 3 | # Boost Software License, Version 1.0. (See accompanying 4 | # file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | project 7 | : requirements ../../build/boost_date_time 8 | ; 9 | 10 | exe time_math : time_math.cpp ; 11 | exe local_utc_conversion : local_utc_conversion.cpp ; 12 | exe print_hours : print_hours.cpp ; 13 | exe time_periods : time_periods.cpp ; 14 | -------------------------------------------------------------------------------- /example/posix_time/print_hours.cpp: -------------------------------------------------------------------------------- 1 | /* Print the remaining hours of the day 2 | * Uses the clock to get the local time 3 | * Use an iterator to iterate over the remaining hours 4 | * Retrieve the date part from a time 5 | * 6 | * Expected Output something like: 7 | * 8 | * 2002-Mar-08 16:30:59 9 | * 2002-Mar-08 17:30:59 10 | * 2002-Mar-08 18:30:59 11 | * 2002-Mar-08 19:30:59 12 | * 2002-Mar-08 20:30:59 13 | * 2002-Mar-08 21:30:59 14 | * 2002-Mar-08 22:30:59 15 | * 2002-Mar-08 23:30:59 16 | * Time left till midnight: 07:29:01 17 | */ 18 | 19 | #include "boost/date_time/posix_time/posix_time.hpp" 20 | #include 21 | 22 | int 23 | main() 24 | { 25 | using namespace boost::posix_time; 26 | using namespace boost::gregorian; 27 | 28 | //get the current time from the clock -- one second resolution 29 | ptime now = second_clock::local_time(); 30 | //Get the date part out of the time 31 | date today = now.date(); 32 | date tomorrow = today + days(1); 33 | ptime tomorrow_start(tomorrow); //midnight 34 | 35 | //iterator adds by one hour 36 | time_iterator titr(now,hours(1)); 37 | for (; titr < tomorrow_start; ++titr) { 38 | std::cout << to_simple_string(*titr) << std::endl; 39 | } 40 | 41 | time_duration remaining = tomorrow_start - now; 42 | std::cout << "Time left till midnight: " 43 | << to_simple_string(remaining) << std::endl; 44 | return 0; 45 | } 46 | 47 | /* Copyright 2001-2004: CrystalClear Software, Inc 48 | * http://www.crystalclearsoftware.com 49 | * 50 | * Subject to the Boost Software License, Version 1.0. 51 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 52 | */ 53 | 54 | -------------------------------------------------------------------------------- /example/posix_time/time_math.cpp: -------------------------------------------------------------------------------- 1 | /* Some simple examples of constructing and calculating with times 2 | * Output: 3 | * 2002-Feb-01 00:00:00 - 2002-Feb-01 05:04:02.001000000 = -5:04:02.001000000 4 | */ 5 | 6 | #include "boost/date_time/posix_time/posix_time.hpp" 7 | #include 8 | 9 | int 10 | main() 11 | { 12 | using namespace boost::posix_time; 13 | using namespace boost::gregorian; 14 | 15 | date d(2002,Feb,1); //an arbitrary date 16 | //construct a time by adding up some durations 17 | ptime t1(d, hours(5)+minutes(4)+seconds(2)+milliseconds(1)); 18 | //construct a new time by subtracting some times 19 | ptime t2 = t1 - hours(5)- minutes(4)- seconds(2)- milliseconds(1); 20 | //construct a duration by taking the difference between times 21 | time_duration td = t2 - t1; 22 | 23 | std::cout << to_simple_string(t2) << " - " 24 | << to_simple_string(t1) << " = " 25 | << to_simple_string(td) << std::endl; 26 | 27 | return 0; 28 | } 29 | 30 | /* Copyright 2001-2004: CrystalClear Software, Inc 31 | * http://www.crystalclearsoftware.com 32 | * 33 | * Subject to the Boost Software License, Version 1.0. 34 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 35 | */ 36 | 37 | -------------------------------------------------------------------------------- /example/posix_time/time_periods.cpp: -------------------------------------------------------------------------------- 1 | /* Some simple examples of constructing and calculating with times 2 | * Returns: 3 | * [2002-Feb-01 00:00:00/2002-Feb-01 23:59:59.999999999] contains 2002-Feb-01 03:00:05 4 | * [2002-Feb-01 00:00:00/2002-Feb-01 23:59:59.999999999] intersected with 5 | * [2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999] is 6 | * [2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999] 7 | */ 8 | 9 | #include "boost/date_time/posix_time/posix_time.hpp" 10 | #include 11 | 12 | using namespace boost::posix_time; 13 | using namespace boost::gregorian; 14 | 15 | //Create a simple period class to contain all the times in a day 16 | class day_period : public time_period 17 | { 18 | public: 19 | day_period(date d) : time_period(ptime(d),//midnight 20 | ptime(d,hours(24))) 21 | {} 22 | 23 | }; 24 | 25 | int 26 | main() 27 | { 28 | 29 | date d(2002,Feb,1); //an arbitrary date 30 | //a period that represents a day 31 | day_period dp(d); 32 | ptime t(d, hours(3)+seconds(5)); //an arbitray time on that day 33 | if (dp.contains(t)) { 34 | std::cout << to_simple_string(dp) << " contains " 35 | << to_simple_string(t) << std::endl; 36 | } 37 | //a period that represents part of the day 38 | time_period part_of_day(ptime(d, hours(0)), t); 39 | //intersect the 2 periods and print the results 40 | if (part_of_day.intersects(dp)) { 41 | time_period result = part_of_day.intersection(dp); 42 | std::cout << to_simple_string(dp) << " intersected with\n" 43 | << to_simple_string(part_of_day) << " is \n" 44 | << to_simple_string(result) << std::endl; 45 | } 46 | 47 | 48 | return 0; 49 | } 50 | 51 | 52 | /* Copyright 2001-2004: CrystalClear Software, Inc 53 | * http://www.crystalclearsoftware.com 54 | * 55 | * Subject to the Boost Software License, Version 1.0. 56 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 57 | */ 58 | 59 | -------------------------------------------------------------------------------- /include/boost/date_time.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_DATE_TIME_ALL_HPP___ 2 | #define BOOST_DATE_TIME_ALL_HPP___ 3 | 4 | /* Copyright (c) 2006 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | // See www.boost.org/libs/date_time for documentation. 13 | 14 | //gregorian and posix time included by indirectly 15 | #include "boost/date_time/local_time/local_time.hpp" 16 | 17 | #endif // BOOST_DATE_TIME_ALL_HPP___ 18 | -------------------------------------------------------------------------------- /include/boost/date_time/c_local_time_adjustor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__ 2 | #define DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__ 3 | 4 | /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | /*! @file c_local_time_adjustor.hpp 13 | Time adjustment calculations based on machine 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace boost { 23 | namespace date_time { 24 | 25 | //! Adjust to / from utc using the C API 26 | /*! Warning!!! This class assumes that timezone settings of the 27 | * machine are correct. This can be a very dangerous assumption. 28 | */ 29 | template 30 | class c_local_adjustor { 31 | public: 32 | typedef typename time_type::time_duration_type time_duration_type; 33 | typedef typename time_type::date_type date_type; 34 | typedef typename date_type::duration_type date_duration_type; 35 | //! Convert a utc time to local time 36 | static time_type utc_to_local(const time_type& t) 37 | { 38 | date_type time_t_start_day(1970,1,1); 39 | time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0)); 40 | if (t < time_t_start_time) { 41 | boost::throw_exception(std::out_of_range("Cannot convert dates prior to Jan 1, 1970")); 42 | BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_t_start_time); // should never reach 43 | } 44 | date_duration_type dd = t.date() - time_t_start_day; 45 | time_duration_type td = t.time_of_day(); 46 | uint64_t t2 = static_cast(dd.days())*86400 + 47 | static_cast(td.hours())*3600 + 48 | static_cast(td.minutes())*60 + 49 | td.seconds(); 50 | // detect y2038 issue and throw instead of proceed with bad time 51 | std::time_t tv = boost::numeric_cast(t2); 52 | std::tm tms, *tms_ptr; 53 | tms_ptr = c_time::localtime(&tv, &tms); 54 | date_type d(static_cast(tms_ptr->tm_year + 1900), 55 | static_cast(tms_ptr->tm_mon + 1), 56 | static_cast(tms_ptr->tm_mday)); 57 | time_duration_type td2(tms_ptr->tm_hour, 58 | tms_ptr->tm_min, 59 | tms_ptr->tm_sec, 60 | t.time_of_day().fractional_seconds()); 61 | 62 | return time_type(d,td2); 63 | } 64 | }; 65 | 66 | 67 | 68 | } } //namespace date_time 69 | 70 | 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /include/boost/date_time/date_clock_device.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_CLOCK_DEVICE_HPP___ 2 | #define DATE_CLOCK_DEVICE_HPP___ 3 | 4 | /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | #include "boost/date_time/c_time.hpp" 13 | 14 | 15 | namespace boost { 16 | namespace date_time { 17 | 18 | //! A clock providing day level services based on C time_t capabilities 19 | /*! This clock uses Posix interfaces as its implementation and hence 20 | * uses the timezone settings of the operating system. Incorrect 21 | * user settings will result in incorrect results for the calls 22 | * to local_day. 23 | */ 24 | template 25 | class day_clock 26 | { 27 | public: 28 | typedef typename date_type::ymd_type ymd_type; 29 | //! Get the local day as a date type 30 | static date_type local_day() 31 | { 32 | return date_type(local_day_ymd()); 33 | } 34 | //! Get the local day as a ymd_type 35 | static typename date_type::ymd_type local_day_ymd() 36 | { 37 | ::std::tm result; 38 | ::std::tm* curr = get_local_time(result); 39 | return ymd_type(static_cast(curr->tm_year + 1900), 40 | static_cast(curr->tm_mon + 1), 41 | static_cast(curr->tm_mday)); 42 | } 43 | //! Get the current day in universal date as a ymd_type 44 | static typename date_type::ymd_type universal_day_ymd() 45 | { 46 | ::std::tm result; 47 | ::std::tm* curr = get_universal_time(result); 48 | return ymd_type(static_cast(curr->tm_year + 1900), 49 | static_cast(curr->tm_mon + 1), 50 | static_cast(curr->tm_mday)); 51 | } 52 | //! Get the UTC day as a date type 53 | static date_type universal_day() 54 | { 55 | return date_type(universal_day_ymd()); 56 | } 57 | 58 | private: 59 | static ::std::tm* get_local_time(std::tm& result) 60 | { 61 | ::std::time_t t; 62 | ::std::time(&t); 63 | return c_time::localtime(&t, &result); 64 | } 65 | static ::std::tm* get_universal_time(std::tm& result) 66 | { 67 | ::std::time_t t; 68 | ::std::time(&t); 69 | return c_time::gmtime(&t, &result); 70 | } 71 | 72 | }; 73 | 74 | } } //namespace date_time 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/boost/date_time/date_defs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_DATE_DEFS_HPP 2 | #define DATE_TIME_DATE_DEFS_HPP 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | 13 | namespace boost { 14 | namespace date_time { 15 | 16 | //! An enumeration of weekday names 17 | enum weekdays {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; 18 | 19 | //! Simple enum to allow for nice programming with Jan, Feb, etc 20 | enum months_of_year {Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,NotAMonth,NumMonths}; 21 | 22 | } } //namespace date_time 23 | 24 | 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/date_time/dst_transition_generators.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | */ 7 | #ifndef DATE_TIME_DATE_DST_TRANSITION_DAY_GEN_HPP__ 8 | #define DATE_TIME_DATE_DST_TRANSITION_DAY_GEN_HPP__ 9 | 10 | #include 11 | 12 | namespace boost { 13 | namespace date_time { 14 | 15 | //! Defines base interface for calculating start and end date of daylight savings 16 | template 17 | class dst_day_calc_rule 18 | { 19 | public: 20 | typedef typename date_type::year_type year_type; 21 | virtual ~dst_day_calc_rule() {} 22 | virtual date_type start_day(year_type y) const=0; 23 | virtual std::string start_rule_as_string() const=0; 24 | virtual date_type end_day(year_type y) const=0; 25 | virtual std::string end_rule_as_string() const=0; 26 | 27 | }; 28 | 29 | //! Canonical form for a class that provides day rule calculation 30 | /*! This class is used to generate specific sets of dst rules 31 | * 32 | *@tparam spec Provides a specifiction of the function object types used 33 | * to generate start and end days of daylight savings as well 34 | * as the date type. 35 | */ 36 | template 37 | class day_calc_dst_rule : public dst_day_calc_rule 38 | { 39 | public: 40 | typedef typename spec::date_type date_type; 41 | typedef typename date_type::year_type year_type; 42 | typedef typename spec::start_rule start_rule; 43 | typedef typename spec::end_rule end_rule; 44 | day_calc_dst_rule(start_rule dst_start, 45 | end_rule dst_end) : 46 | dst_start_(dst_start), 47 | dst_end_(dst_end) 48 | {} 49 | virtual date_type start_day(year_type y) const 50 | { 51 | return dst_start_.get_date(y); 52 | } 53 | virtual std::string start_rule_as_string() const 54 | { 55 | return dst_start_.to_string(); 56 | } 57 | virtual date_type end_day(year_type y) const 58 | { 59 | return dst_end_.get_date(y); 60 | } 61 | virtual std::string end_rule_as_string() const 62 | { 63 | return dst_end_.to_string(); 64 | } 65 | private: 66 | start_rule dst_start_; 67 | end_rule dst_end_; 68 | }; 69 | 70 | 71 | } }//namespace 72 | 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /include/boost/date_time/find_match.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _BOOST_DATE_TIME_FIND_MATCH_HPP___ 2 | #define _BOOST_DATE_TIME_FIND_MATCH_HPP___ 3 | 4 | /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace date_time { 16 | 17 | 18 | //! Find index of a string in either of 2 arrays 19 | /*! find_match searches both arrays for a match to 's'. Both arrays 20 | * must contain 'size' elements. The index of the match is returned. 21 | * If no match is found, 'size' is returned. 22 | * Ex. "Jan" returns 0, "Dec" returns 11, "Tue" returns 2. 23 | * 'size' can be sent in with: (greg_month::max)() (which 12), 24 | * (greg_weekday::max)() + 1 (which is 7) or date_time::NumSpecialValues */ 25 | template 26 | short find_match(const charT* const* short_names, 27 | const charT* const* long_names, 28 | short size, 29 | const std::basic_string& s) { 30 | for(short i = 0; i < size; ++i){ 31 | if(short_names[i] == s || long_names[i] == s){ 32 | return i; 33 | } 34 | } 35 | return size; // not-found, return a value out of range 36 | } 37 | 38 | 39 | } } //namespace date_time 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/conversion.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _GREGORIAN__CONVERSION_HPP___ 2 | #define _GREGORIAN__CONVERSION_HPP___ 3 | 4 | /* Copyright (c) 2004-2005 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { 21 | 22 | namespace gregorian { 23 | 24 | //! Converts a date to a tm struct. Throws out_of_range exception if date is a special value 25 | inline 26 | std::tm to_tm(const date& d) 27 | { 28 | if (d.is_special()) 29 | { 30 | std::string s = "tm unable to handle "; 31 | switch (d.as_special()) 32 | { 33 | case date_time::not_a_date_time: 34 | s += "not-a-date-time value"; break; 35 | case date_time::neg_infin: 36 | s += "-infinity date value"; break; 37 | case date_time::pos_infin: 38 | s += "+infinity date value"; break; 39 | default: 40 | s += "a special date value"; break; 41 | } 42 | boost::throw_exception(std::out_of_range(s)); 43 | } 44 | 45 | std::tm datetm; 46 | std::memset(&datetm, 0, sizeof(datetm)); 47 | boost::gregorian::date::ymd_type ymd = d.year_month_day(); 48 | datetm.tm_year = ymd.year - 1900; 49 | datetm.tm_mon = ymd.month - 1; 50 | datetm.tm_mday = ymd.day; 51 | datetm.tm_wday = d.day_of_week(); 52 | datetm.tm_yday = d.day_of_year() - 1; 53 | datetm.tm_isdst = -1; // negative because not enough info to set tm_isdst 54 | return datetm; 55 | } 56 | 57 | //! Converts a tm structure into a date dropping the any time values. 58 | inline 59 | date date_from_tm(const std::tm& datetm) 60 | { 61 | return date(static_cast(datetm.tm_year+1900), 62 | static_cast(datetm.tm_mon+1), 63 | static_cast(datetm.tm_mday)); 64 | } 65 | 66 | } } //namespace boost::gregorian 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/formatters_limited.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREGORIAN_FORMATTERS_LIMITED_HPP___ 2 | #define GREGORIAN_FORMATTERS_LIMITED_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | #include "boost/date_time/gregorian/gregorian_types.hpp" 13 | #include "boost/date_time/date_formatting_limited.hpp" 14 | #include "boost/date_time/iso_format.hpp" 15 | #include "boost/date_time/date_format_simple.hpp" 16 | #include "boost/date_time/compiler_config.hpp" 17 | 18 | namespace boost { 19 | namespace gregorian { 20 | 21 | //! To YYYY-mmm-DD string where mmm 3 char month name. Example: 2002-Jan-01 22 | /*!\ingroup date_format 23 | */ 24 | inline std::string to_simple_string(const date& d) { 25 | return date_time::date_formatter >::date_to_string(d); 26 | } 27 | 28 | //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02] 29 | /*!\ingroup date_format 30 | */ 31 | inline std::string to_simple_string(const date_period& d) { 32 | std::string s("["); 33 | std::string d1(date_time::date_formatter >::date_to_string(d.begin())); 34 | std::string d2(date_time::date_formatter >::date_to_string(d.last())); 35 | return std::string("[" + d1 + "/" + d2 + "]"); 36 | } 37 | 38 | //! Date period to ISO 8601 standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231 39 | /*!\ingroup date_format 40 | */ 41 | inline std::string to_iso_string(const date_period& d) { 42 | std::string s(date_time::date_formatter >::date_to_string(d.begin())); 43 | return s + "/" + date_time::date_formatter >::date_to_string(d.last()); 44 | } 45 | 46 | 47 | //! Convert to ISO 8601 extended format string CCYY-MM-DD. Example 2002-12-31 48 | /*!\ingroup date_format 49 | */ 50 | inline std::string to_iso_extended_string(const date& d) { 51 | return date_time::date_formatter >::date_to_string(d); 52 | } 53 | 54 | //! Convert to ISO 8601 standard string YYYYMMDD. Example: 20021231 55 | /*!\ingroup date_format 56 | */ 57 | inline std::string to_iso_string(const date& d) { 58 | return date_time::date_formatter >::date_to_string(d); 59 | } 60 | 61 | 62 | 63 | inline std::string to_sql_string(const date& d) 64 | { 65 | date::ymd_type ymd = d.year_month_day(); 66 | std::ostringstream ss; 67 | ss << ymd.year << "-" 68 | << std::setw(2) << std::setfill('0') 69 | << ymd.month.as_number() //solves problem with gcc 3.1 hanging 70 | << "-" 71 | << std::setw(2) << std::setfill('0') 72 | << ymd.day; 73 | return ss.str(); 74 | } 75 | 76 | 77 | } } //namespace gregorian 78 | 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/greg_calendar.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREGORIAN_GREGORIAN_CALENDAR_HPP__ 2 | #define GREGORIAN_GREGORIAN_CALENDAR_HPP__ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost { 21 | namespace gregorian { 22 | 23 | //!An internal date representation that includes infinities, not a date 24 | typedef date_time::int_adapter fancy_date_rep; 25 | 26 | //! Gregorian calendar for this implementation, hard work in the base 27 | class BOOST_SYMBOL_VISIBLE gregorian_calendar : 28 | public date_time::gregorian_calendar_base { 29 | public: 30 | //! Type to hold a weekday (eg: Sunday, Monday,...) 31 | typedef greg_weekday day_of_week_type; 32 | //! Counter type from 1 to 366 for gregorian dates. 33 | typedef greg_day_of_year_rep day_of_year_type; 34 | //! Internal date representation that handles infinity, not a date 35 | typedef fancy_date_rep date_rep_type; 36 | //! Date rep implements the traits stuff as well 37 | typedef fancy_date_rep date_traits_type; 38 | 39 | 40 | private: 41 | }; 42 | 43 | } } //namespace gregorian 44 | 45 | 46 | 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/greg_day.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREG_DAY_HPP___ 2 | #define GREG_DAY_HPP___ 3 | 4 | /* Copyright (c) 2002,2003,2020 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace gregorian { 19 | 20 | //! Exception type for gregorian day of month (1..31) 21 | struct BOOST_SYMBOL_VISIBLE bad_day_of_month : public std::out_of_range 22 | { 23 | bad_day_of_month() : 24 | std::out_of_range(std::string("Day of month value is out of range 1..31")) 25 | {} 26 | //! Allow other classes to throw with unique string for bad day like Feb 29 27 | bad_day_of_month(const std::string& s) : 28 | std::out_of_range(s) 29 | {} 30 | }; 31 | //! Policy class that declares error handling and day of month ranges 32 | typedef CV::simple_exception_policy greg_day_policies; 33 | 34 | //! Generated represetation for gregorian day of month 35 | typedef CV::constrained_value greg_day_rep; 36 | 37 | //! Represent a day of the month (range 1 - 31) 38 | /*! This small class allows for simple conversion an integer value into 39 | a day of the month for a standard gregorian calendar. The type 40 | is automatically range checked so values outside of the range 1-31 41 | will cause a bad_day_of_month exception 42 | */ 43 | class BOOST_SYMBOL_VISIBLE greg_day : public greg_day_rep { 44 | public: 45 | BOOST_CXX14_CONSTEXPR greg_day(value_type day_of_month) : greg_day_rep(day_of_month) {} 46 | BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;} 47 | BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;} 48 | private: 49 | 50 | }; 51 | 52 | 53 | 54 | } } //namespace gregorian 55 | 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/greg_day_of_year.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREG_DAY_OF_YEAR_HPP___ 2 | #define GREG_DAY_OF_YEAR_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace gregorian { 19 | 20 | //! Exception type for day of year (1..366) 21 | struct BOOST_SYMBOL_VISIBLE bad_day_of_year : public std::out_of_range 22 | { 23 | bad_day_of_year() : 24 | std::out_of_range(std::string("Day of year value is out of range 1..366")) 25 | {} 26 | }; 27 | 28 | //! A day of the year range (1..366) 29 | typedef CV::simple_exception_policy greg_day_of_year_policies; 30 | 31 | //! Define a range representation type for the day of the year 1..366 32 | typedef CV::constrained_value greg_day_of_year_rep; 33 | 34 | 35 | } } //namespace gregorian 36 | 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/greg_duration_types.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREG_DURATION_TYPES_HPP___ 2 | #define GREG_DURATION_TYPES_HPP___ 3 | 4 | /* Copyright (c) 2004 CrystalClear Software, Inc. 5 | * Subject to Boost Software License, Version 1.0. (See accompanying 6 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace gregorian { 21 | 22 | //! config struct for additional duration types (ie months_duration<> & years_duration<>) 23 | struct BOOST_SYMBOL_VISIBLE greg_durations_config { 24 | typedef date date_type; 25 | typedef date_time::int_adapter int_rep; 26 | typedef date_time::month_functor month_adjustor_type; 27 | }; 28 | 29 | typedef date_time::months_duration months; 30 | typedef date_time::years_duration years; 31 | 32 | class BOOST_SYMBOL_VISIBLE weeks_duration : public date_duration { 33 | public: 34 | BOOST_CXX14_CONSTEXPR weeks_duration(duration_rep w) 35 | : date_duration(w * 7) {} 36 | BOOST_CXX14_CONSTEXPR weeks_duration(date_time::special_values sv) 37 | : date_duration(sv) {} 38 | }; 39 | 40 | typedef weeks_duration weeks; 41 | 42 | }} // namespace boost::gregorian 43 | 44 | #endif // GREG_DURATION_TYPES_HPP___ 45 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/greg_year.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREG_YEAR_HPP___ 2 | #define GREG_YEAR_HPP___ 3 | 4 | /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace gregorian { 19 | 20 | //! Exception type for gregorian year 21 | struct BOOST_SYMBOL_VISIBLE bad_year : public std::out_of_range 22 | { 23 | bad_year() : 24 | std::out_of_range(std::string("Year is out of valid range: 1400..9999")) 25 | {} 26 | }; 27 | //! Policy class that declares error handling gregorian year type 28 | typedef CV::simple_exception_policy greg_year_policies; 29 | 30 | //! Generated representation for gregorian year 31 | typedef CV::constrained_value greg_year_rep; 32 | 33 | //! Represent a year (range 1400 - 9999) 34 | /*! This small class allows for simple conversion an integer value into 35 | a year for the gregorian calendar. This currently only allows a 36 | range of 1400 to 9999. Both ends of the range are a bit arbitrary 37 | at the moment, but they are the limits of current testing of the 38 | library. As such they may be increased in the future. 39 | */ 40 | class BOOST_SYMBOL_VISIBLE greg_year : public greg_year_rep { 41 | public: 42 | BOOST_CXX14_CONSTEXPR greg_year(value_type year) : greg_year_rep(year) {} 43 | BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;} 44 | }; 45 | 46 | 47 | 48 | } } //namespace gregorian 49 | 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/greg_ymd.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_GREG_YMD_HPP__ 2 | #define DATE_TIME_GREG_YMD_HPP__ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include "boost/date_time/year_month_day.hpp" 13 | #include "boost/date_time/special_defs.hpp" 14 | #include "boost/date_time/gregorian/greg_day.hpp" 15 | #include "boost/date_time/gregorian/greg_year.hpp" 16 | #include "boost/date_time/gregorian/greg_month.hpp" 17 | 18 | namespace boost { 19 | namespace gregorian { 20 | 21 | typedef date_time::year_month_day_base greg_year_month_day; 24 | 25 | 26 | 27 | } } //namespace gregorian 28 | 29 | 30 | 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian/gregorian.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GREGORIAN_HPP__ 2 | #define GREGORIAN_HPP__ 3 | 4 | /* Copyright (c) 2002-2004 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | /*! @file gregorian.hpp 13 | Single file header that provides overall include for all elements of 14 | the gregorian date-time system. This includes the various types 15 | defined, but also other functions for formatting and parsing. 16 | */ 17 | 18 | 19 | #include "boost/date_time/compiler_config.hpp" 20 | #include "boost/date_time/gregorian/gregorian_types.hpp" 21 | #include "boost/date_time/gregorian/conversion.hpp" 22 | #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) 23 | #include "boost/date_time/gregorian/formatters_limited.hpp" 24 | #else 25 | #include "boost/date_time/gregorian/formatters.hpp" 26 | #endif 27 | 28 | #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO) 29 | #include "boost/date_time/gregorian/greg_facet.hpp" 30 | #else 31 | #include "boost/date_time/gregorian/gregorian_io.hpp" 32 | #endif // USE_DATE_TIME_PRE_1_33_FACET_IO 33 | 34 | #include "boost/date_time/gregorian/parsers.hpp" 35 | 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/boost/date_time/gregorian_calendar.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_GREGORIAN_CALENDAR_HPP__ 2 | #define DATE_TIME_GREGORIAN_CALENDAR_HPP__ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace date_time { 16 | 17 | 18 | //! An implementation of the Gregorian calendar 19 | /*! This is a parameterized implementation of a proleptic Gregorian Calendar that 20 | can be used in the creation of date systems or just to perform calculations. 21 | All the methods of this class are static functions, so the intent is to 22 | never create instances of this class. 23 | @tparam ymd_type_ Struct type representing the year, month, day. The ymd_type must 24 | define a of types for the year, month, and day. These types need to be 25 | arithmetic types. 26 | @tparam date_int_type_ Underlying type for the date count. Must be an arithmetic type. 27 | */ 28 | template 29 | class BOOST_SYMBOL_VISIBLE gregorian_calendar_base { 30 | public: 31 | //! define a type a date split into components 32 | typedef ymd_type_ ymd_type; 33 | //! define a type for representing months 34 | typedef typename ymd_type::month_type month_type; 35 | //! define a type for representing days 36 | typedef typename ymd_type::day_type day_type; 37 | //! Type to hold a stand alone year value (eg: 2002) 38 | typedef typename ymd_type::year_type year_type; 39 | //! Define the integer type to use for internal calculations 40 | typedef date_int_type_ date_int_type; 41 | 42 | 43 | static BOOST_CXX14_CONSTEXPR unsigned short day_of_week(const ymd_type& ymd); 44 | static BOOST_CXX14_CONSTEXPR int week_number(const ymd_type&ymd); 45 | static BOOST_CXX14_CONSTEXPR date_int_type day_number(const ymd_type& ymd); 46 | static BOOST_CXX14_CONSTEXPR date_int_type julian_day_number(const ymd_type& ymd); 47 | static BOOST_CXX14_CONSTEXPR date_int_type modjulian_day_number(const ymd_type& ymd); 48 | static BOOST_CXX14_CONSTEXPR ymd_type from_day_number(date_int_type); 49 | static BOOST_CXX14_CONSTEXPR ymd_type from_julian_day_number(date_int_type); 50 | static BOOST_CXX14_CONSTEXPR ymd_type from_modjulian_day_number(date_int_type); 51 | static BOOST_CXX14_CONSTEXPR bool is_leap_year(year_type); 52 | static BOOST_CXX14_CONSTEXPR unsigned short end_of_month_day(year_type y, month_type m); 53 | static BOOST_CXX14_CONSTEXPR ymd_type epoch(); 54 | static BOOST_CXX14_CONSTEXPR unsigned short days_in_week(); 55 | 56 | }; 57 | 58 | 59 | 60 | } } //namespace 61 | 62 | #include "boost/date_time/gregorian_calendar.ipp" 63 | 64 | 65 | 66 | 67 | #endif 68 | 69 | 70 | -------------------------------------------------------------------------------- /include/boost/date_time/local_time/conversion.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_LOCAL_TIME_CONVERSION_HPP__ 2 | #define DATE_TIME_LOCAL_TIME_CONVERSION_HPP__ 3 | 4 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 5 | * Subject to the Boost Software License, Version 1.0. 6 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | 12 | #include "boost/date_time/posix_time/conversion.hpp" 13 | #include "boost/date_time/c_time.hpp" 14 | #include "boost/date_time/local_time/local_date_time.hpp" 15 | 16 | namespace boost { 17 | namespace local_time { 18 | 19 | //! Function that creates a tm struct from a local_date_time 20 | inline 21 | std::tm to_tm(const local_date_time& lt) { 22 | std::tm lt_tm = posix_time::to_tm(lt.local_time()); 23 | if(lt.is_dst()){ 24 | lt_tm.tm_isdst = 1; 25 | } 26 | else{ 27 | lt_tm.tm_isdst = 0; 28 | } 29 | return lt_tm; 30 | } 31 | 32 | 33 | }} // namespaces 34 | #endif // DATE_TIME_LOCAL_TIME_CONVERSION_HPP__ 35 | -------------------------------------------------------------------------------- /include/boost/date_time/local_time/dst_transition_day_rules.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LOCAL_TIME_DST_TRANSITION_DAY_RULES_HPP__ 2 | #define LOCAL_TIME_DST_TRANSITION_DAY_RULES_HPP__ 3 | 4 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 5 | * Subject to the Boost Software License, Version 1.0. 6 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | 12 | #include "boost/date_time/gregorian/gregorian_types.hpp" 13 | #include "boost/date_time/dst_transition_generators.hpp" 14 | 15 | namespace boost { 16 | namespace local_time { 17 | 18 | //! Provides rule of the form starting Apr 30 ending Oct 21 19 | typedef date_time::dst_day_calc_rule dst_calc_rule; 20 | 21 | struct partial_date_rule_spec 22 | { 23 | typedef gregorian::date date_type; 24 | typedef gregorian::partial_date start_rule; 25 | typedef gregorian::partial_date end_rule; 26 | }; 27 | 28 | //! Provides rule of the form first Sunday in April, last Saturday in Oct 29 | typedef date_time::day_calc_dst_rule partial_date_dst_rule; 30 | 31 | struct first_last_rule_spec 32 | { 33 | typedef gregorian::date date_type; 34 | typedef gregorian::first_kday_of_month start_rule; 35 | typedef gregorian::last_kday_of_month end_rule; 36 | }; 37 | 38 | //! Provides rule of the form first Sunday in April, last Saturday in Oct 39 | typedef date_time::day_calc_dst_rule first_last_dst_rule; 40 | 41 | struct last_last_rule_spec 42 | { 43 | typedef gregorian::date date_type; 44 | typedef gregorian::last_kday_of_month start_rule; 45 | typedef gregorian::last_kday_of_month end_rule; 46 | }; 47 | 48 | //! Provides rule of the form last Sunday in April, last Saturday in Oct 49 | typedef date_time::day_calc_dst_rule last_last_dst_rule; 50 | 51 | struct nth_last_rule_spec 52 | { 53 | typedef gregorian::date date_type; 54 | typedef gregorian::nth_kday_of_month start_rule; 55 | typedef gregorian::last_kday_of_month end_rule; 56 | }; 57 | 58 | //! Provides rule in form of [1st|2nd|3rd|4th] Sunday in April, last Sunday in Oct 59 | typedef date_time::day_calc_dst_rule nth_last_dst_rule; 60 | 61 | struct nth_kday_rule_spec 62 | { 63 | typedef gregorian::date date_type; 64 | typedef gregorian::nth_kday_of_month start_rule; 65 | typedef gregorian::nth_kday_of_month end_rule; 66 | }; 67 | 68 | //! Provides rule in form of [1st|2nd|3rd|4th] Sunday in April/October 69 | typedef date_time::day_calc_dst_rule nth_kday_dst_rule; 70 | //! Provides rule in form of [1st|2nd|3rd|4th] Sunday in April/October 71 | typedef date_time::day_calc_dst_rule nth_day_of_the_week_in_month_dst_rule; 72 | 73 | 74 | } }//namespace 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/boost/date_time/local_time/local_time.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LOCAL_TIME_LOCAL_TIME_HPP__ 2 | #define LOCAL_TIME_LOCAL_TIME_HPP__ 3 | 4 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 5 | * Subject to the Boost Software License, Version 1.0. 6 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | #include "boost/date_time/posix_time/posix_time.hpp" 12 | #include "boost/date_time/local_time/local_date_time.hpp" 13 | #include "boost/date_time/local_time/local_time_types.hpp" 14 | #if !defined(USE_DATE_TIME_PRE_1_33_FACET_IO) 15 | #include "boost/date_time/local_time/local_time_io.hpp" 16 | #endif // USE_DATE_TIME_PRE_1_33_FACET_IO 17 | #include "boost/date_time/local_time/posix_time_zone.hpp" 18 | #include "boost/date_time/local_time/custom_time_zone.hpp" 19 | #include "boost/date_time/local_time/tz_database.hpp" 20 | #include "boost/date_time/local_time/conversion.hpp" 21 | #include "boost/date_time/time_zone_base.hpp" 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/boost/date_time/local_time/local_time_types.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LOCAL_TIME_LOCAL_TIME_TYPES_HPP__ 2 | #define LOCAL_TIME_LOCAL_TIME_TYPES_HPP__ 3 | 4 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 5 | * Subject to the Boost Software License, Version 1.0. 6 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | #include "boost/date_time/local_time/local_date_time.hpp" 12 | #include "boost/date_time/period.hpp" 13 | #include "boost/date_time/time_iterator.hpp" 14 | #include "boost/date_time/compiler_config.hpp" 15 | #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) 16 | #include "boost/date_time/local_time/date_duration_operators.hpp" 17 | #endif //BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES 18 | #include "boost/date_time/local_time/custom_time_zone.hpp" 19 | 20 | namespace boost { 21 | namespace local_time { 22 | 23 | typedef boost::date_time::period local_time_period; 25 | 26 | typedef date_time::time_itr local_time_iterator; 27 | 28 | typedef date_time::second_clock local_sec_clock; 29 | typedef date_time::microsec_clock local_microsec_clock; 30 | 31 | typedef date_time::time_zone_base time_zone; 32 | typedef date_time::time_zone_base wtime_zone; 33 | 34 | //! Shared Pointer for custom_time_zone and posix_time_zone objects 35 | typedef boost::shared_ptr time_zone_ptr; 36 | typedef boost::shared_ptr wtime_zone_ptr; 37 | 38 | typedef date_time::time_zone_names_base time_zone_names; 39 | typedef date_time::time_zone_names_base wtime_zone_names; 40 | 41 | //bring special enum values into the namespace 42 | using date_time::special_values; 43 | using date_time::not_special; 44 | using date_time::neg_infin; 45 | using date_time::pos_infin; 46 | using date_time::not_a_date_time; 47 | using date_time::max_date_time; 48 | using date_time::min_date_time; 49 | 50 | }} // namespaces 51 | 52 | #endif // LOCAL_TIME_LOCAL_TIME_TYPES_HPP__ 53 | -------------------------------------------------------------------------------- /include/boost/date_time/local_time/tz_database.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_DATE_TIME_TZ_DATABASE_HPP__ 2 | #define BOOST_DATE_TIME_TZ_DATABASE_HPP__ 3 | 4 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 5 | * Subject to the Boost Software License, Version 1.0. 6 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | #include 12 | #include "boost/date_time/local_time/custom_time_zone.hpp" 13 | #include "boost/date_time/local_time/dst_transition_day_rules.hpp" 14 | #include "boost/date_time/tz_db_base.hpp" 15 | 16 | 17 | namespace boost { 18 | namespace local_time { 19 | 20 | using date_time::data_not_accessible; 21 | using date_time::bad_field_count; 22 | 23 | //! Object populated with boost::shared_ptr objects 24 | /*! Object populated with boost::shared_ptr objects 25 | * Database is populated from specs stored in external csv file. See 26 | * date_time::tz_db_base for greater detail */ 27 | typedef date_time::tz_db_base tz_database; 28 | 29 | }} // namespace 30 | 31 | #endif // BOOST_DATE_TIME_TZ_DATABASE_HPP__ 32 | 33 | -------------------------------------------------------------------------------- /include/boost/date_time/locale_config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_LOCALE_CONFIG_HPP___ 2 | #define DATE_TIME_LOCALE_CONFIG_HPP___ 3 | 4 | /* Copyright (c) 2002-2020 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | // This file configures whether the library will support locales and hence 13 | // iostream based i/o. Even if a compiler has some support for locales, 14 | // any failure to be compatible gets the compiler on the exclusion list. 15 | // 16 | // At the moment this is defined for MSVC 6 and any compiler that 17 | // defines BOOST_NO_STD_LOCALE (gcc 2.95.x) 18 | 19 | #include "boost/config.hpp" //sets BOOST_NO_STD_LOCALE 20 | #include "boost/config/workaround.hpp" 21 | 22 | //This file basically becomes a noop if locales are not properly supported 23 | #if (defined(BOOST_NO_STD_LOCALE) \ 24 | || (BOOST_WORKAROUND( BOOST_MSVC, < 1300)) \ 25 | || (BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT( 0x581 )) ) \ 26 | || (BOOST_WORKAROUND( BOOST_XLCPP_ZOS, BOOST_TESTED_AT( 0x42010000 )) ) /* "shadows" the locale enabled overloads from */ \ 27 | ) 28 | #define BOOST_DATE_TIME_NO_LOCALE 29 | #endif 30 | 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /include/boost/date_time/parse_format_base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_PARSE_FORMAT_BASE__ 2 | #define DATE_TIME_PARSE_FORMAT_BASE__ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | namespace boost { 13 | namespace date_time { 14 | 15 | //! Enum for distinguishing parsing and formatting options 16 | enum month_format_spec {month_as_integer, month_as_short_string, 17 | month_as_long_string}; 18 | 19 | //! Enum for distinguishing the order of Month, Day, & Year. 20 | /*! Enum for distinguishing the order in which Month, Day, & Year 21 | * will appear in a date string */ 22 | enum ymd_order_spec {ymd_order_iso, //order is year-month-day 23 | ymd_order_dmy, //day-month-year 24 | ymd_order_us}; //order is month-day-year 25 | 26 | 27 | } }//namespace date_time 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/posix_time.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSIX_TIME_HPP___ 2 | #define POSIX_TIME_HPP___ 3 | 4 | /* Copyright (c) 2002-2005 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | /*!@file posix_time.hpp Global header file to get all of posix time types 12 | */ 13 | 14 | #include "boost/date_time/compiler_config.hpp" 15 | #include "boost/date_time/posix_time/ptime.hpp" 16 | #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) 17 | #include "boost/date_time/posix_time/date_duration_operators.hpp" 18 | #endif 19 | 20 | // output functions 21 | #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) 22 | #include "boost/date_time/posix_time/time_formatters_limited.hpp" 23 | #else 24 | #include "boost/date_time/posix_time/time_formatters.hpp" 25 | #endif // BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS 26 | 27 | // streaming operators 28 | #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO) 29 | #include "boost/date_time/posix_time/posix_time_legacy_io.hpp" 30 | #else 31 | #include "boost/date_time/posix_time/posix_time_io.hpp" 32 | #endif // USE_DATE_TIME_PRE_1_33_FACET_IO 33 | 34 | #include "boost/date_time/posix_time/time_parsers.hpp" 35 | #include "boost/date_time/posix_time/conversion.hpp" 36 | 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/posix_time_duration.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSIX_TIME_DURATION_HPP___ 2 | #define POSIX_TIME_DURATION_HPP___ 3 | 4 | /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost { 19 | namespace posix_time { 20 | 21 | //! Allows expression of durations as an hour count 22 | //! The argument must be an integral type 23 | /*! \ingroup time_basics 24 | */ 25 | class BOOST_SYMBOL_VISIBLE hours : public time_duration 26 | { 27 | public: 28 | template 29 | BOOST_CXX14_CONSTEXPR explicit hours(T const& h, 30 | typename boost::enable_if, void>::type* = BOOST_DATE_TIME_NULLPTR) : 31 | time_duration(numeric_cast(h), 0, 0) 32 | {} 33 | }; 34 | 35 | //! Allows expression of durations as a minute count 36 | //! The argument must be an integral type 37 | /*! \ingroup time_basics 38 | */ 39 | class BOOST_SYMBOL_VISIBLE minutes : public time_duration 40 | { 41 | public: 42 | template 43 | BOOST_CXX14_CONSTEXPR explicit minutes(T const& m, 44 | typename boost::enable_if, void>::type* = BOOST_DATE_TIME_NULLPTR) : 45 | time_duration(0, numeric_cast(m),0) 46 | {} 47 | }; 48 | 49 | //! Allows expression of durations as a seconds count 50 | //! The argument must be an integral type 51 | /*! \ingroup time_basics 52 | */ 53 | class BOOST_SYMBOL_VISIBLE seconds : public time_duration 54 | { 55 | public: 56 | template 57 | BOOST_CXX14_CONSTEXPR explicit seconds(T const& s, 58 | typename boost::enable_if, void>::type* = BOOST_DATE_TIME_NULLPTR) : 59 | time_duration(0,0, numeric_cast(s)) 60 | {} 61 | }; 62 | 63 | 64 | //! Allows expression of durations as milli seconds 65 | /*! \ingroup time_basics 66 | */ 67 | typedef date_time::subsecond_duration millisec; 68 | typedef date_time::subsecond_duration milliseconds; 69 | 70 | //! Allows expression of durations as micro seconds 71 | /*! \ingroup time_basics 72 | */ 73 | typedef date_time::subsecond_duration microsec; 74 | typedef date_time::subsecond_duration microseconds; 75 | 76 | //This is probably not needed anymore... 77 | #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) 78 | 79 | //! Allows expression of durations as nano seconds 80 | /*! \ingroup time_basics 81 | */ 82 | typedef date_time::subsecond_duration nanosec; 83 | typedef date_time::subsecond_duration nanoseconds; 84 | 85 | #endif 86 | 87 | } }//namespace posix_time 88 | 89 | 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/posix_time_system.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSIX_TIME_SYSTEM_HPP___ 2 | #define POSIX_TIME_SYSTEM_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | 13 | #include "boost/date_time/posix_time/posix_time_config.hpp" 14 | #include "boost/date_time/time_system_split.hpp" 15 | #include "boost/date_time/time_system_counted.hpp" 16 | #include "boost/date_time/compiler_config.hpp" 17 | 18 | 19 | namespace boost { 20 | namespace posix_time { 21 | 22 | #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 23 | 24 | #if (defined(BOOST_DATE_TIME_NO_MEMBER_INIT)) //help bad compilers 25 | typedef date_time::split_timedate_system posix_time_system; 26 | #else 27 | typedef date_time::split_timedate_system posix_time_system; 28 | #endif 29 | 30 | #else 31 | 32 | typedef date_time::counted_time_rep int64_time_rep; 33 | typedef date_time::counted_time_system posix_time_system; 34 | 35 | #endif 36 | 37 | } }//namespace posix_time 38 | 39 | 40 | #endif 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/posix_time_types.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | #ifndef POSIX_TIME_TYPES_HPP___ 8 | #define POSIX_TIME_TYPES_HPP___ 9 | 10 | #include "boost/date_time/time_clock.hpp" 11 | #include "boost/date_time/microsec_time_clock.hpp" 12 | #include "boost/date_time/posix_time/ptime.hpp" 13 | #if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) 14 | #include "boost/date_time/posix_time/date_duration_operators.hpp" 15 | #endif 16 | #include "boost/date_time/posix_time/posix_time_duration.hpp" 17 | #include "boost/date_time/posix_time/posix_time_system.hpp" 18 | #include "boost/date_time/posix_time/time_period.hpp" 19 | #include "boost/date_time/time_iterator.hpp" 20 | #include "boost/date_time/dst_rules.hpp" 21 | 22 | namespace boost { 23 | 24 | //!Defines a non-adjusted time system with nano-second resolution and stable calculation properties 25 | namespace posix_time { 26 | 27 | //! Iterator over a defined time duration 28 | /*! \ingroup time_basics 29 | */ 30 | typedef date_time::time_itr time_iterator; 31 | //! A time clock that has a resolution of one second 32 | /*! \ingroup time_basics 33 | */ 34 | typedef date_time::second_clock second_clock; 35 | 36 | #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK 37 | //! A time clock that has a resolution of one microsecond 38 | /*! \ingroup time_basics 39 | */ 40 | typedef date_time::microsec_clock microsec_clock; 41 | #endif 42 | 43 | //! Define a dst null dst rule for the posix_time system 44 | typedef date_time::null_dst_rules no_dst; 45 | //! Define US dst rule calculator for the posix_time system 46 | typedef date_time::us_dst_rules us_dst; 47 | 48 | 49 | } } //namespace posix_time 50 | 51 | 52 | 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/ptime.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSIX_PTIME_HPP___ 2 | #define POSIX_PTIME_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost { 17 | 18 | namespace posix_time { 19 | 20 | //bring special enum values into the namespace 21 | using date_time::special_values; 22 | using date_time::not_special; 23 | using date_time::neg_infin; 24 | using date_time::pos_infin; 25 | using date_time::not_a_date_time; 26 | using date_time::max_date_time; 27 | using date_time::min_date_time; 28 | 29 | //! Time type with no timezone or other adjustments 30 | /*! \ingroup time_basics 31 | */ 32 | class BOOST_SYMBOL_VISIBLE ptime : public date_time::base_time 33 | { 34 | public: 35 | typedef posix_time_system time_system_type; 36 | typedef time_system_type::time_rep_type time_rep_type; 37 | typedef time_system_type::time_duration_type time_duration_type; 38 | typedef ptime time_type; 39 | //! Construct with date and offset in day 40 | BOOST_CXX14_CONSTEXPR 41 | ptime(gregorian::date d,time_duration_type td) : 42 | date_time::base_time(d,td) 43 | {} 44 | //! Construct a time at start of the given day (midnight) 45 | BOOST_CXX14_CONSTEXPR 46 | explicit ptime(gregorian::date d) : 47 | date_time::base_time(d,time_duration_type(0,0,0)) 48 | {} 49 | //! Copy from time_rep 50 | BOOST_CXX14_CONSTEXPR 51 | ptime(const time_rep_type& rhs): 52 | date_time::base_time(rhs) 53 | {} 54 | //! Construct from special value 55 | BOOST_CXX14_CONSTEXPR 56 | ptime(const special_values sv) : 57 | date_time::base_time(sv) 58 | {} 59 | #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR) 60 | // Default constructor constructs to not_a_date_time 61 | BOOST_CXX14_CONSTEXPR 62 | ptime() : 63 | date_time::base_time(gregorian::date(not_a_date_time), 64 | time_duration_type(not_a_date_time)) 65 | {} 66 | #endif // DATE_TIME_NO_DEFAULT_CONSTRUCTOR 67 | 68 | friend BOOST_CXX14_CONSTEXPR 69 | bool operator==(const ptime& lhs, const ptime& rhs); 70 | 71 | }; 72 | 73 | inline BOOST_CXX14_CONSTEXPR 74 | bool operator==(const ptime& lhs, const ptime& rhs) 75 | { 76 | return ptime::time_system_type::is_equal(lhs.time_,rhs.time_); 77 | } 78 | 79 | 80 | } }//namespace posix_time 81 | 82 | 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/time_parsers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSIXTIME_PARSERS_HPP___ 2 | #define POSIXTIME_PARSERS_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include "boost/date_time/gregorian/gregorian.hpp" 13 | #include "boost/date_time/time_parsing.hpp" 14 | #include "boost/date_time/posix_time/posix_time_types.hpp" 15 | 16 | 17 | namespace boost { 18 | 19 | namespace posix_time { 20 | 21 | //! Creates a time_duration object from a delimited string 22 | /*! Expected format for string is "[-]h[h][:mm][:ss][.fff]". 23 | * A negative duration will be created if the first character in 24 | * string is a '-', all other '-' will be treated as delimiters. 25 | * Accepted delimiters are "-:,.". */ 26 | inline time_duration duration_from_string(const std::string& s) { 27 | return date_time::parse_delimited_time_duration(s); 28 | } 29 | 30 | inline ptime time_from_string(const std::string& s) { 31 | return date_time::parse_delimited_time(s, ' '); 32 | } 33 | 34 | inline ptime from_iso_string(const std::string& s) { 35 | return date_time::parse_iso_time(s, 'T'); 36 | } 37 | 38 | inline ptime from_iso_extended_string(const std::string& s) { 39 | if (s.size() == 10) { //assume we just have a date which is 10 chars 40 | gregorian::date d = gregorian::from_simple_string(s); 41 | return ptime( d ); 42 | } 43 | return date_time::parse_delimited_time(s, 'T'); 44 | } 45 | 46 | 47 | 48 | } } //namespace posix_time 49 | 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /include/boost/date_time/posix_time/time_period.hpp: -------------------------------------------------------------------------------- 1 | #ifndef POSIX_TIME_PERIOD_HPP___ 2 | #define POSIX_TIME_PERIOD_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include "boost/date_time/period.hpp" 13 | #include "boost/date_time/posix_time/posix_time_duration.hpp" 14 | #include "boost/date_time/posix_time/ptime.hpp" 15 | 16 | namespace boost { 17 | namespace posix_time { 18 | 19 | //! Time period type 20 | /*! \ingroup time_basics 21 | */ 22 | typedef date_time::period time_period; 23 | 24 | 25 | } }//namespace posix_time 26 | 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /include/boost/date_time/special_defs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_SPECIAL_DEFS_HPP__ 2 | #define DATE_TIME_SPECIAL_DEFS_HPP__ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | namespace boost { 13 | namespace date_time { 14 | 15 | enum special_values {not_a_date_time, 16 | neg_infin, pos_infin, 17 | min_date_time, max_date_time, 18 | not_special, NumSpecialValues}; 19 | 20 | 21 | } } //namespace date_time 22 | 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /include/boost/date_time/string_convert.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _STRING_CONVERT_HPP___ 2 | #define _STRING_CONVERT_HPP___ 3 | 4 | /* Copyright (c) 2005 CrystalClear Software, Inc. 5 | * Subject to the Boost Software License, Version 1.0. (See accompanying 6 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 7 | * Author: Jeff Garland, Bart Garst 8 | * $Date$ 9 | */ 10 | 11 | #include "boost/date_time/compiler_config.hpp" 12 | #include 13 | 14 | namespace boost { 15 | namespace date_time { 16 | 17 | //! Converts a string from one value_type to another 18 | /*! Converts a wstring to a string (or a string to wstring). If both template parameters 19 | * are of same type, a copy of the input string is returned. */ 20 | template 21 | inline 22 | std::basic_string convert_string_type(const std::basic_string& inp_str) 23 | { 24 | typedef std::basic_string output_type; 25 | output_type result; 26 | result.insert(result.begin(), inp_str.begin(), inp_str.end()); 27 | return result; 28 | } 29 | 30 | }} // namespace boost::date_time 31 | 32 | #endif // _STRING_CONVERT_HPP___ 33 | -------------------------------------------------------------------------------- /include/boost/date_time/time_clock.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_TIME_CLOCK_HPP___ 2 | #define DATE_TIME_TIME_CLOCK_HPP___ 3 | 4 | /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | /*! @file time_clock.hpp 13 | This file contains the interface for clock devices. 14 | */ 15 | 16 | #include "boost/date_time/c_time.hpp" 17 | #include "boost/shared_ptr.hpp" 18 | 19 | namespace boost { 20 | namespace date_time { 21 | 22 | 23 | //! A clock providing time level services based on C time_t capabilities 24 | /*! This clock provides resolution to the 1 second level 25 | */ 26 | template 27 | class second_clock 28 | { 29 | public: 30 | typedef typename time_type::date_type date_type; 31 | typedef typename time_type::time_duration_type time_duration_type; 32 | 33 | static time_type local_time() 34 | { 35 | ::std::time_t t; 36 | ::std::time(&t); 37 | ::std::tm curr, *curr_ptr; 38 | //curr_ptr = ::std::localtime(&t); 39 | curr_ptr = c_time::localtime(&t, &curr); 40 | return create_time(curr_ptr); 41 | } 42 | 43 | 44 | //! Get the current day in universal date as a ymd_type 45 | static time_type universal_time() 46 | { 47 | 48 | ::std::time_t t; 49 | ::std::time(&t); 50 | ::std::tm curr, *curr_ptr; 51 | //curr_ptr = ::std::gmtime(&t); 52 | curr_ptr = c_time::gmtime(&t, &curr); 53 | return create_time(curr_ptr); 54 | } 55 | 56 | template 57 | static time_type local_time(boost::shared_ptr tz_ptr) 58 | { 59 | typedef typename time_type::utc_time_type utc_time_type; 60 | utc_time_type utc_time = second_clock::universal_time(); 61 | return time_type(utc_time, tz_ptr); 62 | } 63 | 64 | 65 | private: 66 | static time_type create_time(::std::tm* current) 67 | { 68 | date_type d(static_cast(current->tm_year + 1900), 69 | static_cast(current->tm_mon + 1), 70 | static_cast(current->tm_mday)); 71 | time_duration_type td(current->tm_hour, 72 | current->tm_min, 73 | current->tm_sec); 74 | return time_type(d,td); 75 | } 76 | 77 | }; 78 | 79 | 80 | } } //namespace date_time 81 | 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /include/boost/date_time/time_defs.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_TIME_PRECISION_LIMITS_HPP 2 | #define DATE_TIME_TIME_PRECISION_LIMITS_HPP 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | 13 | 14 | /*! \file time_defs.hpp 15 | This file contains nice definitions for handling the resoluion of various time 16 | reprsentations. 17 | */ 18 | 19 | namespace boost { 20 | namespace date_time { 21 | 22 | //!Defines some nice types for handling time level resolutions 23 | enum time_resolutions { 24 | sec, 25 | tenth, 26 | hundreth, // deprecated misspelled version of hundredth 27 | hundredth = hundreth, 28 | milli, 29 | ten_thousandth, 30 | micro, 31 | nano, 32 | NumResolutions 33 | }; 34 | 35 | //! Flags for daylight savings or summer time 36 | enum dst_flags {not_dst, is_dst, calculate}; 37 | 38 | 39 | } } //namespace date_time 40 | 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/boost/date_time/time_iterator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATE_TIME_TIME_ITERATOR_HPP___ 2 | #define DATE_TIME_TIME_ITERATOR_HPP___ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland, Bart Garst 9 | * $Date$ 10 | */ 11 | 12 | 13 | namespace boost { 14 | namespace date_time { 15 | 16 | 17 | //! Simple time iterator skeleton class 18 | template 19 | class time_itr { 20 | public: 21 | typedef typename time_type::time_duration_type time_duration_type; 22 | time_itr(time_type t, time_duration_type d) : current_(t), offset_(d) {} 23 | time_itr& operator++() 24 | { 25 | current_ = current_ + offset_; 26 | return *this; 27 | } 28 | time_itr& operator--() 29 | { 30 | current_ = current_ - offset_; 31 | return *this; 32 | } 33 | const time_type& operator*() const {return current_;} 34 | const time_type* operator->() const {return ¤t_;} 35 | bool operator< (const time_type& t) const {return current_ < t;} 36 | bool operator<= (const time_type& t) const {return current_ <= t;} 37 | bool operator!= (const time_type& t) const {return current_ != t;} 38 | bool operator== (const time_type& t) const {return current_ == t;} 39 | bool operator> (const time_type& t) const {return current_ > t;} 40 | bool operator>= (const time_type& t) const {return current_ >= t;} 41 | 42 | private: 43 | time_type current_; 44 | time_duration_type offset_; 45 | }; 46 | 47 | 48 | 49 | } }//namespace date_time 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/boost/date_time/year_month_day.hpp: -------------------------------------------------------------------------------- 1 | #ifndef YearMonthDayBase_HPP__ 2 | #define YearMonthDayBase_HPP__ 3 | 4 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 5 | * Use, modification and distribution is subject to the 6 | * Boost Software License, Version 1.0. (See accompanying 7 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 8 | * Author: Jeff Garland 9 | * $Date$ 10 | */ 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace date_time { 16 | 17 | //! Allow rapid creation of ymd triples of different types 18 | template 19 | struct BOOST_SYMBOL_VISIBLE year_month_day_base { 20 | BOOST_CXX14_CONSTEXPR 21 | year_month_day_base(YearType year, 22 | MonthType month, 23 | DayType day); 24 | 25 | YearType year; 26 | MonthType month; 27 | DayType day; 28 | typedef YearType year_type; 29 | typedef MonthType month_type; 30 | typedef DayType day_type; 31 | }; 32 | 33 | 34 | //! A basic constructor 35 | template 36 | inline BOOST_CXX14_CONSTEXPR 37 | year_month_day_base::year_month_day_base(YearType y, 38 | MonthType m, 39 | DayType d) : 40 | year(y), 41 | month(m), 42 | day(d) 43 | {} 44 | 45 | } }//namespace date_time 46 | 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/date_time/39714907b7d32ed8f005b5a01d1c2b885b5717b3/index.html -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "date_time", 3 | "name": "Date Time", 4 | "authors": [ 5 | "Jeff Garland" 6 | ], 7 | "description": "A set of date-time libraries based on generic programming concepts.", 8 | "category": [ 9 | "Domain", 10 | "System" 11 | ], 12 | "maintainers": [ 13 | "Jeff Garland ", 14 | "James E. King III " 15 | ], 16 | "cxxstd": "03" 17 | } 18 | -------------------------------------------------------------------------------- /src/date_time.doc: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2001-2004 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | * $Date$ 7 | */ 8 | 9 | 10 | /*! @mainpage Boost Date-Time Library Reference Documentation 11 | * 12 | * 13 | *@section intro Introduction 14 | * 15 | * The Boost Date-Time Library (originally the Generic Date-Time Library or GDTL) 16 | * is a set of C++ date-time libraries based on the concepts of generic programming. 17 | * This is an online reference guide generated from the source code 18 | * that provides a handy way to learn about the details of the 19 | * library. If you are a user you should start with the 20 | * User Documentation. 21 | * 22 | *@section using Using This Documentation 23 | * 24 | * The online documentation provides extensive information about the details 25 | * of the library including: 26 | * - Class hierarchy 27 | * - Namespace Documentation 28 | * - List of source files 29 | * - Annotated list of classes and structs 30 | * (Compound List) 31 | * 32 | * For example, suppose you wanted to learn more about the 33 | * gregorian::greg_month class. 34 | * You could alternatively browse the 35 | * - Class documentation page 36 | * - Include dependencies for greg_month.hpp 37 | * - Hyperlinked and colorized source files: [hpp file] [cpp file] 38 | * 39 | * The main navigation bar at the top provides that access to many 40 | * different modes of naviation through the library. 41 | 42 | * 43 | */ 44 | 45 | //! Overall boost namespace -- library does not put any symbols here 46 | namespace boost { 47 | 48 | //! Namespace for basic templates and components used to construct date-time systems 49 | /*! 50 | This namespace encapsulates various types of templates and classes used 51 | to construct coherent date-time systems including date, time, etc. These 52 | components should be considered helper components to be utilized in the 53 | construction of specific date-time system implementations. See namespace 54 | gregorian for one such example. 55 | */ 56 | namespace date_time {} 57 | 58 | } 59 | /*! Namespace for the c++ standard library. Library does not define any symbols in the namespace, but uses some classes from this namespace. 60 | */ 61 | namespace std {} 62 | 63 | /*!\class std::out_of_range 64 | \brief Exception class defined in c++ standard library. 65 | A derivative of std::logic_error and std::exception and base class for 66 | many exceptions in the library. See also: 67 | 68 | Mandragor docs for libstdcpp_v3 std::out_of_range 69 | */ 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/gregorian/date_generators.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | * $Date$ 7 | */ 8 | 9 | 10 | 11 | #ifndef BOOST_DATE_TIME_SOURCE 12 | #define BOOST_DATE_TIME_SOURCE 13 | #endif 14 | #include "boost/date_time/date_generators.hpp" 15 | 16 | namespace boost { 17 | namespace date_time { 18 | 19 | const char* const _nth_as_str[] = {"out of range", "first", "second", 20 | "third", "fourth", "fifth"}; 21 | 22 | //! Returns nth arg as string. 1 -> "first", 2 -> "second", max is 5. 23 | BOOST_DATE_TIME_DECL const char* nth_as_str(int ele) 24 | { 25 | if(ele >= 1 && ele <= 5) { 26 | return _nth_as_str[ele]; 27 | } 28 | else { 29 | return _nth_as_str[0]; 30 | } 31 | } 32 | 33 | } } //namespace date_time 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/gregorian/greg_month.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002-2020 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | * $Date$ 7 | */ 8 | 9 | 10 | // define BOOST_DATE_TIME_SOURCE so that knows 11 | // the library is being built (possibly exporting rather than importing code) 12 | #ifndef BOOST_DATE_TIME_SOURCE 13 | #define BOOST_DATE_TIME_SOURCE 14 | #endif 15 | 16 | #include 17 | 18 | namespace boost { 19 | namespace gregorian { 20 | 21 | 22 | BOOST_DATE_TIME_DECL void date_time_dummy_exported_function() 23 | {} 24 | 25 | } } //namespace boost::gregorian 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/gregorian/greg_names.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002-2004 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | * $Date$ 7 | */ 8 | 9 | 10 | 11 | #ifndef DATE_TIME_SRC_GREG_NAMES_HPP___ 12 | #define DATE_TIME_SRC_GREG_NAMES_HPP___ 13 | 14 | #include "boost/date_time/gregorian/greg_month.hpp" 15 | #include "boost/date_time/special_defs.hpp" 16 | namespace boost { 17 | namespace gregorian { 18 | 19 | 20 | const char* const short_month_names[NumMonths]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", "NAM"}; 21 | const char* const long_month_names[NumMonths]={"January","February","March","April","May","June","July","August","September","October","November","December","NotAMonth"}; 22 | const char* const special_value_names[date_time::NumSpecialValues]={"not-a-date-time","-infinity","+infinity","min_date_time","max_date_time","not_special"}; 23 | 24 | 25 | const char* const short_weekday_names[]={"Sun", "Mon", "Tue", 26 | "Wed", "Thu", "Fri", "Sat"}; 27 | const char* const long_weekday_names[]= {"Sunday","Monday","Tuesday", 28 | "Wednesday", "Thursday", 29 | "Friday", "Saturday"}; 30 | 31 | #ifndef BOOST_NO_STD_WSTRING 32 | const wchar_t* const w_short_month_names[NumMonths]={L"Jan",L"Feb",L"Mar",L"Apr",L"May",L"Jun",L"Jul",L"Aug",L"Sep",L"Oct",L"Nov",L"Dec",L"NAM"}; 33 | const wchar_t* const w_long_month_names[NumMonths]={L"January",L"February",L"March",L"April",L"May",L"June",L"July",L"August",L"September",L"October",L"November",L"December",L"NotAMonth"}; 34 | const wchar_t* const w_special_value_names[date_time::NumSpecialValues]={L"not-a-date-time",L"-infinity",L"+infinity",L"min_date_time",L"max_date_time",L"not_special"}; 35 | 36 | const wchar_t* const w_short_weekday_names[]={L"Sun", L"Mon", L"Tue", 37 | L"Wed", L"Thu", L"Fri", L"Sat"}; 38 | const wchar_t* const w_long_weekday_names[]= {L"Sunday",L"Monday",L"Tuesday", 39 | L"Wednesday", L"Thursday", 40 | L"Friday", L"Saturday"}; 41 | #endif // BOOST_NO_STD_WSTRING 42 | } } // boost::gregorian 43 | #endif // DATE_TIME_SRC_GREG_NAMES_HPP___ 44 | -------------------------------------------------------------------------------- /src/gregorian/greg_weekday.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002-2004 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | * $Date$ 7 | */ 8 | 9 | 10 | 11 | #ifndef BOOST_DATE_TIME_SOURCE 12 | #define BOOST_DATE_TIME_SOURCE 13 | #endif 14 | #include "boost/date_time/gregorian/greg_weekday.hpp" 15 | 16 | #include "greg_names.hpp" 17 | 18 | namespace boost { 19 | namespace gregorian { 20 | 21 | //! Return a 3 digit english string of the day of week (eg: Sun) 22 | const char* 23 | greg_weekday::as_short_string() const 24 | { 25 | return short_weekday_names[value_]; 26 | } 27 | //! Return a point to a long english string representing day of week 28 | const char* 29 | greg_weekday::as_long_string() const 30 | { 31 | return long_weekday_names[value_]; 32 | } 33 | 34 | #ifndef BOOST_NO_STD_WSTRING 35 | //! Return a 3 digit english wchar_t string of the day of week (eg: Sun) 36 | const wchar_t* 37 | greg_weekday::as_short_wstring() const 38 | { 39 | return w_short_weekday_names[value_]; 40 | } 41 | //! Return a point to a long english wchar_t string representing day of week 42 | const wchar_t* 43 | greg_weekday::as_long_wstring() const 44 | { 45 | return w_long_weekday_names[value_]; 46 | } 47 | #endif // BOOST_NO_STD_WSTRING 48 | 49 | } } //namespace gregorian 50 | 51 | -------------------------------------------------------------------------------- /src/gregorian/gregorian_types.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | * $Date$ 7 | */ 8 | 9 | 10 | /** @defgroup date_basics Date Basics 11 | This page summarizes some of the key user types and functions needed 12 | to write programs using the gregorian date system. This is not a 13 | comprehensive list, but rather some key types to start exploring. 14 | 15 | 16 | **/ 17 | 18 | /** @defgroup date_alg Date Algorithms / Generators 19 | Date algorithms or generators are tools for generating other dates or 20 | schedules of dates. A generator function starts with some part of a 21 | date such as a month and day and is supplied another part to then 22 | generate a final date. 23 | 24 | **/ 25 | 26 | /** @defgroup date_format Date Formatting 27 | The functions on these page are some of the key formatting functions 28 | for dates. 29 | **/ 30 | 31 | 32 | //File doesn't have a current purpose except to generate docs 33 | //and keep it changeable without recompiles 34 | /*! @example days_alive.cpp 35 | Calculate the number of days you have been living using durations and dates. 36 | */ 37 | /*! @example days_till_new_year.cpp 38 | Calculate the number of days till new years 39 | */ 40 | /*! @example print_month.cpp 41 | Simple utility to print out days of the month with the days of a month. Demontstrates date iteration (date_time::date_itr). 42 | */ 43 | /*! @example localization.cpp 44 | An example showing localized stream-based I/O. 45 | */ 46 | /*! @example dates_as_strings.cpp 47 | Various parsing and output of strings (mostly supported for 48 | compilers that do not support localized streams). 49 | */ 50 | /*! @example period_calc.cpp 51 | Calculates if a date is in an 'irregular' collection of periods using 52 | period calculation functions. 53 | */ 54 | /*! @example print_holidays.cpp 55 | This is an example of using functors to define a holiday schedule 56 | */ 57 | /*! @example localization.cpp 58 | Demonstrates the use of facets to localize date output for Gregorian dates. 59 | */ 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/posix_time/posix_time_types.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* Copyright (c) 2002-2004 CrystalClear Software, Inc. 3 | * Use, modification and distribution is subject to the 4 | * Boost Software License, Version 1.0. (See accompanying 5 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 | * Author: Jeff Garland 7 | * $Date$ 8 | */ 9 | 10 | 11 | //File doesn't have a current purpose except to generate docs 12 | //and keep it changeable without recompiles 13 | 14 | /** @defgroup time_basics Time Basics 15 | 16 | **/ 17 | 18 | /** @defgroup time_format Time Formatting 19 | 20 | **/ 21 | 22 | 23 | 24 | /*! @example local_utc_conversion.cpp 25 | Demonstrate utc to local and local to utc calculations including dst. 26 | */ 27 | /*! @example time_periods.cpp Demonstrate some simple uses of time periods. 28 | */ 29 | /*! @example print_hours.cpp Demonstrate time iteration, clock retrieval, and simple calculation. 30 | */ 31 | /*! @example time_math.cpp Various types of calculations with times and time durations. 32 | */ 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/gregorian/testcurrent_day.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include "boost/date_time/gregorian/gregorian.hpp" 9 | #include 10 | 11 | int 12 | main() 13 | { 14 | 15 | boost::gregorian::date d1(boost::gregorian::day_clock::local_day()); 16 | std::cout << "Check the printed date by hand: " 17 | << boost::gregorian::to_iso_string(d1) << std::endl; 18 | 19 | using namespace boost::gregorian; 20 | date::ymd_type ymd = day_clock::local_day_ymd(); 21 | std::cout << ymd.year << "-" 22 | << ymd.month.as_long_string() << "-" 23 | << ymd.day << std::endl; 24 | 25 | date d2(day_clock::universal_day()); 26 | std::cout << "Getting UTC date: " 27 | << to_iso_string(d2) << std::endl; 28 | 29 | date::ymd_type ymd2 = day_clock::universal_day_ymd(); 30 | std::cout << ymd2.year << "-" 31 | << ymd2.month.as_long_string() << "-" 32 | << ymd2.day << std::endl; 33 | 34 | return 0; 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /test/gregorian/testdate_duration.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | */ 7 | 8 | #include "boost/date_time/gregorian/gregorian.hpp" 9 | #include "../testfrmwk.hpp" 10 | #include 11 | 12 | 13 | void test_date_duration() 14 | { 15 | using namespace boost::gregorian; 16 | 17 | date_duration threeDays(3); 18 | date_duration twoDays(2); 19 | //date_duration zeroDays(0); 20 | check("Self equal case", threeDays == threeDays); 21 | check("Not equal case", !(threeDays == twoDays)); 22 | check("Less case succeed", twoDays < threeDays); 23 | check("Not less case", !(threeDays < twoDays)); 24 | check("Not less case - equal", !(threeDays < threeDays)); 25 | check("Greater than ", !(threeDays > threeDays)); 26 | check("Greater equal ", threeDays >= threeDays); 27 | check("Greater equal - false", !(twoDays >= threeDays)); 28 | check("add", twoDays + threeDays == date_duration(5)); 29 | date_duration fiveDays = threeDays; 30 | fiveDays += twoDays; 31 | check("add", fiveDays == date_duration(5)); 32 | date_duration tenDays = fiveDays; 33 | tenDays += date_duration(5); 34 | check("add", tenDays.days() == 10); 35 | 36 | date_duration derivedOneDay = threeDays - twoDays; 37 | check("Subtraction - neg result", twoDays - threeDays == date_duration(-1)); 38 | date_duration oneDay(1); 39 | check("Subtraction", oneDay == derivedOneDay); 40 | date_duration fiveDaysDerived = tenDays; 41 | fiveDaysDerived -= fiveDays; 42 | check("Subtraction", fiveDaysDerived == fiveDays); 43 | 44 | oneDay = twoDays / 2; 45 | check("Division", oneDay.days() == 1); 46 | date_duration oneDayDivide = threeDays / 2; 47 | check("Division", oneDayDivide.days() == 1); 48 | date_duration hundred(100); 49 | hundred /= -10; 50 | check("Division", hundred.days() == -10 && hundred.is_negative()); 51 | 52 | date_duration pos_dur(123); 53 | date_duration neg_dur(-pos_dur); 54 | check("unary-", neg_dur.days() == -123); 55 | 56 | // special values tests 57 | date_duration pi_dur(pos_infin); 58 | date_duration ni_dur(neg_infin); 59 | date_duration nd_dur(not_a_date_time); 60 | check("pos_inf + neg_inf", (pi_dur + ni_dur) == nd_dur); 61 | //check("inf * integer", (pi_dur * 2) == pi_dur); // not implemented 62 | check("neg_inf / integer", (ni_dur / 3) == ni_dur); 63 | check("inf + dur", (pi_dur + hundred) == pi_dur); 64 | check("unary-", date_duration(-pi_dur) == ni_dur); 65 | 66 | // date_duration dd(1); 67 | // dd++; 68 | // check("Increment", dd == twoDays); 69 | 70 | } 71 | 72 | int main() { 73 | test_date_duration(); 74 | return printTestStats(); 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /test/gregorian/testformatters.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | */ 7 | 8 | #include "boost/date_time/gregorian/gregorian.hpp" 9 | #include "../testfrmwk.hpp" 10 | 11 | int 12 | main() 13 | { 14 | 15 | boost::gregorian::date d1(2002,01,02); 16 | std::string ds1 = boost::gregorian::to_simple_string(d1); 17 | check("check string: " + ds1, ds1 == "2002-Jan-02"); 18 | 19 | std::string ids1(boost::gregorian::to_iso_string(d1)); 20 | // std::cout << boost::gregorian::to_iso_string(d1) << std::endl; 21 | check("check iso normal: " + ids1, ids1 == "20020102"); 22 | 23 | std::string sds1 = boost::gregorian::to_sql_string(d1); 24 | check("check sql string: "+sds1, sds1 == "2002-01-02"); 25 | 26 | boost::gregorian::date d2(2001,12,30); 27 | std::string ds2 = boost::gregorian::to_simple_string(d2); 28 | check("check string: "+ds2, ds2 == "2001-Dec-30"); 29 | std::string ids2 = boost::gregorian::to_iso_extended_string(d2); 30 | check("check iso extended string: "+ids2, ids2 == "2001-12-30"); 31 | 32 | using namespace boost::gregorian; 33 | date d3(neg_infin); 34 | std::cout << "|" << to_simple_string(d3) << "|" << std::endl; 35 | check("check negative infinity", 36 | (to_simple_string(d3) == std::string("-infinity"))); 37 | date d4(pos_infin); 38 | check("check positive infinity", 39 | (to_simple_string(d4) == std::string("+infinity"))); 40 | date d5(not_a_date_time); 41 | std::cout << to_simple_string(d5) << "|" << std::endl; 42 | check("check not a date", 43 | (to_simple_string(d5) == std::string("not-a-date-time"))); 44 | 45 | date_period p1(date(2000,Jan,1), date(2001,Jan,1)); 46 | check("check period format", 47 | (to_simple_string(p1) == std::string("[2000-Jan-01/2000-Dec-31]"))); 48 | date_period p2(date(2000,Jan,1), date(pos_infin)); 49 | check("check period format", 50 | (to_simple_string(p2) == std::string("[2000-Jan-01/+infinity]"))); 51 | std::cout << to_simple_string(p2) << std::endl; 52 | 53 | 54 | 55 | // TODO enhance wchar support 56 | // std::wstringstream wss; 57 | // wss << d3 << std::endl; 58 | // std::wcout << d3; 59 | return printTestStats(); 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /test/gregorian/testgreg_day.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include "boost/date_time/gregorian/greg_day.hpp" 9 | #include "boost/date_time/gregorian/greg_weekday.hpp" 10 | #include "boost/date_time/gregorian/greg_day_of_year.hpp" 11 | #include "../testfrmwk.hpp" 12 | #include 13 | 14 | 15 | void 16 | test_day() 17 | { 18 | using namespace boost::gregorian; 19 | greg_day d1(1); 20 | check("Basic test", d1 == 1); 21 | try { 22 | greg_day bad(0); 23 | check("Bad day creation", false); //oh oh, fail 24 | //unreachable 25 | std::cout << "Shouldn't reach here: " << bad << std::endl; 26 | } 27 | catch(std::exception &) { 28 | check("Bad day creation", true); //good 29 | 30 | } 31 | try { 32 | greg_day bad(32); 33 | check("Bad day creation2", false); //oh oh, fail 34 | //unreachable 35 | std::cout << "Shouldn't reach here: " << bad << std::endl; 36 | } 37 | catch(std::exception&) { 38 | check("Bad day creation2", true); //good 39 | 40 | } 41 | check("traits min day", (greg_day::min)() == 1); 42 | check("traits max day", (greg_day::max)() == 31); 43 | 44 | greg_weekday sunday(0); 45 | greg_weekday monday(1); 46 | 47 | check("Weekday 0 short name == Sun", 48 | sunday.as_short_string() == std::string("Sun")); 49 | check("Weekday 1 short name == Mon", 50 | monday.as_short_string() == std::string("Mon")); 51 | check("Weekday 2 short name == Tue", 52 | greg_weekday(2).as_short_string() == std::string("Tue")); 53 | check("Weekday 3 short name == Wed", 54 | greg_weekday(3).as_short_string() == std::string("Wed")); 55 | check("Weekday 4 short name == Thu", 56 | greg_weekday(4).as_short_string() == std::string("Thu")); 57 | check("Weekday 5 short name == Fri", 58 | greg_weekday(5).as_short_string() == std::string("Fri")); 59 | check("Weekday 6 short name == Sat", 60 | greg_weekday(6).as_short_string() == std::string("Sat")); 61 | try { 62 | greg_weekday bad(7); 63 | check("Bad weekday creation", false); //oh oh, fail 64 | //unreachable 65 | std::cout << "Shouldn't reach here: " << bad << std::endl; 66 | } 67 | catch(bad_weekday&) { 68 | check("Bad weekday creation", true); //good 69 | 70 | } 71 | 72 | try { 73 | greg_day_of_year_rep bad(367); 74 | check("Bad day of year", false); //oh oh, fail 75 | //unreachable 76 | std::cout << "Shouldn't reach here: " << bad << std::endl; 77 | 78 | } 79 | catch(bad_day_of_year&) { 80 | check("Bad day of year", true); //good 81 | } 82 | 83 | } 84 | 85 | int 86 | main() 87 | { 88 | test_day(); 89 | return printTestStats(); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /test/gregorian/testgreg_year.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include "boost/date_time/gregorian/greg_year.hpp" 9 | #include "../testfrmwk.hpp" 10 | #include 11 | #include 12 | 13 | void test_yearlimit(int yr, bool allowed) 14 | { 15 | std::stringstream sdesc; 16 | sdesc << "should" << (allowed ? "" : " not") << " be able to make a year " << yr; 17 | 18 | try { 19 | boost::gregorian::greg_year chkyr(yr); 20 | check(sdesc.str(), allowed); 21 | if (allowed) { 22 | check_equal("year operator ==", chkyr, yr); 23 | } 24 | } 25 | catch (std::out_of_range&) { check(sdesc.str(), !allowed); } 26 | } 27 | 28 | int 29 | main() 30 | { 31 | // trac-13159 better limit testing 32 | test_yearlimit( 0, false); 33 | test_yearlimit( 1399, false); 34 | test_yearlimit( 1400, true); 35 | test_yearlimit( 1401, true); 36 | test_yearlimit( 9999, true); 37 | test_yearlimit(10000, false); 38 | test_yearlimit(10001, false); 39 | 40 | check("traits min year", (boost::gregorian::greg_year::min)() == 1400); 41 | check("traits max year", (boost::gregorian::greg_year::max)() == 9999); 42 | 43 | return printTestStats(); 44 | } 45 | 46 | -------------------------------------------------------------------------------- /test/local_time/README.poorly_formed_zonespec: -------------------------------------------------------------------------------- 1 | The file "poorly_formed_zonespec.csv" is only used for testing. 2 | 3 | This file has the wrong number of fields in it and should not be used for 4 | any other prupose. 5 | -------------------------------------------------------------------------------- /test/local_time/poorly_formed_zonespec.csv: -------------------------------------------------------------------------------- 1 | "ID","STD ABBR","STD NAME","DST ABBR","DST NAME","GMT offset","DST adjustment","DST Start Date rule","Start time","DST End date rule","End time" 2 | "Unique/Zone_name","GMT","","+00:00:00" 3 | -------------------------------------------------------------------------------- /test/local_time/testclocks.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 2 | * Subject to the Boost Software License, Version 1.0. 3 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 4 | * Author: Jeff Garland, Bart Garst 5 | * $Date$ 6 | */ 7 | 8 | #include "boost/date_time/local_time/local_time.hpp" 9 | #include 10 | 11 | // The actual clocks are tested in posix_time/testclock.cpp. 12 | // These tests are to verify that the time zone is applied correctly 13 | 14 | int 15 | main() 16 | { 17 | using namespace boost::gregorian; 18 | using namespace boost::posix_time; 19 | using namespace boost::local_time; 20 | 21 | 22 | boost::shared_ptr az_tz(new posix_time_zone("MST-07")); 23 | boost::shared_ptr ny_tz(new posix_time_zone("EST-05EDT,M4.1.0,M10.5.0")); 24 | 25 | ptime tl = second_clock::local_time(); 26 | std::cout << tl << std::endl; 27 | local_date_time ldt1 = local_sec_clock::local_time(az_tz); 28 | std::cout << ldt1.to_string() << std::endl; 29 | local_date_time ldt2 = local_sec_clock::local_time(ny_tz); 30 | std::cout << ldt2.to_string() << std::endl; 31 | 32 | tl = microsec_clock::local_time(); 33 | std::cout << tl << std::endl; 34 | local_date_time ldt3 = local_microsec_clock::local_time(az_tz); 35 | std::cout << ldt3.to_string() << std::endl; 36 | local_date_time ldt4 = local_microsec_clock::local_time(ny_tz); 37 | std::cout << ldt4.to_string() << std::endl; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /test/local_time/testdst_transition_day_rule.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 2 | * Subject to the Boost Software License, Version 1.0. 3 | * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 4 | * Author: Jeff Garland, Bart Garst 5 | * $Date$ 6 | */ 7 | 8 | #include "boost/date_time/gregorian/gregorian.hpp" 9 | #include "boost/date_time/local_time/dst_transition_day_rules.hpp" 10 | #include "boost/shared_ptr.hpp" 11 | #include "../testfrmwk.hpp" 12 | 13 | 14 | 15 | // see http://www.timeanddate.com/time/aboutdst.html for some info 16 | // also 17 | int 18 | main() 19 | { 20 | // using namespace boost::posix_time; 21 | using namespace boost::local_time; 22 | using namespace boost::gregorian; 23 | 24 | boost::shared_ptr 25 | rule1(new partial_date_dst_rule(partial_date(30,Apr), 26 | partial_date(30,Oct))); 27 | 28 | check("partial date rule", rule1->start_day(2001) == date(2001, Apr, 30)); 29 | check("partial date rule", rule1->end_day(2001) == date(2001, Oct, 30)); 30 | 31 | boost::shared_ptr 32 | rule2(new first_last_dst_rule(first_last_dst_rule::start_rule(Sunday,Apr), 33 | first_last_dst_rule::end_rule(Sunday,Oct))); 34 | 35 | check("first last rule", rule2->start_day(2001) == date(2001, Apr, 1)); 36 | check("first last rule", rule2->end_day(2001) == date(2001, Oct, 28)); 37 | 38 | boost::shared_ptr 39 | rule3(new last_last_dst_rule(last_last_dst_rule::start_rule(Sunday,Mar), 40 | last_last_dst_rule::end_rule(Sunday,Oct))); 41 | 42 | check("last last rule", rule3->start_day(2001) == date(2001, Mar, 25)); 43 | check("last last rule", rule3->end_day(2001) == date(2001, Oct, 28)); 44 | 45 | typedef nth_kday_of_month nkday; 46 | boost::shared_ptr 47 | rule4(new nth_last_dst_rule(nth_last_dst_rule::start_rule(nkday::first,Sunday,Mar), 48 | nth_last_dst_rule::end_rule(Sunday,Oct))); 49 | 50 | check("nth Last rule", rule4->start_day(2001) == date(2001, Mar, 4)); 51 | check("nth Last rule", rule4->end_day(2001) == date(2001, Oct, 28)); 52 | 53 | boost::shared_ptr 54 | rule5(new nth_kday_dst_rule(nth_kday_dst_rule::start_rule(nkday::first,Sunday,Mar), 55 | nth_kday_dst_rule::end_rule(nkday::fourth,Sunday,Oct))); 56 | 57 | check("nth_kday rule", rule5->start_day(2001) == date(2001, Mar, 4)); 58 | check("nth_kday rule", rule5->end_day(2001) == date(2001, Oct, 28)); 59 | 60 | 61 | 62 | return printTestStats(); 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /test/local_time/testlocal_time_iterator.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | * $Date$ 7 | */ 8 | 9 | #include 10 | #include "boost/date_time/local_time/local_time.hpp" 11 | #include "../testfrmwk.hpp" 12 | // #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) 13 | // #include "boost/date_time/gregorian/formatters_limited.hpp" 14 | // #else 15 | // #include "boost/date_time/gregorian/formatters.hpp" 16 | // #endif 17 | 18 | using namespace boost::posix_time; 19 | using namespace boost::gregorian; 20 | using namespace boost::local_time; 21 | 22 | void iterate_backward(const local_date_time *answers, 23 | int ary_len, 24 | const time_duration& td) 25 | { 26 | int i = ary_len -1; 27 | local_date_time end = answers[i]; 28 | local_time_iterator titr(end,td); 29 | 30 | std::cout << "counting down by previous duration..." << std::endl; 31 | for (; titr >= answers[0]; --titr) { 32 | std::cout << *titr << std::endl; 33 | check("iterating backward", answers[i] == *titr); 34 | --i; 35 | } 36 | check("iterating backward count", i == -1); // check the number of iterations 37 | std::cout << std::endl; 38 | } 39 | 40 | int 41 | main() 42 | { 43 | 44 | time_zone_ptr ny_tz(new posix_time_zone("EST-05EDT,M4.1.0,M10.5.0")); 45 | 46 | //set up a time right on the dst boundary -- iterator will 47 | //jump forward an hour at the boundary 48 | date d(2005,Apr,3); 49 | time_duration dst_offset(1,59,59); 50 | local_date_time start(d, dst_offset, ny_tz, false); 51 | 52 | const local_date_time answer1[] = 53 | { 54 | local_date_time(d,dst_offset, ny_tz, false), 55 | local_date_time(d,hours(3), ny_tz, true), 56 | local_date_time(d,hours(3)+seconds(1), ny_tz, true), 57 | local_date_time(d,hours(3)+seconds(2), ny_tz, true) 58 | }; 59 | 60 | int i=0; 61 | local_time_iterator titr(start,seconds(1)); 62 | local_date_time end = start + seconds(4); 63 | for (; titr < end; ++titr) { 64 | std::cout << (*titr) << std::endl; 65 | check("iterator -- 1 sec", answer1[i] == *titr); 66 | i++; 67 | } 68 | check("iterator -- 1 sec -- num iterations", i == 4); // check the number of iterations 69 | 70 | iterate_backward(answer1, 4, seconds(1)); 71 | 72 | //iterate by hours 73 | const local_date_time answer2[] = 74 | { local_date_time(d,dst_offset, ny_tz, false), 75 | local_date_time(d,dst_offset+hours(2), ny_tz, true), 76 | local_date_time(d,dst_offset+hours(3), ny_tz, true), 77 | local_date_time(d,dst_offset+hours(4), ny_tz, true) 78 | }; 79 | i=0; 80 | local_time_iterator titr2(start,hours(1)); 81 | local_date_time end2 = start + hours(4); 82 | for (; titr2 < end2; ++titr2) { 83 | std::cout << *titr2 << std::endl; 84 | check("iterator -- 1 hour", answer2[i] == *titr2); 85 | i++; 86 | } 87 | check("iterator -- 1 hour -- num iterations", i == 4); 88 | 89 | iterate_backward(answer2, 4, hours(1)); 90 | 91 | 92 | 93 | return printTestStats(); 94 | } 95 | 96 | -------------------------------------------------------------------------------- /test/posix_time/compile_fail/hours_special_value.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 James E. King III 3 | // Use, modification and distribution is subject to the 4 | // Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | using boost::date_time::pos_infin; 15 | using boost::posix_time::hours; 16 | boost::ignore_unused(hours(static_cast(pos_infin))); // compiles: it's an integral 17 | boost::ignore_unused(hours(pos_infin)); // won't compile: not an integral 18 | return 1; // return an error if we actually compile 19 | } 20 | -------------------------------------------------------------------------------- /test/posix_time/compile_fail/millisec_special_value.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 James E. King III 3 | // Use, modification and distribution is subject to the 4 | // Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | using boost::date_time::pos_infin; 15 | using boost::posix_time::millisec; 16 | boost::ignore_unused(millisec(static_cast(pos_infin))); // compiles: it's a number 17 | boost::ignore_unused(millisec(pos_infin)); // won't compile: not an integral 18 | return 1; // return an error if we actually run for some reason 19 | } 20 | -------------------------------------------------------------------------------- /test/posix_time/compile_fail/minutes_special_value.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 James E. King III 3 | // Use, modification and distribution is subject to the 4 | // Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | using boost::date_time::pos_infin; 15 | using boost::posix_time::minutes; 16 | boost::ignore_unused(minutes(static_cast(pos_infin))); // compiles: it's an integral 17 | boost::ignore_unused(minutes(pos_infin)); // won't compile: not an integral 18 | return 1; // return an error if we actually run for some reason 19 | } 20 | -------------------------------------------------------------------------------- /test/posix_time/compile_fail/seconds_special_value.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 James E. King III 3 | // Use, modification and distribution is subject to the 4 | // Boost Software License, Version 1.0. (See accompanying 5 | // file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 6 | // 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | using boost::date_time::pos_infin; 15 | using boost::posix_time::seconds; 16 | boost::ignore_unused(seconds(static_cast(pos_infin))); // compiles: it's an integral 17 | boost::ignore_unused(seconds(pos_infin)); // won't compile: not an integral 18 | return 1; // return an error if we actually run for some reason 19 | } 20 | -------------------------------------------------------------------------------- /test/posix_time/testclock.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include 9 | #include "boost/date_time/posix_time/posix_time.hpp" 10 | #include 11 | 12 | int 13 | main() 14 | { 15 | 16 | using namespace boost::posix_time; 17 | ptime tl = second_clock::local_time(); 18 | std::cout << tl << std::endl; 19 | 20 | ptime tu = second_clock::universal_time(); 21 | std::cout << tu << std::endl; 22 | 23 | #if !defined(BOOST_WINDOWS) && defined(_POSIX_TIMERS) 24 | for (int i=0; i < 3; ++i) { 25 | ptime t2 = second_clock::local_time(); 26 | std::cout << t2 << std::endl; 27 | sleep(1); 28 | } 29 | #endif 30 | 31 | #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK 32 | for (int i=0; i < 10; ++i) { 33 | //ptime t2 = high_precision_clock::local_time(); 34 | ptime t2 = microsec_clock::local_time(); 35 | std::cout << t2 << std::endl; 36 | } 37 | #endif // BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK 38 | 39 | return 0; 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /test/posix_time/testformatters.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | */ 7 | 8 | #include "boost/date_time/posix_time/posix_time.hpp" 9 | #include "../testfrmwk.hpp" 10 | 11 | int 12 | main() 13 | { 14 | //This has been deprecated for testtime_formatters.cpp 15 | return 0; 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /test/posix_time/testgreg_duration_operators.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland, Bart Garst 6 | */ 7 | 8 | #include "boost/date_time/gregorian/gregorian.hpp" 9 | #include "boost/date_time/posix_time/posix_time.hpp" 10 | #include "../testfrmwk.hpp" 11 | 12 | 13 | int main(){ 14 | 15 | #if !defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) 16 | // do not set this test to return fail - 17 | // this is not necessarily a compiler problem 18 | check("Optional gregorian types not selected - no tests run", true); 19 | #else 20 | 21 | using namespace boost::gregorian; 22 | using namespace boost::posix_time; 23 | 24 | 25 | /*** months ***/ 26 | { 27 | ptime p(date(2001, Oct, 31), hours(5)); 28 | check("ptime + months", 29 | ptime(date(2002, Feb, 28), hours(5)) == p + months(4)); 30 | p += months(4); 31 | check("ptime += months", 32 | ptime(date(2002, Feb, 28), hours(5)) == p); 33 | } 34 | { 35 | ptime p(date(2001, Oct, 31), hours(5)); 36 | check("ptime - months", 37 | ptime(date(2001, Apr, 30), hours(5)) == p - months(6)); 38 | p -= months(6); 39 | check("ptime -= months", 40 | ptime(date(2001, Apr, 30), hours(5)) == p); 41 | } 42 | 43 | /*** years ***/ 44 | { 45 | ptime p(date(2001, Feb, 28), hours(5)); 46 | check("ptime + years", 47 | ptime(date(2004, Feb, 29), hours(5)) == p + years(3)); 48 | p += years(3); 49 | check("ptime += years", 50 | ptime(date(2004, Feb, 29), hours(5)) == p); 51 | } 52 | { 53 | ptime p(date(2000, Feb, 29), hours(5)); 54 | check("ptime - years", 55 | ptime(date(1998, Feb, 28), hours(5)) == p - years(2)); 56 | p -= years(2); 57 | check("ptime -= years", 58 | ptime(date(1998, Feb, 28), hours(5)) == p); 59 | } 60 | 61 | 62 | /*** weeks ***/ 63 | // shouldn't need many tests, it is nothing more than a date_duration 64 | // so all date_duration tests should prove this class 65 | { 66 | ptime p(date(2001, Feb, 28), hours(5)); 67 | check("ptime + weeks", 68 | ptime(date(2001, Mar, 21), hours(5)) == p + weeks(3)); 69 | p += weeks(3); 70 | check("ptime += weeks", 71 | ptime(date(2001, Mar, 21), hours(5)) == p); 72 | } 73 | { 74 | ptime p(date(2001, Feb, 28), hours(5)); 75 | check("ptime - weeks", 76 | ptime(date(2001, Feb, 14), hours(5)) == p - weeks(2)); 77 | p -= weeks(2); 78 | check("ptime -= weeks", 79 | ptime(date(2001, Feb, 14), hours(5)) == p); 80 | } 81 | 82 | #endif // BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES 83 | 84 | return printTestStats(); 85 | } 86 | -------------------------------------------------------------------------------- /test/posix_time/testperiod.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include 9 | #include "boost/date_time/posix_time/posix_time.hpp" 10 | #include "boost/date_time/posix_time/time_period.hpp" 11 | #include "../testfrmwk.hpp" 12 | 13 | int main() 14 | { 15 | 16 | //FILE OBSOLETE: replace by testtime_period.cpp 17 | 18 | return 1; 19 | // return printTestStats(); 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /test/posix_time/testtime_period.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include 9 | #include "boost/date_time/posix_time/posix_time.hpp" 10 | #include "boost/date_time/posix_time/time_period.hpp" 11 | #include "../testfrmwk.hpp" 12 | 13 | int main() 14 | { 15 | using namespace boost::gregorian; 16 | using namespace boost::posix_time; 17 | date d1(2001,Jan, 1); 18 | ptime t1 (d1,hours(2));//2001-Jan-1 02:00:00 19 | ptime t2 (d1,hours(3));//2001-Jan-1 03:00:00 20 | time_period p1(t1,t2); //2001-Jan-1 02:59:59 21 | time_period p2(p1); 22 | check("copy construct & ==", p1 == p2); 23 | time_period p3 = p2; 24 | check("assignment", p3 == p2); 25 | time_period p4(t1,hours(1)); 26 | check("length", p4.length() == hours(1)); 27 | std::cout << t1 << std::endl; 28 | std::cout << p4 << std::endl; 29 | std::cout << p1 << std::endl; 30 | check("construction and ==", p1 == p4); 31 | check("begin", p1.begin() == t1); 32 | check("last", p1.end() == t2); 33 | check("end", p1.last() == t2-time_duration::unit()); 34 | 35 | std::cout << p1 << std::endl; 36 | // check("last", p1.() == t2); 37 | check("contains begin", p1.contains(t1)); 38 | check("contains end-not", !p1.contains(t2)); 39 | check("contains last", p1.contains(t2-seconds(1))); 40 | ptime t3(date(2001,Jan,1),hours(4)); 41 | time_period p5(t2,t3); 42 | check("check contains", !p1.contains(p5.begin())); 43 | check("check contains", !p5.contains(p1.begin())); 44 | check("operator== not equal case", !(p1 == p5)); 45 | check("less than order", p1 < p5); 46 | check("greater than order", p5 > p1); 47 | check("not equal", p5 != p1); 48 | check("intersects with myself", p1.intersects(p1)); 49 | check("not intersects", !(p1.intersects(p5))); 50 | check("not intersects", !(p5.intersects(p1))); 51 | 52 | time_period p6(p5); 53 | p6.shift(minutes(30)); 54 | std::cout << p5 << std::endl; 55 | std::cout << p6 << std::endl; 56 | check("shifted intersects", p5.intersects(p6)); 57 | check("shifted intersects", p6.intersects(p5)); 58 | check("contains begin", p5.contains(p6.begin())); 59 | p6.shift(minutes(30)); 60 | std::cout << p5 << std::endl; 61 | std::cout << p6 << std::endl; 62 | check("shifted !intersects", !p5.intersects(p6)); 63 | check("shifted !intersects", !p6.intersects(p5)); 64 | p6.shift(minutes(-30)); 65 | std::cout << p5 << std::endl; 66 | std::cout << p6 << std::endl; 67 | time_period p7 = p5.intersection(p6); 68 | std::cout << p7 << std::endl; 69 | check("shifted intersection", 70 | p7 == time_period(ptime(d1,time_duration(3,30,0)), 71 | ptime(d1,time_duration(4,0,0)))); 72 | 73 | 74 | return printTestStats(); 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /test/posix_time/testtime_serialize_versioning.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017 James E. King III 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "../testfrmwk.hpp" 13 | #include 14 | 15 | using namespace boost; 16 | using namespace posix_time; 17 | 18 | void check_filesize(const std::string& filename, std::ifstream::pos_type expectedSize) 19 | { 20 | std::ifstream in(filename.c_str(), std::ifstream::ate | std::ifstream::binary); 21 | check_equal("check file size is " + boost::lexical_cast(expectedSize), in.tellg(), expectedSize); 22 | } 23 | 24 | std::string get_fname(int version) 25 | { 26 | return "time_duration_serialization." + 27 | std::string((sizeof(size_t) == 4) ? "x32" : "x64") + 28 | ".v" + boost::lexical_cast(version); 29 | } 30 | 31 | int main() { 32 | time_duration td(12, 13, 52, 123456); 33 | 34 | #if BOOST_DATE_TIME_POSIX_TIME_DURATION_VERSION == 0 35 | std::ofstream ofs(get_fname(0).c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); 36 | boost::archive::binary_oarchive oa(ofs); 37 | oa << td; 38 | ofs.close(); 39 | 40 | #if defined(_MSC_VER) 41 | check_filesize(get_fname(0), 58 + sizeof(size_t)); 42 | #endif 43 | 44 | #else // BOOST_DATE_TIME_POSIX_TIME_DURATION_VERSION > 0 45 | std::ifstream ifs(get_fname(0).c_str(), std::ios_base::binary | std::ios_base::in); 46 | boost::archive::binary_iarchive ia(ifs); 47 | time_duration tmp; 48 | ia >> tmp; 49 | ifs.close(); 50 | check_equal("read older version structure ok", td, tmp); 51 | 52 | std::ofstream ofs(get_fname(1).c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); 53 | boost::archive::binary_oarchive oa(ofs); 54 | oa << td; 55 | ofs.close(); 56 | 57 | #if defined(_MSC_VER) 58 | check_filesize(get_fname(1), 70 + sizeof(size_t)); 59 | #endif 60 | 61 | #endif // BOOST_DATE_TIME_POSIX_TIME_DURATION_VERSION 62 | 63 | return printTestStats(); 64 | } 65 | -------------------------------------------------------------------------------- /test/posix_time/testtime_wstream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003-2004 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Bart Garst 6 | * $Date$ 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "../testfrmwk.hpp" 13 | #include 14 | 15 | using namespace boost::gregorian; 16 | using namespace boost::posix_time; 17 | using boost::lexical_cast; 18 | 19 | int main(){ 20 | #if defined(BOOST_NO_STD_WSTRING) || \ 21 | defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS) 22 | check("No wstring/wstream support for this compiler", false); 23 | #else 24 | 25 | std::wstring res, ws; 26 | std::wstringstream wss; 27 | /* time_period was used because all the time-type objects 28 | * that have operator<< can be easily accessed from it. 29 | * Tose are: ptime, time_duration, time_period */ 30 | date d1(2003,Jan,20), d2(2003,May,10); 31 | time_period tp(ptime(d1,hours(1)), ptime(d2,hours(15))); 32 | 33 | // ptime 34 | wss << tp.begin(); 35 | res = L"2003-Jan-20 01:00:00"; 36 | check("ptime op<<", res == wss.str()); 37 | wss.str(L""); 38 | ws = to_simple_wstring(tp.begin()); 39 | check("ptime to_simple_wstring", res == ws); 40 | res = L"20030120T010000"; 41 | ws = to_iso_wstring(tp.begin()); 42 | check("ptime to_iso_wstring", res == ws); 43 | res = L"2003-01-20T01:00:00"; 44 | ws = to_iso_extended_wstring(tp.begin()); 45 | check("ptime to_iso_extended_wstring", res == ws); 46 | 47 | // time_duration 48 | wss << tp.length(); 49 | res = L"2654:00:00"; 50 | check("time_duration", res == wss.str()); 51 | wss.str(L""); 52 | ws = to_simple_wstring(tp.length()); 53 | check("time_duration to_simple_wstring", res == ws); 54 | res = L"26540000"; 55 | ws = to_iso_wstring(tp.length()); 56 | check("time_duration to_iso_wstring", res == ws); 57 | 58 | // time_period 59 | wss << tp; 60 | #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 61 | res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999999]"; 62 | #else 63 | res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999]"; 64 | #endif 65 | check("time_period", res == wss.str()); 66 | wss.str(L""); 67 | ws = to_simple_wstring(tp); 68 | check("time_period to_simple_wstring", res == ws); 69 | 70 | // special values 71 | time_duration sv_td(neg_infin); 72 | date sv_d(pos_infin); 73 | ptime sv_tp(sv_d,hours(1)); 74 | res = L"+infinity"; 75 | wss << sv_tp; 76 | check("ptime op<< special value", res == wss.str()); 77 | wss.str(L""); 78 | ws = to_simple_wstring(sv_tp); 79 | check("ptime to_simple_wstring special value", res == ws); 80 | res = L"-infinity"; 81 | wss << sv_td; 82 | check("time_duration op<< special value", res == wss.str()); 83 | wss.str(L""); 84 | ws = to_simple_wstring(sv_td); 85 | check("time_duration to_simple_wstring special value", res == ws); 86 | 87 | #endif 88 | return printTestStats(); 89 | } 90 | -------------------------------------------------------------------------------- /test/self_contained_header.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Andrey Semashev 2020. 3 | * Distributed under the Boost Software License, Version 1.0. 4 | * (See accompanying file LICENSE_1_0.txt or copy at 5 | * http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | /*! 8 | * \file self_contained_header.cpp 9 | * \author Andrey Semashev 10 | * \date 04.04.2020 11 | * 12 | * \brief This file contains a test boilerplate for checking that every public header is self-contained and does not have any missing #includes. 13 | */ 14 | 15 | #define BOOST_DATE_TIME_TEST_INCLUDE_HEADER() 16 | 17 | #include BOOST_DATE_TIME_TEST_INCLUDE_HEADER() 18 | 19 | int main(int, char*[]) 20 | { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/testconstrained_value.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include "boost/config.hpp" 9 | #include "boost/date_time/constrained_value.hpp" 10 | #include "testfrmwk.hpp" 11 | #include 12 | 13 | class bad_day {}; //exception type 14 | 15 | 16 | class day_value_policies 17 | { 18 | public: 19 | typedef unsigned int value_type; 20 | static BOOST_CXX14_CONSTEXPR unsigned int min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }; 21 | static BOOST_CXX14_CONSTEXPR unsigned int max BOOST_PREVENT_MACRO_SUBSTITUTION () { return 31;}; 22 | static void on_error(unsigned int&, unsigned int, boost::CV::violation_enum) 23 | { 24 | throw bad_day(); 25 | } 26 | }; 27 | 28 | struct range_error {}; //exception type 29 | typedef boost::CV::simple_exception_policy one_to_ten_range_policy; 30 | 31 | int main() 32 | { 33 | using namespace boost::CV; 34 | constrained_value cv1(0), cv2(31); 35 | check("not equal", cv1 != cv2); 36 | check("equal", cv1 == cv1); 37 | check("greater", cv2 > cv1); 38 | check("greater or equal ", cv2 >= cv1); 39 | //various running of the conversion operator 40 | std::cout << cv1 << std::endl; 41 | unsigned int i = cv1; 42 | check("test conversion", i == cv1); 43 | 44 | #ifdef BOOST_NO_CXX14_CONSTEXPR 45 | check("constexpr not configured", true); 46 | #else 47 | //check constexpr case 48 | constexpr constrained_value cv3(1); 49 | static_assert(cv3 == 1, "constexpr construction/conversion"); 50 | check("constexpr constrained value construct and equal", true); 51 | #endif 52 | 53 | try { 54 | constrained_value cv3(11); 55 | std::cout << "Not Reachable: " << cv3 << " "; 56 | check("got range exception max", false); 57 | } 58 | catch(range_error&) { 59 | check("got range exception max", true); 60 | } 61 | 62 | try { 63 | constrained_value cv3(0); 64 | std::cout << "Not Reachable: " << cv3 << " "; 65 | check("got range exception min", false); 66 | } 67 | catch(range_error&) { 68 | check("got range exception min", true); 69 | } 70 | 71 | try { 72 | constrained_value cv4(1); 73 | cv4 = 12; 74 | check("range exception on assign", false); 75 | } 76 | catch(range_error&) { 77 | check("range exception on assign", true); 78 | } 79 | 80 | return printTestStats(); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /test/testfrom_facet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2004 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | * $Date$ 7 | * 8 | * This file isn't part of the official regression test suite at 9 | * the moment, but it is a basic test of the strings_from_facet.hpp 10 | * infrastructure that can be compiled trivially. 11 | */ 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "boost/date_time/strings_from_facet.hpp" 21 | #include "algorithm_ext/container_print.hpp" 22 | 23 | 24 | 25 | int 26 | main() 27 | { 28 | using boost::date_time::gather_month_strings; 29 | using boost::date_time::gather_weekday_strings; 30 | 31 | std::vector data; 32 | std::vector wdata; 33 | 34 | data = gather_month_strings(std::locale::classic()); 35 | print(data, std::cout); 36 | data = gather_month_strings(std::locale::classic(), false); 37 | print(data, std::cout); 38 | data = gather_weekday_strings(std::locale::classic()); 39 | print(data, std::cout); 40 | data = gather_weekday_strings(std::locale::classic(), false); 41 | print(data, std::cout); 42 | 43 | wdata = gather_month_strings(std::locale::classic()); 44 | std::wofstream wof("from_facet_test.out"); 45 | int i=0; 46 | while (i < wdata.size()) { 47 | wof << wdata[i] << std::endl; 48 | i++; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/testmisc.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2020 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include "boost/date_time/wrapping_int.hpp" 9 | 10 | //#include 11 | #include "boost/date_time/posix_time/posix_time_duration.hpp" 12 | 13 | #include "testfrmwk.hpp" 14 | #include 15 | 16 | using std::cout; 17 | using std::endl; 18 | 19 | int 20 | main() 21 | { 22 | using namespace boost::date_time; 23 | using namespace boost::posix_time; 24 | 25 | #ifdef BOOST_NO_CXX14_CONSTEXPR 26 | check("constexpr not configured", true); 27 | #else 28 | constexpr wrapping_int wi(3599); 29 | static_assert(wi == 3599, "constexpr construction/conversion"); 30 | check("constexpr wrapping construct and equal", true); 31 | 32 | constexpr microseconds ms(1000); 33 | static_assert(ms.is_special() == false, "constexpr duration is_special"); 34 | static_assert(ms.is_positive() == true, "constexpr duration is_positive"); 35 | static_assert(ms.is_negative() == false, "constexpr duration is_negative"); 36 | static_assert(ms.total_microseconds() == 1000, "constexpr total_microseconds"); 37 | check("constexpr microseconds - total_microseconds", true); 38 | 39 | #endif 40 | 41 | #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG 42 | cout << "Standard Config" << endl; 43 | #else 44 | cout << "NOT Standard Config" << endl; 45 | #endif 46 | 47 | #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS 48 | cout << "Has NANO: " << endl; 49 | #else 50 | cout << "NO NANO: " << endl; 51 | #endif 52 | 53 | check("success", true); 54 | 55 | return printTestStats(); 56 | 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /test/testtime_resolution_traits.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2002,2003 CrystalClear Software, Inc. 2 | * Use, modification and distribution is subject to the 3 | * Boost Software License, Version 1.0. (See accompanying 4 | * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 5 | * Author: Jeff Garland 6 | */ 7 | 8 | #include "boost/date_time/time_resolution_traits.hpp" 9 | #include "testfrmwk.hpp" 10 | 11 | 12 | int 13 | main() 14 | { 15 | using namespace boost::date_time; 16 | check("milli traits num digits", milli_res::num_fractional_digits() == 3); 17 | check("milli traits resolution adjust", 18 | milli_res::res_adjust() == 1000); 19 | check("milli tick calculations", 20 | milli_res::to_tick_count(0,0,0,1) == 1); 21 | check("milli tick calculations", 22 | milli_res::to_tick_count(0,0,1,1) == 1001); 23 | check("milli tick calculations", 24 | milli_res::to_tick_count(0,1,0,0) == 60000); 25 | boost::int64_t one_hour_milli = 3600*1000; 26 | check("milli tick calculations", 27 | milli_res::to_tick_count(1,0,0,0) == one_hour_milli); 28 | 29 | check("micro traits num digits", micro_res::num_fractional_digits() == 6); 30 | check("micro traits resolution adjust", 31 | micro_res::res_adjust() == 1000000); 32 | check("micro tick calculations", 33 | micro_res::to_tick_count(0,0,0,1) == 1); 34 | check("micro tick calculations", 35 | micro_res::to_tick_count(0,0,1,1) == 1000001); 36 | check("micro tick calculations", 37 | micro_res::to_tick_count(0,1,0,0) == 60000000); 38 | boost::int64_t one_hour_micro = 3600*1000; 39 | one_hour_micro = one_hour_micro*1000; //avoid compiler overflow! 40 | check("micro tick calculations", 41 | micro_res::to_tick_count(1,0,0,0) == one_hour_micro); 42 | 43 | check("nano traits num digits", nano_res::num_fractional_digits() == 9); 44 | check("nano traits resolution adjust", 45 | nano_res::res_adjust() == 1000000000); 46 | check("nano tick calculations", 47 | nano_res::to_tick_count(0,0,0,1) == 1); 48 | check("nano tick calculations", 49 | nano_res::to_tick_count(0,0,1,1) == 1000000001); 50 | boost::int64_t one_minute_nano = 60*1000*1000; 51 | one_minute_nano = one_minute_nano*1000; 52 | check("nano tick calculations", 53 | nano_res::to_tick_count(0,1,0,0) == one_minute_nano); 54 | 55 | //skip io on VC6 b/c of lack of operator<< for int64 56 | #if (defined(BOOST_MSVC) && (_MSC_VER < 1300)) 57 | #else 58 | std::cout << one_hour_micro << std::endl; 59 | #endif 60 | boost::int64_t one_hour_nano = one_hour_micro*1000; 61 | #if (defined(BOOST_MSVC) && (_MSC_VER < 1300)) 62 | #else 63 | std::cout << one_hour_nano << std::endl; 64 | #endif 65 | check("nano tick calculations", 66 | nano_res::to_tick_count(1,0,0,0) == one_hour_nano); 67 | 68 | 69 | return printTestStats(); 70 | 71 | } 72 | 73 | -------------------------------------------------------------------------------- /xmldoc/README: -------------------------------------------------------------------------------- 1 | I couldn't get the date_time.xml to validate, however, it works anyway. 2 | The build process with fail with adequate error messages to fix 3 | any errors. 4 | 5 | /********************************/ 6 | Do not place a dtd declaration in the doc xml files. 7 | Begin each file with: 8 |
19 | 20 | And in subsection/xml: 21 |
23 | 24 | ... 25 | 26 | 27 | 28 | /********************************/ 29 | To crosslink use: 30 | optional text 31 | 32 | If you use 'top' the link will automatically 33 | go to the top of the page it ends up in. 34 | 35 | # Copyright (c) 2002-2006 CrystalClear Software, Inc. 36 | # Use, modification and distribution is subject to the 37 | # Boost Software License, Version 1.0. (See accompanying 38 | # file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) 39 | -------------------------------------------------------------------------------- /xmldoc/acknowledgements.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Acknowledgements 12 | 13 | 14 | Many people have contributed to the development of this library. In particular Hugo Duncan and Joel de Guzman for help with porting to various compilers. For initial development of concepts and design Corwin Joy and Michael Kenniston deserve special thanks. Also extra thanks to Michael for writing up the theory and tradeoffs part of the documentation. Dave Zumbro for initial inspiration and sage thoughts. Many thanks to boost reviewers and users including: William Seymour, Kjell Elster, Beman Dawes, Gary Powell, Andrew Maclean, William Kempf, Peter Dimov, Chris Little, David Moore, Darin Adler, Gennadiy Rozental, Joachim Achtzehnter, Paul Bristow, Jan Langer, Mark Rodgers, Glen Knowles, Matthew Denman, and George Heintzelman. 15 | 16 |
17 | -------------------------------------------------------------------------------- /xmldoc/conceptual.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Conceptual 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | -------------------------------------------------------------------------------- /xmldoc/date_time.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | Jeff 11 | Garland 12 | 13 | 14 | 15 | 2001 16 | 2002 17 | 2003 18 | 2004 19 | 2005 20 | CrystalClear Software, Inc 21 | 22 | 23 | 24 | Subject to the Boost Software License, Version 1.0. (See accompanying file 25 | LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 27 | 28 | 29 | A set of facilities to ease programming with dates and times. 30 | 31 | 32 | 33 | 34 | Boost.Date_Time 35 | 36 | Introduction 37 | 38 | 39 | A set of date-time libraries based on generic programming concepts. 40 | 41 | 42 | This documentation is also available in PDF format. It can be found at: 43 | 44 | 45 | 46 | In addition, a full doxygen reference can be found at: 47 | 48 | 49 | 50 | The most current version of the documentation can be found at: 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /xmldoc/design_concepts.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Design Concepts 12 | 13 | 14 | A large part of the genesis of this library has been the observation that few date-time libraries are built in a fashion that allows customization and extension. A typical example, the calendar logic is built directly into the date class. Or the clock retrieval functions are built directly into the time class. These design decisions usually make it impossible to extend or change the library behavior. At a more fundamental level, there are usually assumptions about the resolution of time representation or the gregorian calendar. 15 | 16 | 17 | Often times, the result is that a project must settle for a less than complete library because of a requirement for high resolution time representation or other assumptions that do not match the implementation of the library. This is extremely unfortunate because development of a library of this sort is far from a trivial task. 18 | 19 | 20 | While the design is far from perfect the current design is far more flexible than any date-time library the author is aware of. It is expected that the various aspects of extensibility will be better documented in future versions. Information about the design goals of the library is summarized here. 21 | 22 |
23 | -------------------------------------------------------------------------------- /xmldoc/details.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Details 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | -------------------------------------------------------------------------------- /xmldoc/doxy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Library Reference 12 | 13 | 14 | The following is a detailed reference of the date_time library. A click on any of the reference links will take you to a list of the header files found in that section. Following one of those links will take you to a list of the items declared in that header file. Further sublinks take you to detailed descriptions of each individual item. 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | -------------------------------------------------------------------------------- /xmldoc/ex_calc_rules.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Daylight Savings Calc Rules 12 | 13 | 14 | Example of creating various Daylight Savings Calc Rule objects. 15 | 16 | 17 | 24 | 25 | int 26 | main() 27 | { 28 | using namespace boost; 29 | using namespace local_time; 30 | using namespace gregorian; 31 | 32 | /***** create the necessary date_generator objects *****/ 33 | // starting generators 34 | first_day_of_the_week_in_month fd_start(Sunday, May); 35 | last_day_of_the_week_in_month ld_start(Sunday, May); 36 | nth_day_of_the_week_in_month nkd_start(nth_day_of_the_week_in_month::third, 37 | Sunday, May); 38 | partial_date pd_start(1, May); 39 | // ending generators 40 | first_day_of_the_week_in_month fd_end(Sunday, Oct); 41 | last_day_of_the_week_in_month ld_end(Sunday, Oct); 42 | nth_day_of_the_week_in_month nkd_end(nth_day_of_the_week_in_month::third, 43 | Sunday, Oct); 44 | partial_date pd_end(31, Oct); 45 | 46 | /***** create the various dst_calc_rule objects *****/ 47 | dst_calc_rule_ptr pdr(new partial_date_dst_rule(pd_start, pd_end)); 48 | dst_calc_rule_ptr flr(new first_last_dst_rule(fd_start, ld_end)); 49 | dst_calc_rule_ptr llr(new last_last_dst_rule(ld_start, ld_end)); 50 | dst_calc_rule_ptr nlr(new nth_last_dst_rule(nkd_start, ld_end)); 51 | dst_calc_rule_ptr ndr(new nth_day_of_the_week_in_month_dst_rule(nkd_start, 52 | nkd_end)); 53 | 54 | return 0; 55 | } 56 | 57 | ]]> 58 | 59 |
60 | -------------------------------------------------------------------------------- /xmldoc/ex_date_period_calc.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Date Period Calculations 12 | 13 | 14 | Calculates if a date is in an 'irregular' collection of periods using period calculation functions. 15 | 16 | 17 | 20020216/20020217 35 | 20020223/20020224 36 | 37 | */ 38 | 39 | 40 | #include "boost/date_time/gregorian/gregorian.hpp" 41 | #include 42 | #include 43 | #include 44 | 45 | typedef std::set date_period_set; 46 | 47 | //Simple population of the exclusion set 48 | date_period_set 49 | generateExclusion() 50 | { 51 | using namespace boost::gregorian; 52 | date_period periods_array[] = 53 | { date_period(date(2002,Feb,2), date(2002,Feb,4)),//weekend of 2nd-3rd 54 | date_period(date(2002,Feb,9), date(2002,Feb,11)), 55 | date_period(date(2002,Feb,16), date(2002,Feb,18)), 56 | date_period(date(2002,Feb,23), date(2002,Feb,25)), 57 | date_period(date(2002,Feb,12), date(2002,Feb,13))//a random holiday 2-12 58 | }; 59 | const int num_periods = sizeof(periods_array)/sizeof(date_period); 60 | 61 | date_period_set ps; 62 | //insert the periods in the set 63 | std::insert_iterator itr(ps, ps.begin()); 64 | std::copy(periods_array, periods_array+num_periods, itr ); 65 | return ps; 66 | 67 | } 68 | 69 | 70 | int main() 71 | { 72 | using namespace boost::gregorian; 73 | 74 | date_period_set ps = generateExclusion(); 75 | std::cout << "Number Excluded Periods: " << ps.size() << std::endl; 76 | 77 | date d(2002,Feb,16); 78 | date_period_set::const_iterator i = ps.begin(); 79 | //print the periods, check for containment 80 | for (;i != ps.end(); i++) { 81 | std::cout << to_iso_string(*i) << std::endl; 82 | //if date is in exclusion period then print it 83 | if (i->contains(d)) { 84 | std::cout << "In Exclusion Period: " 85 | << to_iso_string(d) << " --> " << to_iso_string(*i) 86 | << std::endl; 87 | } 88 | } 89 | 90 | return 0; 91 | 92 | } 93 | 94 | ]]> 95 | 96 |
97 | -------------------------------------------------------------------------------- /xmldoc/ex_dates_as_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Dates as Strings 12 | 13 | 14 | Various parsing and output of strings. 15 | 16 | 17 | 32 | #include 33 | 34 | int 35 | main() 36 | { 37 | 38 | using namespace boost::gregorian; 39 | 40 | try { 41 | // The following date is in ISO 8601 extended format (CCYY-MM-DD) 42 | std::string s("2001-10-9"); //2001-October-09 43 | date d(from_simple_string(s)); 44 | std::cout << to_simple_string(d) << std::endl; 45 | 46 | //Read ISO Standard(CCYYMMDD) and output ISO Extended 47 | std::string ud("20011009"); //2001-Oct-09 48 | date d1(from_undelimited_string(ud)); 49 | std::cout << to_iso_extended_string(d1) << std::endl; 50 | 51 | //Output the parts of the date - Tuesday October 9, 2001 52 | date::ymd_type ymd = d1.year_month_day(); 53 | greg_weekday wd = d1.day_of_week(); 54 | std::cout << wd.as_long_string() << " " 55 | << ymd.month.as_long_string() << " " 56 | << ymd.day << ", " << ymd.year 57 | << std::endl; 58 | 59 | //Let's send in month 25 by accident and create an exception 60 | std::string bad_date("20012509"); //2001-??-09 61 | std::cout << "An expected exception is next: " << std::endl; 62 | date wont_construct(from_undelimited_string(bad_date)); 63 | //use wont_construct so compiler doesn't complain, but you wont get here! 64 | std::cout << "oh oh, you shouldn't reach this line: " 65 | << to_iso_string(wont_construct) << std::endl; 66 | } 67 | catch(std::exception& e) { 68 | std::cout << " Exception: " << e.what() << std::endl; 69 | } 70 | 71 | 72 | return 0; 73 | } 74 | 75 | ]]> 76 | 77 |
78 | -------------------------------------------------------------------------------- /xmldoc/ex_days_between_new_years.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Days Between New Years 12 | 13 | 14 | Calculate the number of days till new years 15 | 16 | 17 | 26 | #include "boost/date_time/gregorian/gregorian.hpp" 27 | 28 | int 29 | main() 30 | { 31 | 32 | using namespace boost::gregorian; 33 | 34 | date today = day_clock::local_day(); 35 | partial_date new_years_day(1,Jan); 36 | //Subtract two dates to get a duration 37 | days days_since_year_start = today - new_years_day.get_date(today.year()); 38 | std::cout << "Days since Jan 1: " << days_since_year_start.days() 39 | << std::endl; 40 | 41 | days days_until_year_start = new_years_day.get_date(today.year()+1) - today; 42 | std::cout << "Days until next Jan 1: " << days_until_year_start.days() 43 | << std::endl; 44 | return 0; 45 | }; 46 | 47 | ]]> 48 | 49 |
50 | -------------------------------------------------------------------------------- /xmldoc/ex_end_of_month_day.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | End of the Months 12 | 13 | 14 | Iterates accross the remaining months in a given year, always landing on the last day of the month. 15 | 16 | 17 | 25 | 26 | int 27 | main() 28 | { 29 | using namespace boost::gregorian; 30 | 31 | std::cout << " Enter Year(ex: 2002): "; 32 | int year, month; 33 | std::cin >> year; 34 | std::cout << " Enter Month(1..12): "; 35 | std::cin >> month; 36 | try { 37 | int day = gregorian_calendar::end_of_month_day(year,month); 38 | date end_of_month(year,month,day); 39 | 40 | //Iterate thru by months -- 41 | month_iterator mitr(end_of_month,1); 42 | date start_of_next_year(year+1, Jan, 1); 43 | //loop thru the days and print each one 44 | while (mitr < start_of_next_year){ 45 | std::cout << to_simple_string(*mitr) << std::endl; 46 | ++mitr; 47 | } 48 | 49 | } 50 | catch(...) { 51 | std::cout << "Invalid Date Entered" << std::endl; 52 | } 53 | return 0; 54 | 55 | } 56 | 57 | ]]> 58 | 59 |
60 | -------------------------------------------------------------------------------- /xmldoc/ex_find_last_day_of_months.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Last Day of the Months 12 | 13 | 14 | Example that gets a month and a year from the user and finds the last day of each remaining month of that year. 15 | 16 | 17 | 24 | 25 | int 26 | main() 27 | { 28 | using namespace boost::gregorian; 29 | 30 | greg_year year(1400); 31 | greg_month month(1); 32 | 33 | // get a month and a year from the user 34 | try { 35 | int y, m; 36 | std::cout << " Enter Year(ex: 2002): "; 37 | std::cin >> y; 38 | year = greg_year(y); 39 | std::cout << " Enter Month(1..12): "; 40 | std::cin >> m; 41 | month = greg_month(m); 42 | } 43 | catch(bad_year by) { 44 | std::cout << "Invalid Year Entered: " << by.what() << '\n' 45 | << "Using minimum values for month and year." << std::endl; 46 | } 47 | catch(bad_month bm) { 48 | std::cout << "Invalid Month Entered" << bm.what() << '\n' 49 | << "Using minimum value for month. " << std::endl; 50 | } 51 | 52 | date start_of_next_year(year+1, Jan, 1); 53 | date d(year, month, 1); 54 | 55 | // add another month to d until we enter the next year. 56 | while (d < start_of_next_year){ 57 | std::cout << to_simple_string(d.end_of_month()) << std::endl; 58 | d += months(1); 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | ]]> 65 | 66 |
67 | -------------------------------------------------------------------------------- /xmldoc/ex_month_add.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Month Adding 12 | 13 | 14 | Adding a month to a day without the use of iterators. 15 | 16 | 17 | 26 | 27 | int 28 | main() 29 | { 30 | 31 | using namespace boost::gregorian; 32 | 33 | date d = day_clock::local_day(); 34 | add_month mf(1); 35 | date d2 = d + mf.get_offset(d); 36 | std::cout << "Today is: " << to_simple_string(d) << ".\n" 37 | << "One month from today will be: " << to_simple_string(d2) 38 | << std::endl; 39 | 40 | return 0; 41 | } 42 | ]]> 43 | 44 |
45 | -------------------------------------------------------------------------------- /xmldoc/ex_print_holidays.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Print Holidays 12 | 13 | 14 | This is an example of using functors to define a holiday schedule 15 | 16 | 17 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | void 40 | print_date(boost::gregorian::date d) 41 | { 42 | using namespace boost::gregorian; 43 | #if defined(BOOST_DATE_TIME_NO_LOCALE) 44 | std::cout << to_simple_string(d) << " [" << d.day_of_week() << "]\n"; 45 | #else 46 | std::cout << d << " [" << d.day_of_week() << "]\n"; 47 | #endif 48 | } 49 | 50 | 51 | int 52 | main() { 53 | 54 | std::cout << "Enter Year: "; 55 | int year; 56 | std::cin >> year; 57 | 58 | using namespace boost::gregorian; 59 | 60 | //define a collection of holidays fixed by month and day 61 | std::vector holidays; 62 | holidays.push_back(new partial_date(1,Jan)); //Western New Year 63 | holidays.push_back(new partial_date(4,Jul)); //US Independence Day 64 | holidays.push_back(new partial_date(25, Dec));//Christmas day 65 | 66 | 67 | //define a shorthand for the nth_day_of_the_week_in_month function object 68 | typedef nth_day_of_the_week_in_month nth_dow; 69 | 70 | //US labor day 71 | holidays.push_back(new nth_dow(nth_dow::first, Monday, Sep)); 72 | //MLK Day 73 | holidays.push_back(new nth_dow(nth_dow::third, Monday, Jan)); 74 | //Pres day 75 | holidays.push_back(new nth_dow(nth_dow::second, Tuesday, Feb)); 76 | //Thanksgiving 77 | holidays.push_back(new nth_dow(nth_dow::fourth, Thursday, Nov)); 78 | 79 | typedef std::set date_set; 80 | date_set all_holidays; 81 | 82 | for(std::vector::iterator it = holidays.begin(); 83 | it != holidays.end(); ++it) 84 | { 85 | all_holidays.insert((*it)->get_date(year)); 86 | } 87 | 88 | //print the holidays to the screen 89 | std::for_each(all_holidays.begin(), all_holidays.end(), print_date); 90 | std::cout << "Number Holidays: " << all_holidays.size() << std::endl; 91 | 92 | return 0; 93 | } 94 | 95 | ]]> 96 | 97 |
98 | -------------------------------------------------------------------------------- /xmldoc/ex_print_hours.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Print Hours 12 | 13 | 14 | Demonstrate time iteration, clock retrieval, and simple calculation. 15 | 16 | 17 | 38 | 39 | int 40 | main() 41 | { 42 | using namespace boost::posix_time; 43 | using namespace boost::gregorian; 44 | 45 | //get the current time from the clock -- one second resolution 46 | ptime now = second_clock::local_time(); 47 | //Get the date part out of the time 48 | date today = now.date(); 49 | date tommorrow = today + days(1); 50 | ptime tommorrow_start(tommorrow); //midnight 51 | 52 | //iterator adds by one hour 53 | time_iterator titr(now,hours(1)); 54 | for (; titr < tommorrow_start; ++titr) { 55 | std::cout << to_simple_string(*titr) << std::endl; 56 | } 57 | 58 | time_duration remaining = tommorrow_start - now; 59 | std::cout << "Time left till midnight: " 60 | << to_simple_string(remaining) << std::endl; 61 | return 0; 62 | } 63 | 64 | ]]> 65 | 66 |
67 | -------------------------------------------------------------------------------- /xmldoc/ex_print_month.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Print Month 12 | 13 | 14 | Simple utility to print out days of the month with the days of a month. Demontstrates date iteration (date_time::date_itr). 15 | 16 | 17 | 35 | 36 | int 37 | main() 38 | { 39 | std::cout << "Enter Year: "; 40 | int year, month; 41 | std::cin >> year; 42 | std::cout << "Enter Month(1..12): "; 43 | std::cin >> month; 44 | 45 | using namespace boost::gregorian; 46 | try { 47 | //Use the calendar to get the last day of the month 48 | int eom_day = gregorian_calendar::end_of_month_day(year,month); 49 | date endOfMonth(year,month,eom_day); 50 | 51 | //construct an iterator starting with firt day of the month 52 | day_iterator ditr(date(year,month,1)); 53 | //loop thru the days and print each one 54 | for (; ditr <= endOfMonth; ++ditr) { 55 | #if defined(BOOST_DATE_TIME_NO_LOCALE) 56 | std::cout << to_simple_string(*ditr) << " [" 57 | #else 58 | std::cout << *ditr << " [" 59 | #endif 60 | << ditr->day_of_week() << "]" 61 | << std::endl; 62 | } 63 | } 64 | catch(std::exception& e) { 65 | 66 | std::cout << "Error bad date, check your entry: \n" 67 | << " Details: " << e.what() << std::endl; 68 | } 69 | return 0; 70 | } 71 | 72 | ]]> 73 | 74 |
75 | -------------------------------------------------------------------------------- /xmldoc/ex_seconds_since_epoch.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Seconds Since Epoch 12 | 13 | 14 | Example of calculating seconds elapsed since epoch (1970-Jan-1) using local_date_time. 15 | 16 | 17 | 34 | 35 | int main() 36 | { 37 | using namespace boost::gregorian; 38 | using namespace boost::local_time; 39 | using namespace boost::posix_time; 40 | 41 | tz_database tz_db; 42 | try { 43 | tz_db.load_from_file("../data/date_time_zonespec.csv"); 44 | }catch(data_not_accessible dna) { 45 | std::cerr << "Error with time zone data file: " << dna.what() << std::endl; 46 | exit(EXIT_FAILURE); 47 | }catch(bad_field_count bfc) { 48 | std::cerr << "Error with time zone data file: " << bfc.what() << std::endl; 49 | exit(EXIT_FAILURE); 50 | } 51 | 52 | time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York"); 53 | date in_date(2004,10,04); 54 | time_duration td(12,14,32); 55 | // construct with local time value 56 | // create not-a-date-time if invalid (eg: in dst transition) 57 | local_date_time nyc_time(in_date, 58 | td, 59 | nyc_tz, 60 | local_date_time::NOT_DATE_TIME_ON_ERROR); 61 | 62 | std::cout << nyc_time << std::endl; 63 | 64 | ptime time_t_epoch(date(1970,1,1)); 65 | std::cout << time_t_epoch << std::endl; 66 | 67 | // first convert nyc_time to utc via the utc_time() 68 | // call and subtract the ptime. 69 | time_duration diff = nyc_time.utc_time() - time_t_epoch; 70 | 71 | //Expected 1096906472 72 | std::cout << "Seconds diff: " << diff.total_seconds() << std::endl; 73 | 74 | } 75 | ]]> 76 | 77 |
78 | -------------------------------------------------------------------------------- /xmldoc/ex_time_math.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Time Math 12 | 13 | 14 | Various types of calculations with times and time durations. 15 | 16 | 17 | 25 | 26 | int 27 | main() 28 | { 29 | using namespace boost::posix_time; 30 | using namespace boost::gregorian; 31 | 32 | date d(2002,Feb,1); //an arbitrary date 33 | //construct a time by adding up some durations durations 34 | ptime t1(d, hours(5)+minutes(4)+seconds(2)+millisec(1)); 35 | //construct a new time by subtracting some times 36 | ptime t2 = t1 - hours(5)- minutes(4)- seconds(2)- millisec(1); 37 | //construct a duration by taking the difference between times 38 | time_duration td = t2 - t1; 39 | 40 | std::cout << to_simple_string(t2) << " - " 41 | << to_simple_string(t1) << " = " 42 | << to_simple_string(td) << std::endl; 43 | 44 | return 0; 45 | } 46 | ]]> 47 | 48 |
49 | -------------------------------------------------------------------------------- /xmldoc/ex_time_periods.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Time Periods 12 | 13 | 14 | Demonstrate some simple uses of time periods. 15 | 16 | 17 | 32 | 33 | using namespace boost::posix_time; 34 | using namespace boost::gregorian; 35 | 36 | //Create a simple period class to contain all the times in a day 37 | class day_period : public time_period 38 | { 39 | public: 40 | day_period(date d) : time_period(ptime(d),//midnight 41 | ptime(d,hours(24))) 42 | {} 43 | 44 | }; 45 | 46 | int 47 | main() 48 | { 49 | 50 | date d(2002,Feb,1); //an arbitrary date 51 | //a period that represents a day 52 | day_period dp(d); 53 | ptime t(d, hours(3)+seconds(5)); //an arbitray time on that day 54 | if (dp.contains(t)) { 55 | std::cout << to_simple_string(dp) << " contains " 56 | << to_simple_string(t) << std::endl; 57 | } 58 | //a period that represents part of the day 59 | time_period part_of_day(ptime(d, hours(0)), t); 60 | //intersect the 2 periods and print the results 61 | if (part_of_day.intersects(dp)) { 62 | time_period result = part_of_day.intersection(dp); 63 | std::cout << to_simple_string(dp) << " intersected with\n" 64 | << to_simple_string(part_of_day) << " is \n" 65 | << to_simple_string(result) << std::endl; 66 | } 67 | 68 | 69 | return 0; 70 | } 71 | 72 | ]]> 73 | 74 |
75 | -------------------------------------------------------------------------------- /xmldoc/examples.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Examples 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
35 | -------------------------------------------------------------------------------- /xmldoc/exclusive_date_time.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 11 | 13 | The Boost Date Time Library 14 | 15 | 16 | -------------------------------------------------------------------------------- /xmldoc/license.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 |
9 | Boost Date-Time Library License 10 | Boost Date-Time Library License 11 | 18 | 19 | 20 | The following is the overall license for the boost date_time 21 | library. This notice is found in all source files related to the 22 | library. 23 | 24 | 25 | Copyright © 2002 CrystalClear Software, Inc. 26 | 27 | 28 | Permission to use, copy, modify, distribute and sell this software 29 | and its documentation for any purpose is hereby granted without 30 | fee, provided that the above copyright notice appear in all copies 31 | and that both that copyright notice and this permission notice 32 | appear in supporting documentation. CrystalClear Software makes no 33 | representations about the suitability of this software for any 34 | purpose. It is provided "as is" without express or implied 35 | warranty. 36 | 37 | 38 | Jeff Garland 39 | © 2000-2002 40 |
41 | -------------------------------------------------------------------------------- /xmldoc/motivation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 |
9 | Motivation 10 | 11 | 12 | The motivation for this library comes from working with and helping build several date-time libraries on several projects. Date-time libraries provide fundamental infrastructure for most development projects. However, most of them have limitations in their ability to calculate, format, convert, or perform some other functionality. For example, most libraries do not correctly handle leap seconds, provide concepts such as infinity, or provide the ability to use high resolution or network time sources. These libraries also tend to be rigid in their representation of dates and times. Thus customized policies for a project or subproject are not possible. 13 | 14 | 15 | Programming with dates and times should be almost as simple and natural as programming with strings and integers. Applications with lots of temporal logic can be radically simplified by having a robust set of operators and calculation capabilities. Classes should provide the ability to compare dates and times, add lengths or time durations, retrieve dates and times from clocks, and work naturally with date and time intervals. 16 | 17 | 18 | Another motivation for development of the library was to apply modern C++ library design techniques to the date-time domain. Really to build a framework for the construction of building temporal types. For example, by providing iterators and traits classes to control fundamental properties of the library. To the authors knowledge this library is the only substantial attempt to apply modern C++ to a date-time library. 19 | 20 |
21 | -------------------------------------------------------------------------------- /xmldoc/posix_time.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
12 | Posix Time 13 | Posix Time System 14 | 15 | Introduction -- 16 | Usage Examples 17 | 18 | 19 | 20 | Introduction 21 | 22 | Defines a non-adjusted time system with nano-second/micro-second resolution and stable calculation properties. The nano-second resolution option uses 96 bits of underlying storage for each ptime while the micro-second resolution uses 64 bits per ptime (see Build Options for details). This time system uses the Gregorian calendar to implement the date portion of the time representation. 23 | 24 | 25 | 26 | Usage Examples 27 | 28 | 29 | 30 | 31 | 32 | Example 33 | Description 34 | 35 | 36 | 37 | 38 | Time Math 39 | A few simple calculations using ptime and time_durations. 40 | 41 | 42 | Print Hours 43 | Retrieve time from clock, use a time_iterator. 44 | 45 | 46 | Local to UTC Conversion 47 | Demonstrates a couple different ways to convert a local to UTC time including daylight savings rules. 48 | 49 | 50 | Time Periods 51 | Some simple examples of intersection and display of time periods. 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 |
65 | 66 | -------------------------------------------------------------------------------- /xmldoc/table_template.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Syntax 14 | Description 15 | 16 | 17 | Example 18 | 19 | 20 | 21 | 22 | time_zone_ptr zone() 23 | Returns associated time_zone object via a time_zone_ptr 24 | 25 | 26 | the example... 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /xmldoc/tests.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 |
11 | Tests 12 | 13 | 14 | The library provides a large number of tests in the 15 | 16 | libs/date_time/test 17 | libs/date_time/test/gregorian 18 | libs/date_time/test/posix_time 19 | libs/date_time/test/local_time 20 | 21 | directories. Building and executing these tests assures that the installation is correct and that the library is functioning correctly. In addition, these tests facilitate the porting to new compilers. Finally, the tests provide examples of many functions not explicitly described in the usage examples. 22 | 23 |
24 | --------------------------------------------------------------------------------