diff --git a/build/Jamfile b/build/Jamfile index c0cf2d1..d718691 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -4,115 +4,113 @@ # warranty, and with no claim as to its suitability for any purpose. # # -# Boost.gdtl build and test Jamfile +# Boost.date_time build and test Jamfile # # Based on boost.python Jamfile # # To run all tests quietly: jam test # # Declares the following targets: -# 1. libboost_gdtl, a static link library to be linked with all -# Boost.gdtl modules +# 1. libboost_date_time, a static link library to be linked with all +# Boost.date_time modules # # declare the location of this subproject relative to the root -subproject libs/gdtl/build ; +subproject libs/date_time/build ; -local GDTL_PROPERTIES = $(GDTL_PROPERTIES) GDTL_INLINE BOOST_GDTL_POSIX_TIME_STD_CONFIG ; +#local DATE_TIME_PROPERTIES = $(DATE_TIME_PROPERTIES) DATE_TIME_INLINE BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG ; +local DATE_TIME_PROPERTIES = $(DATE_TIME_PROPERTIES) DATE_TIME_INLINE ; -# ../../../boost obviates need to change #includes -# ../../.. is there because gdtl is not under BOOST_ROOT - -local GDTL_INCLUDES = $(BOOST_ROOT) +local DATE_TIME_INCLUDES = $(BOOST_ROOT) ../../.. ../../../boost ; ####################### -rule gdtl-test ( test-name : sources + ) +rule date_time-test ( test-name : sources + ) { - unit-test $(test-name) : $(sources) libboost_gdtl - : $(GDTL_INCLUDES) $(GDTL_PROPERTIES) ; + unit-test $(test-name) : $(sources) libboost_date_time + : $(DATE_TIME_INCLUDES) $(DATE_TIME_PROPERTIES) ; } -rule gdtl-example ( example-name : sources + ) +rule date_time-example ( example-name : sources + ) { - exe $(example-name) : $(sources) libboost_gdtl - : $(GDTL_INCLUDES) $(GDTL_PROPERTIES) ; + exe $(example-name) : $(sources) libboost_date_time + : $(DATE_TIME_INCLUDES) $(DATE_TIME_PROPERTIES) ; } ####################### # -# Declare the boost gdtl static link library +# Declare the boost date_time static link library # -# Base names of the source files for libboost_gdtl +# Base names of the source files for libboost_date_time local GREGORIAN_CPP_SOURCES = gregorian_types greg_month greg_weekday ; -lib libboost_gdtl : ../src/gregorian/$(GREGORIAN_CPP_SOURCES).cpp +lib libboost_date_time : ../src/gregorian/$(GREGORIAN_CPP_SOURCES).cpp # requirements - : $(GDTL_INCLUDES) - $(GDTL_PROPERTIES) ; + : $(DATE_TIME_INCLUDES) + $(DATE_TIME_PROPERTIES) ; #dll libboost_gdtl # # $(SUFDLL[1]) # : ../gregorian/src/$(GREGORIAN_CPP_SOURCES).cpp # # requirements -# : $(GDTL_INCLUDES) +# : $(DATE_TIME_INCLUDES) # true # dynamic -# $(GDTL_PROPERTIES) +# $(DATE_TIME_PROPERTIES) # ; ############# tests ########### # Generic tests -gdtl-test testconstrained_value : ../test/testconstrained_value.cpp ; -gdtl-test testint_adapter : ../test/testint_adapter.cpp ; -gdtl-test testwrapping_int : ../test/testwrapping_int.cpp ; -gdtl-test testtime_resolution_traits : ../test/testtime_resolution_traits.cpp ; -gdtl-test testgregorian_calendar : ../test/testgregorian_calendar.cpp ; -gdtl-test testint64_range : ../test/testint64_range.cpp ; +date_time-test testconstrained_value : ../test/testconstrained_value.cpp ; +date_time-test testint_adapter : ../test/testint_adapter.cpp ; +date_time-test testwrapping_int : ../test/testwrapping_int.cpp ; +date_time-test testtime_resolution_traits : ../test/testtime_resolution_traits.cpp ; +date_time-test testgregorian_calendar : ../test/testgregorian_calendar.cpp ; +date_time-test testint64_range : ../test/testint64_range.cpp ; # Gregorian Date System -gdtl-test testdate_iterator : ../test/gregorian/testdate_iterator.cpp ; -gdtl-test testgreg_month : ../test/gregorian/testgreg_month.cpp ; -gdtl-test testcurrent_day : ../test/gregorian/testcurrent_day.cpp ; -gdtl-test testformatters : ../test/gregorian/testformatters.cpp ; -gdtl-test testparse_date : ../test/gregorian/testparse_date.cpp ; -gdtl-test testdate : ../test/gregorian/testdate.cpp ; -gdtl-test testgreg_cal : ../test/gregorian/testgreg_cal.cpp ; -gdtl-test testgenerators : ../test/gregorian/testgenerators.cpp ; -gdtl-test testdate_duration : ../test/gregorian/testdate_duration.cpp ; -gdtl-test testgreg_day : ../test/gregorian/testgreg_day.cpp ; -gdtl-test testperiod : ../test/gregorian/testperiod.cpp ; -gdtl-test testfacet : ../test/gregorian/testfacet.cpp ; +date_time-test testdate_iterator : ../test/gregorian/testdate_iterator.cpp ; +date_time-test testgreg_month : ../test/gregorian/testgreg_month.cpp ; +date_time-test testcurrent_day : ../test/gregorian/testcurrent_day.cpp ; +date_time-test testformatters : ../test/gregorian/testformatters.cpp ; +date_time-test testparse_date : ../test/gregorian/testparse_date.cpp ; +date_time-test testdate : ../test/gregorian/testdate.cpp ; +date_time-test testgreg_cal : ../test/gregorian/testgreg_cal.cpp ; +date_time-test testgenerators : ../test/gregorian/testgenerators.cpp ; +date_time-test testdate_duration : ../test/gregorian/testdate_duration.cpp ; +date_time-test testgreg_day : ../test/gregorian/testgreg_day.cpp ; +date_time-test testperiod : ../test/gregorian/testperiod.cpp ; +date_time-test testfacet : ../test/gregorian/testfacet.cpp ; # Posix Time System Tests -gdtl-test testtimeperiod : ../test/posix_time/testperiod.cpp ; -gdtl-test testtime : ../test/posix_time/testtime.cpp ; -gdtl-test testtimeduration : ../test/posix_time/testduration.cpp ; -gdtl-test testtimeformat : ../test/posix_time/testformatters.cpp ; -gdtl-test testlocal_adjustor : ../test/posix_time/testlocal_adjustor.cpp ; -gdtl-test testdst_rules : ../test/posix_time/testdst_rules.cpp ; -gdtl-test testiterator : ../test/posix_time/testiterator.cpp ; -gdtl-test testparse_time : ../test/posix_time/testparse_time.cpp ; +date_time-test testtimeperiod : ../test/posix_time/testperiod.cpp ; +date_time-test testtime : ../test/posix_time/testtime.cpp ; +date_time-test testtimeduration : ../test/posix_time/testduration.cpp ; +date_time-test testtimeformat : ../test/posix_time/testformatters.cpp ; +date_time-test testlocal_adjustor : ../test/posix_time/testlocal_adjustor.cpp ; +date_time-test testdst_rules : ../test/posix_time/testdst_rules.cpp ; +date_time-test testiterator : ../test/posix_time/testiterator.cpp ; +date_time-test testparse_time : ../test/posix_time/testparse_time.cpp ; ############# examples ############ -gdtl-example dates_as_strings : ../example/gregorian/dates_as_strings.cpp ; -gdtl-example end_of_month_day : ../example/gregorian/end_of_month_day.cpp ; -gdtl-example dates_as_strings : ../example/gregorian/dates_as_strings.cpp ; -gdtl-example period_calc : ../example/gregorian/period_calc.cpp ; -gdtl-example days_alive : ../example/gregorian/days_alive.cpp ; -gdtl-example print_holidays : ../example/gregorian/print_holidays.cpp ; -gdtl-example days_since_year_start : ../example/gregorian/days_since_year_start.cpp ; -gdtl-example print_month : ../example/gregorian/print_month.cpp ; -gdtl-example days_till_new_year : ../example/gregorian/days_till_new_year.cpp ; +date_time-example dates_as_strings : ../example/gregorian/dates_as_strings.cpp ; +date_time-example end_of_month_day : ../example/gregorian/end_of_month_day.cpp ; +date_time-example dates_as_strings : ../example/gregorian/dates_as_strings.cpp ; +date_time-example period_calc : ../example/gregorian/period_calc.cpp ; +date_time-example days_alive : ../example/gregorian/days_alive.cpp ; +date_time-example print_holidays : ../example/gregorian/print_holidays.cpp ; +date_time-example days_since_year_start : ../example/gregorian/days_since_year_start.cpp ; +date_time-example print_month : ../example/gregorian/print_month.cpp ; +date_time-example days_till_new_year : ../example/gregorian/days_till_new_year.cpp ; #time examples -gdtl-example time_math : ../example/posix_time/time_math.cpp ; -gdtl-example local_utc_conversion : ../example/posix_time/local_utc_conversion.cpp ; -gdtl-example print_hours : ../example/posix_time/print_hours.cpp ; -gdtl-example time_periods : ../example/posix_time/time_periods.cpp ; +date_time-example time_math : ../example/posix_time/time_math.cpp ; +date_time-example local_utc_conversion : ../example/posix_time/local_utc_conversion.cpp ; +date_time-example print_hours : ../example/posix_time/print_hours.cpp ; +date_time-example time_periods : ../example/posix_time/time_periods.cpp ; diff --git a/doc/index.html b/doc/index.html index c004793..bf90362 100644 --- a/doc/index.html +++ b/doc/index.html @@ -10,7 +10,7 @@ C++ Boost -

Generic Date-Time Library (GDTL) Documentation

+

Boost Date-Time Library Documentation

Version 1.00


@@ -51,7 +51,7 @@

Introduction

-GDTL is a set of date-time libraries based on generic programming concepts. +A set of date-time libraries based on generic programming concepts.

Motivation

@@ -104,10 +104,10 @@ And some time code using the posix_time system. See Ti

Domain Concepts

-The date time domain is rich in terminology and problems. The following is a brief introduction to the concepts you will find reflected in GDTL library. +The date time domain is rich in terminology and problems. The following is a brief introduction to the concepts you will find reflected in the library.

-GDTL supports 3 basic temporal types: +The library supports 3 basic temporal types:

  • Time Point -- Specifier for a location in the time continuum.
  • Time Duration -- A length of time unattached to any point on the time continuum. @@ -120,7 +120,7 @@ Each of these temporal types has a Resolution which is A Clock Device is software component (tied to some hardware) that provides the current date or time with respect to a time system.

    -GDTL provides support for calculating with dates and times. However, time calculations are not quite the same as calculating with integers. If you are serious about the accuracy of your time calculations need to read about Stability, Predictablity, and Aproximations. +The library provides support for calculating with dates and times. However, time calculations are not quite the same as calculating with integers. If you are serious about the accuracy of your time calculations need to read about Stability, Predictablity, and Aproximations.

    Additional reference materials can be found in the following: @@ -139,7 +139,7 @@ Please see the Wiki pages for the most recent information:

      Tests

      -GDTL provides a large number of tests in the +The library provides a large number of tests in the

          libs/gdtl/test 
          libs/gdtl/test/gregorian
      @@ -166,7 +166,7 @@ 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.
       

      -While the GDTL design is far from perfect the current design is far +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 @@ -176,7 +176,7 @@ of the library are summarized here.

      More Info

      -The design of GDTL is currently being evolved using Wiki and email discussions. You can find more information at: +The design of the library is currently being evolved using Wiki and email discussions. You can find more information at:

      • Boost Wiki GDTL Start Page @@ -185,7 +185,7 @@ The design of GDTL is currently being evolved using Wiki and email discussions.
        -Last modified: Tue Aug 13 15:15:50 MST 2002 +Last modified: Thu Aug 15 11:49:01 MST 2002 by Jeff Garland © 2000-2002
        diff --git a/example/gregorian/dates_as_strings.cpp b/example/gregorian/dates_as_strings.cpp index d68a1c5..5f83532 100644 --- a/example/gregorian/dates_as_strings.cpp +++ b/example/gregorian/dates_as_strings.cpp @@ -11,8 +11,8 @@ An expected exception is next: */ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/date_parsing.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/date_parsing.hpp" #include #include diff --git a/example/gregorian/days_alive.cpp b/example/gregorian/days_alive.cpp index 2a3cd0e..e16b175 100644 --- a/example/gregorian/days_alive.cpp +++ b/example/gregorian/days_alive.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/date_parsing.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/date_parsing.hpp" #include int @@ -12,7 +12,7 @@ main() std::cout << "Enter birth day YYYY-MM-DD (eg: 2002-02-01): "; std::cin >> s; try { - date birthday(boost::gdtl::parse_date(s)); + date birthday(boost::date_time::parse_date(s)); //date birthday(2002,Jan,1); date today = day_clock::local_day(); date_duration days_alive = today - birthday; diff --git a/example/gregorian/days_since_year_start.cpp b/example/gregorian/days_since_year_start.cpp index cb5c4a5..f8a881f 100644 --- a/example/gregorian/days_since_year_start.cpp +++ b/example/gregorian/days_since_year_start.cpp @@ -1,6 +1,6 @@ #include -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" int main() diff --git a/example/gregorian/days_till_new_year.cpp b/example/gregorian/days_till_new_year.cpp index f9d8b74..e4ab95e 100644 --- a/example/gregorian/days_till_new_year.cpp +++ b/example/gregorian/days_till_new_year.cpp @@ -1,6 +1,6 @@ // This example displays the amount of time until new year's in days -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include int diff --git a/example/gregorian/end_of_month_day.cpp b/example/gregorian/end_of_month_day.cpp index f9f394e..d78ec21 100644 --- a/example/gregorian/end_of_month_day.cpp +++ b/example/gregorian/end_of_month_day.cpp @@ -1,7 +1,7 @@ // Simple program that uses the gregorian calendar to find the last // day of the month. -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include diff --git a/example/gregorian/month_add.cpp b/example/gregorian/month_add.cpp index 66729cb..5d62a35 100644 --- a/example/gregorian/month_add.cpp +++ b/example/gregorian/month_add.cpp @@ -3,7 +3,7 @@ // Simple program that uses the gregorian calendar to find the last // day of the month. -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include @@ -12,7 +12,7 @@ main() { using namespace boost::gregorian; - typedef boost::gdtl::month_functor add_month; + typedef boost::date_time::month_functor add_month; date d = day_clock::local_day(); add_month mf(1); diff --git a/example/gregorian/period_calc.cpp b/example/gregorian/period_calc.cpp index 583ca02..036e4c5 100644 --- a/example/gregorian/period_calc.cpp +++ b/example/gregorian/period_calc.cpp @@ -20,7 +20,7 @@ In Exclusion Period: 20020216 --> 20020216/20020217 */ -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include #include #include diff --git a/example/gregorian/print_holidays.cpp b/example/gregorian/print_holidays.cpp index a69bf87..39f0429 100644 --- a/example/gregorian/print_holidays.cpp +++ b/example/gregorian/print_holidays.cpp @@ -12,7 +12,7 @@ Number Holidays: 7 */ -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include #include #include @@ -55,7 +55,7 @@ main() { //define a shorthand for the nkday function object - typedef boost::gdtl::nth_kday_of_month nkday; + typedef boost::date_time::nth_kday_of_month nkday; //define a collection of nth kday holidays std::vector more_holidays; more_holidays.push_back(nkday(nkday::first, Monday, Sep)); //US labor day diff --git a/example/gregorian/print_month.cpp b/example/gregorian/print_month.cpp index f007f55..e028db0 100644 --- a/example/gregorian/print_month.cpp +++ b/example/gregorian/print_month.cpp @@ -14,7 +14,7 @@ Enter Month(1..12): 2 2002-Feb-07 [Thu] */ -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include int diff --git a/example/posix_time/local_utc_conversion.cpp b/example/posix_time/local_utc_conversion.cpp index 59789a7..dda1c35 100644 --- a/example/posix_time/local_utc_conversion.cpp +++ b/example/posix_time/local_utc_conversion.cpp @@ -16,9 +16,9 @@ UTC <--> Arizona (7 hours) -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/local_time_adjustor.hpp" -#include "boost/gdtl/c_local_time_adjustor.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/local_time_adjustor.hpp" +#include "boost/date_time/c_local_time_adjustor.hpp" #include int @@ -28,7 +28,7 @@ main() using namespace boost::gregorian; //This local adjustor depends on the machine TZ settings-- highly dangerous! - typedef boost::gdtl::c_local_adjustor local_adj; + typedef boost::date_time::c_local_adjustor local_adj; ptime t10(date(2002,Jan,1), hours(7)); ptime t11 = local_adj::utc_to_local(t10); std::cout << "UTC <--> Zone base on TZ setting" << std::endl; @@ -41,7 +41,7 @@ main() //eastern timezone is utc-5 - typedef boost::gdtl::local_adjustor us_eastern; + typedef boost::date_time::local_adjustor us_eastern; ptime t1(date(2001,Dec,31), hours(19)); //5 hours b/f midnight NY time @@ -71,7 +71,7 @@ main() //Arizona timezone is utc-7 with no dst - typedef boost::gdtl::local_adjustor us_arizona; + typedef boost::date_time::local_adjustor us_arizona; ptime t7(date(2002,May,31), hours(17)); std::cout << "UTC <--> Arizona (7 hours)" << std::endl; diff --git a/example/posix_time/print_hours.cpp b/example/posix_time/print_hours.cpp index efea612..6d8cffe 100644 --- a/example/posix_time/print_hours.cpp +++ b/example/posix_time/print_hours.cpp @@ -17,7 +17,7 @@ Time left till midnight: 07:29:01 */ -#include "boost/gdtl/posix_time/posix_time.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" #include diff --git a/example/posix_time/time_math.cpp b/example/posix_time/time_math.cpp index bdf21dc..90a59a6 100644 --- a/example/posix_time/time_math.cpp +++ b/example/posix_time/time_math.cpp @@ -2,7 +2,7 @@ //Output: //2002-Feb-01 00:00:00 - 2002-Feb-01 05:04:02.001000000 = -5:04:02.001000000 -#include "boost/gdtl/posix_time/posix_time.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" #include int diff --git a/example/posix_time/time_periods.cpp b/example/posix_time/time_periods.cpp index 8a0186a..33bbfe4 100644 --- a/example/posix_time/time_periods.cpp +++ b/example/posix_time/time_periods.cpp @@ -6,7 +6,7 @@ //[2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999] -#include "boost/gdtl/posix_time/posix_time.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" #include using namespace boost::posix_time; diff --git a/include/boost/date_time/adjust_functors.hpp b/include/boost/date_time/adjust_functors.hpp new file mode 100644 index 0000000..60b43b7 --- /dev/null +++ b/include/boost/date_time/adjust_functors.hpp @@ -0,0 +1,135 @@ +#ifndef _DATE_TIME_ADJUST_FUNCTORS_HPP___ +#define _DATE_TIME_ADJUST_FUNCTORS_HPP___ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/date.hpp" +#include "boost/date_time/wrapping_int.hpp" + +namespace boost { +namespace date_time { + + + //! Functor to iterate a fixed number of days + template + class day_functor + { + public: + typedef typename date_type::duration_type duration_type; + day_functor(int f) : f_(f) {} + duration_type get_offset(const date_type& d) const + { + return duration_type(f_); + } + private: + int f_; + }; + + + //! Provides calculation to find next nth month given a date + /*! This adjustment function provides the logic for 'month-based' + * advancement on a ymd based calendar. The policy it uses + * to handle the non existant end of month days is to back + * up to the last day of the month. Also, if the starting + * date is the last day of a month, this functor will attempt + * to adjust to the end of the month. + + */ + template + class month_functor + { + public: + typedef typename date_type::duration_type duration_type; + typedef typename date_type::calendar_type cal_type; + typedef typename cal_type::ymd_type ymd_type; + typedef typename cal_type::day_type day_type; + + month_functor(int f) : f_(f), origDayOfMonth_(0) {} + duration_type get_offset(const date_type& d) const + { + ymd_type ymd(d.year_month_day()); + if (origDayOfMonth_ == 0) { + origDayOfMonth_ = ymd.day; + day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); + if (endOfMonthDay == ymd.day) { + origDayOfMonth_ = -1; //force the value to the end of month + } + } + date_time::wrapping_int2 wi(ymd.month); + unsigned long year = wi.add(f_); //calc the year wrap around + year += ymd.year; //now add in the current year +// std::cout << "trace wi: " << wi.as_int() << std::endl; +// std::cout << "trace year: " << year << std::endl; + //find the last day for the new month + day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); + //original was the end of month -- force to last day of month + if (origDayOfMonth_ == -1) { + return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; + } + day_type dayOfMonth = origDayOfMonth_; + if (dayOfMonth > resultingEndOfMonthDay) { + dayOfMonth = resultingEndOfMonthDay; + } + return date_type(year, wi.as_int(), dayOfMonth) - d; + } + private: + int f_; + mutable short origDayOfMonth_; + }; + + + //! Functor to iterate a over weeks + template + class week_functor + { + public: + typedef typename date_type::duration_type duration_type; + typedef typename date_type::calendar_type calendar_type; + week_functor(int f) : f_(f) {} + duration_type get_offset(const date_type& d) const + { + return duration_type(f_*calendar_type::days_in_week()); + } + private: + int f_; + }; + + //! Functor to iterate by a year adjusting for leap years + /*! + *@throws bad_day if date value is invalid (eg: feb 29) + */ + template + class year_functor + { + public: + typedef typename date_type::year_type year_type; + typedef typename date_type::duration_type duration_type; + year_functor(int f) : f_(f) {} + duration_type get_offset(const date_type& d) const + { + date_type new_date(d.year()+f_, d.month(), d.day()); + return new_date-d; + } + private: + int f_; + }; + + + +} }//namespace date_time + +/* Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/c_local_time_adjustor.hpp b/include/boost/date_time/c_local_time_adjustor.hpp new file mode 100644 index 0000000..c6c9aba --- /dev/null +++ b/include/boost/date_time/c_local_time_adjustor.hpp @@ -0,0 +1,72 @@ + +#ifndef DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__ +#define DATE_TIME_C_LOCAL_TIME_ADJUSTOR_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! @file c_local_time_adjustor.hpp + Time adjustment calculations based on machine +*/ + +#include +#include "boost/date_time/c_time.hpp" + +namespace boost { +namespace date_time { + + //! Adjust to / from utc using the C API + /*! Warning!!! This class assumes that timezone settings of the + * machine are correct. This can be a very dangerous assumption. + */ + template + class c_local_adjustor + { + public: + typedef typename time_type::time_duration_type time_duration_type; + typedef typename time_type::date_type date_type; + typedef typename date_type::duration_type date_duration_type; + //! Convert a utc time to local time + static time_type utc_to_local(const time_type& t) + { + date_type time_t_start_day(1970,1,1); + time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0)); + if (t < time_t_start_time) { + throw std::out_of_range("Cannot convert dates prior to Jan 1, 1970"); + } + date_duration_type dd = t.date() - time_t_start_day; + time_duration_type td = t.time_of_day(); + std::time_t t2 = dd.days()*86400 + td.hours()*3600 + td.minutes()*60 + td.seconds(); + std::tm* tms = std::localtime(&t2); + date_type d(tms->tm_year + 1900, + tms->tm_mon + 1, + tms->tm_mday); + time_duration_type td2(tms->tm_hour, + tms->tm_min, + tms->tm_sec, + t.time_of_day().fractional_seconds()); + + return time_type(d,td2); + } + }; + + + +} } //namespace date_time + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif diff --git a/include/boost/date_time/c_time.hpp b/include/boost/date_time/c_time.hpp new file mode 100644 index 0000000..9504ffe --- /dev/null +++ b/include/boost/date_time/c_time.hpp @@ -0,0 +1,35 @@ + +#ifndef DATE_TIME_C_TIME_HPP___ +#define DATE_TIME_C_TIME_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! @file c_time.hpp + Provide workarounds related to the ctime header +*/ + + +#include +//Work around libraries that don't put time_t and time in namespace std +#include "boost/config.hpp" +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std { using ::time_t; using ::time; using ::localtime; + using ::tm; using ::gmtime; } +#endif + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/constrained_value.hpp b/include/boost/date_time/constrained_value.hpp new file mode 100644 index 0000000..454a054 --- /dev/null +++ b/include/boost/date_time/constrained_value.hpp @@ -0,0 +1,104 @@ + +#ifndef CONSTRAINED_VALUE_HPP___ +#define CONSTRAINED_VALUE_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +namespace boost { + +//! Namespace containing constrained_value template and types +namespace CV { + //! Represent a min or max violation type + enum violation_enum {min_violation, max_violation}; + + //! A template to specify a constrained basic value type + /*! This template provides a quick way to generate + * an integer type with a constrained range. The type + * provides for the ability to specify the min, max, and + * and error handling policy. + * + * value policies + * A class that provides the range limits via the min and + * max functions as well as a function on_error that + * determines how errors are handled. A common strategy + * would be to assert or throw and exception. The on_error + * is passed both the current value and the new value that + * is in error. + * + */ + template + class constrained_value { + public: + typedef typename value_policies::value_type value_type; + // typedef except_type exception_type; + constrained_value(value_type value) + { + assign(value); + }; + constrained_value& operator=(value_type v) + { + assign(v); + return *this; + } + //! Return the max allowed value (traits method) + static value_type max() {return value_policies::max();}; + //! Return the min allowed value (traits method) + static value_type min() {return value_policies::min();}; + //! Coerce into the representation type + operator value_type() const {return value_;}; + protected: + value_type value_; + private: + void assign(value_type value) + { + //adding 1 below gets rid of a compiler warning which occurs when the + //min_value is 0 and the type is unsigned.... + if (value+1 < min()+1) { + value_policies::on_error(value_, value, min_violation); + return; + } + if (value > max()) { + value_policies::on_error(value_, value, max_violation); + return; + } + value_ = value; + + } + +}; + + //! Template to shortcut the constrained_value policy creation process + template + class simple_exception_policy + { + public: + typedef rep_type value_type; + static rep_type min() { return min_value; }; + static rep_type max() { return max_value;}; + static void on_error(rep_type, rep_type, violation_enum) + { + throw exception_type(); + } + }; + + + +} } //namespace CV + + +/* Copyright (c) 2000-2002 + * CrystalClear Software, Inc. + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/date.hpp b/include/boost/date_time/date.hpp new file mode 100644 index 0000000..6366f01 --- /dev/null +++ b/include/boost/date_time/date.hpp @@ -0,0 +1,178 @@ +#ifndef DATE_TIME_DATE_HPP___ +#define DATE_TIME_DATE_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/year_month_day.hpp" +#include "boost/date_time/special_defs.hpp" +#include "boost/operators.hpp" + +namespace boost { +namespace date_time { + + //!Representation of timepoint at the one day level resolution. + /*! + The date template represents an interface shell for a date class + that is based on a year-month-day system such as the gregorian + or iso systems. It provides basic operations to enable calculation + and comparisons. + + Theory + + This date representation fundamentally departs from the C tm struct + approach. The goal for this type is to provide efficient date + operations (add, subtract) and storage (minimize space to represent) + in a concrete class. Thus, the date uses a count internally to + represent a particular date. The calendar parameter defines + the policies for converting the the year-month-day and internal + counted form here. Applications that need to perform heavy + formatting of the same date repeatedly will perform better + by using the year-month-day representation. + + Internally the date uses a day number to represent the date. + This is a monotonic time representation. This representation + allows for fast comparison as well as simplifying + the creation of writing numeric operations. Essentially, the + internal day number is like adjusted julian day. The adjustment + is determined by the Epoch date which is represented as day 1 of + the calendar. Day 0 is reserved for negative infinity so that + any actual date is automatically greater than negative infinity. + When a date is constructed from a date or formatted for output, + the appropriate conversions are applied to create the year, month, + day representations. + */ + + + template + class date + : boost::less_than_comparable > + { + public: + typedef T date_type; + typedef calendar calendar_type; + typedef typename calendar::date_traits_type traits_type; + typedef duration_type_ duration_type; + typedef typename calendar::year_type year_type; + typedef typename calendar::month_type month_type; + typedef typename calendar::day_type day_type; + typedef typename calendar::ymd_type ymd_type; + typedef typename calendar::date_rep_type date_rep_type; + typedef typename calendar::date_int_type date_int_type; + typedef typename calendar::day_of_week_type day_of_week_type; + date(year_type year, month_type month, day_type day) + : days_(calendar::day_number(ymd_type(year, month, day))) + {} + date(const ymd_type& ymd) + : days_(calendar::day_number(ymd)) + {} + //let the compiler write copy, assignment, and destructor + year_type year() const + { + ymd_type ymd = calendar::from_day_number(days_); + return ymd.year; + } + month_type month() const + { + ymd_type ymd = calendar::from_day_number(days_); + return ymd.month; + } + day_type day() const + { + ymd_type ymd = calendar::from_day_number(days_); + return ymd.day; + } + day_of_week_type day_of_week() const + { + ymd_type ymd = calendar::from_day_number(days_); + return calendar::day_of_week(ymd); + } + ymd_type year_month_day() const + { + return calendar::from_day_number(days_); + } + bool operator<(const date_type& rhs) const + { + return days_ < rhs.days_; + } + bool operator==(const date_type& rhs) const + { + return days_ == rhs.days_; + } + //! check to see if date is not a value + bool is_not_a_date() const + { + return traits_type::is_not_a_number(days_); + } + //! check to see if date is one of the infinity values + bool is_infinity() const + { + return traits_type::is_inf(days_); + } + //! check to see if date is greater than all possible dates + bool is_pos_infinity() const + { + return traits_type::is_pos_infinity(days_); + } + //! check to see if date is greater than all possible dates + bool is_neg_infinity() const + { + return traits_type::is_neg_infinity(days_); + } + //! return as a special value or a not_special if a normal date + special_values as_special() const + { + return traits_type::to_special(days_); + } + duration_type operator-(const date_type& d) const + { + date_rep_type val = date_rep_type(days_) - date_rep_type(d.days_); + return duration_type(val.as_number()); + } + + date_type operator-(const duration_type& dd) const + { + return date_type(date_rep_type(days_) - dd.days()); + } + date_rep_type day_count() const {return days_;}; + //allow internal access from operators + date_type operator+(const duration_type& dd) const + { + return date_type(date_rep_type(days_) + dd.days()); + } + + //see reference + protected: + /*! This is a private constructor which allows for the creation of new + dates. It is not exposed to users since that would require class + users to understand the inner workings of the date class. + */ + date(date_int_type days) : days_(days) {}; + date(date_rep_type days) : days_(days.as_number()) {}; + date_int_type days_; + + }; + + + + +} } // namespace date_time + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + + +#endif diff --git a/include/boost/date_time/date_clock_device.hpp b/include/boost/date_time/date_clock_device.hpp new file mode 100644 index 0000000..50075c9 --- /dev/null +++ b/include/boost/date_time/date_clock_device.hpp @@ -0,0 +1,83 @@ + +#ifndef DATE_CLOCK_DEVICE_HPP___ +#define DATE_CLOCK_DEVICE_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/c_time.hpp" + + +namespace boost { +namespace date_time { + + //! A clock providing day level services based on C time_t capabilities + /*! This clock uses Posix interfaces as its implemenation and hence + * uses the timezone settings of the operating system. Incorrect + * user settings will result in incorrect results for the calls + * to local_day. + */ + template + class day_clock + { + public: + typedef typename date_type::ymd_type ymd_type; + //! Get the local day as a date type + static date_type local_day() + { + return date_type(local_day_ymd()); + } + //! Get the local day as a ymd_type + static typename date_type::ymd_type local_day_ymd() + { + ::std::tm* curr = get_local_time(); + return ymd_type(curr->tm_year + 1900, + curr->tm_mon + 1, + curr->tm_mday); + } + //! Get the current day in universal date as a ymd_type + static typename date_type::ymd_type universal_day_ymd() + { + ::std::tm* curr = get_universal_time(); + return ymd_type(curr->tm_year + 1900, + curr->tm_mon + 1, + curr->tm_mday); + } + //! Get the UTC day as a date type + static date_type universal_day() + { + return date_type(universal_day_ymd()); + } + + private: + static ::std::tm* get_local_time() + { + ::std::time_t t; + ::std::time(&t); + return ::std::localtime(&t); + } + static ::std::tm* get_universal_time() + { + ::std::time_t t; + ::std::time(&t); + return ::std::gmtime(&t); + } + + }; + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/date_defs.hpp b/include/boost/date_time/date_defs.hpp new file mode 100644 index 0000000..ae65d20 --- /dev/null +++ b/include/boost/date_time/date_defs.hpp @@ -0,0 +1,33 @@ + +#ifndef DATE_TIME_DATE_DEFS_HPP +#define DATE_TIME_DATE_DEFS_HPP + +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +namespace boost { +namespace date_time { + + //! An enumeration of weekday names + enum weekdays {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; + +} } //namespace date_time + +/* Copyright (c) 2000,2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + + +#endif diff --git a/include/boost/date_time/date_duration.hpp b/include/boost/date_time/date_duration.hpp new file mode 100644 index 0000000..7a26f83 --- /dev/null +++ b/include/boost/date_time/date_duration.hpp @@ -0,0 +1,77 @@ +#ifndef DATE_TIME_DATE_DURATION__ +#define DATE_TIME_DATE_DURATION__ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +#include + +namespace boost { +namespace date_time { + + + //! Duration type with date level resolution + template + class date_duration + : boost::less_than_comparable + , boost::equality_comparable< date_duration< duration_rep> + > > + { + public: + //! Construct from a day count + explicit date_duration(duration_rep days) : days_(days) {}; + duration_rep days() const + { + return days_; + }; + //! Returns the smallest duration -- used by to calculate 'end' + static date_duration unit() + { + return date_duration(1); + } + //! Equality + bool operator==(const date_duration& rhs) const + { + return days_ == rhs.days_; + } + //! Less + bool operator<(const date_duration& rhs) const + { + return days_ < rhs.days_; + } + //! Subtract another duration -- result is signed + date_duration operator-(const date_duration& rhs) const + { + return date_duration(days_ - rhs.days_); + } + //! Add a duration -- result is signed + date_duration operator+(const date_duration& rhs) const + { + return date_duration(days_ + rhs.days_); + } + //! return sign information + bool is_negative() const + { + return days_ < 0; + } + private: + duration_rep days_; + }; + +} } //namspace date_time + +/* Copyright (c) 2000, 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/date_format_simple.hpp b/include/boost/date_time/date_format_simple.hpp new file mode 100644 index 0000000..e79ba60 --- /dev/null +++ b/include/boost/date_time/date_format_simple.hpp @@ -0,0 +1,95 @@ +#ifndef DATE_TIME_SIMPLE_FORMAT_HPP___ +#define DATE_TIME_SIMPLE_FORMAT_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/parse_format_base.hpp" + +namespace boost { +namespace date_time { + +//! Class to provide simple basic formatting rules +class simple_format { +public: + + //! String used printed is date is invalid + static const char* not_a_date() + { + return "not-a-date"; + } + //! String used to for positive infinity value + static const char* pos_infinity() + { //2001-Jan-03 + return "+infinity "; + } + //! String used to for positive infinity value + static const char* neg_infinity() + { + return "-infinity "; + } + //! Describe month format + static month_format_spec month_format() + { + return month_as_short_string; + } + static ymd_order_spec date_order() + { + return ymd_order_iso; //YYYY-MM-DD + } + //! This format uses '-' to separate date elements + static bool has_date_sep_chars() + { + return true; + } + //! Char to sep? + static char year_sep_char() + { + return '-'; + } + //! char between year-month + static char month_sep_char() + { + return '-'; + } + //! Char to separate month-day + static char day_sep_char() + { + return '-'; + } + //! char between date-hours + static char hour_sep_char() + { + return ' '; + } + //! char between hour and minute + static char minute_sep_char() + { + return ':'; + } + //! char for second + static char second_sep_char() + { + return ':'; + } + +}; + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + + +#endif diff --git a/include/boost/date_time/date_formatting.hpp b/include/boost/date_time/date_formatting.hpp new file mode 100644 index 0000000..508e4fc --- /dev/null +++ b/include/boost/date_time/date_formatting.hpp @@ -0,0 +1,127 @@ +#ifndef DATE_TIME_DATE_FORMATTING_HPP___ +#define DATE_TIME_DATE_FORMATTING_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/iso_format.hpp" +#include +#include +#include + + +namespace boost { +namespace date_time { + + //! Formats a month as as string into an ostream + template + class month_formatter + { + public: + //! Formats a month as as string into an ostream + /*! This function demands that month_type provide + * functions for converting to short and long strings + * if that capability is used. + */ + static std::ostream& format_month(const month_type& month, + std::ostream& os) + { + switch (format_type::month_format()) + { + case month_as_short_string: + { + os << month.as_short_string(); + break; + } + case month_as_long_string: + { + os << month.as_long_string(); + break; + } + case month_as_integer: + { + os << std::setw(2) << std::setfill('0') << month; + break; + } + + } + return os; + } // format_month + }; + + + //! Convert ymd to a standard string formatting policies + template + class ymd_formatter + { + public: + //! Convert ymd to a standard string formatting policies + /*! This is standard code for handling date formatting with + * year-month-day based date information. This function + * uses the format_type to control whether the string will + * contain separator characters, and if so what the character + * will be. In addtion, it can format the month as either + * an integer or a string as controled by the formatting + * policy + */ + static std::string ymd_to_string(ymd_type ymd) + { + typedef typename ymd_type::month_type month_type; + std::ostringstream ss; + ss << ymd.year; + if (format_type::has_date_sep_chars()) { + ss << format_type::month_sep_char(); + } + //this name is a bit ugly, oh well.... + month_formatter::format_month(ymd.month, ss); + if (format_type::has_date_sep_chars()) { + ss << format_type::day_sep_char(); + } + ss << std::setw(2) << std::setfill('0') + << ymd.day; + return ss.str(); + } + }; + + + //! Convert a date to string using format policies + template + class date_formatter + { + public: + //! Convert to a date to standard string using format policies + static std::string date_to_string(date_type d) + { + typedef typename date_type::ymd_type ymd_type; + if (d.is_not_a_date()) { + return format_type::not_a_date(); + } + if (d.is_neg_infinity()) { + return format_type::neg_infinity(); + } + if (d.is_pos_infinity()) { + return format_type::pos_infinity(); + } + ymd_type ymd = d.year_month_day(); + return ymd_formatter::ymd_to_string(ymd); + } + }; + +} } //namespace date_time + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/date_formatting_locales.hpp b/include/boost/date_time/date_formatting_locales.hpp new file mode 100644 index 0000000..53127b7 --- /dev/null +++ b/include/boost/date_time/date_formatting_locales.hpp @@ -0,0 +1,179 @@ +#ifndef DATE_TIME_DATE_FORMATTING_LOCALES_HPP___ +#define DATE_TIME_DATE_FORMATTING_LOCALES_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#ifndef BOOST_NO_STD_LOCALE + +#include "boost/date_time/iso_format.hpp" +#include "boost/date_time/date_names_put.hpp" +#include "boost/date_time/parse_format_base.hpp" +//#include +#include +#include + + +namespace boost { +namespace date_time { + + //! Formats a month as as string into an ostream + template + class ostream_month_formatter + { + public: + typedef typename facet_type::month_type month_type; + typedef std::basic_ostream ostream_type; + + //! Formats a month as as string into an output iterator + static void format_month(const month_type& month, + ostream_type& os, + const facet_type& f, + month_format_spec fs) + { + + switch (fs) + { + case month_as_short_string: + { + std::ostreambuf_iterator oitr(os); + f.put_month_short(oitr, month.as_enum()); + break; + } + case month_as_long_string: + { + std::ostreambuf_iterator oitr(os); + f.put_month_long(oitr, month.as_enum()); + break; + } + case month_as_integer: + { + os << std::setw(2) << std::setfill('0') << month; + break; + } + + } + } // format_month + + }; + + + //! Convert ymd to a standard string formatting policies + template + class ostream_ymd_formatter + { + public: + typedef typename ymd_type::month_type month_type; + typedef ostream_month_formatter month_formatter; + typedef std::basic_ostream ostream_type; + typedef std::basic_string foo_type; + + //! Convert ymd to a standard string formatting policies + /*! This is standard code for handling date formatting with + * year-month-day based date information. This function + * uses the format_type to control whether the string will + * contain separator characters, and if so what the character + * will be. In addtion, it can format the month as either + * an integer or a string as controled by the formatting + * policy + */ + // static string_type ymd_to_string(ymd_type ymd) +// { +// std::ostringstream ss; +// facet_type dnp; +// ymd_put(ymd, ss, dnp); +// return ss.str(); +// } + + // Put ymd to ostream -- part of ostream refactor + static void ymd_put(ymd_type ymd, + ostream_type& os, + const facet_type& f) + { + os << ymd.year; + std::ostreambuf_iterator oitr(os); + if (f.has_date_sep_chars()) { + f.month_sep_char(oitr); + } + month_formatter::format_month(ymd.month, os, + f, month_as_short_string); + + + if (f.has_date_sep_chars()) { + f.day_sep_char(oitr); + } + os << std::setw(2) << std::setfill('0') + << ymd.day; + } + + }; + + + //! Convert a date to string using format policies + template + class ostream_date_formatter + { + public: + typedef std::basic_ostream ostream_type; + typedef typename date_type::ymd_type ymd_type; + + //! Put date into an ostream + static void date_put(const date_type& d, + ostream_type& os, + const facet_type& f) + { + special_values sv = d.as_special(); + if (sv == not_special) { + ymd_type ymd = d.year_month_day(); + ostream_ymd_formatter::ymd_put(ymd, os, f); + } + else { // output a special value + std::ostreambuf_iterator coi(os); + f.put_special_value(coi, sv); + } + } + + + //! Put date into an ostream + static void date_put(const date_type& d, + ostream_type& os) + { + //retrieve the local from the ostream + std::locale locale = os.getloc(); + if (std::has_facet(locale)) { + // std::cout << "Good Deal Dude" << std::endl; + const facet_type& f = std::use_facet(locale); + date_put(d, os, f); + } + else { + //default to something sensible if no facet installed + facet_type default_facet; + date_put(d, os, default_facet); + } + } // date_to_ostream + }; //class date_formatter + + +} } //namespace date_time + +#endif + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/date_generators.hpp b/include/boost/date_time/date_generators.hpp new file mode 100644 index 0000000..60dbc13 --- /dev/null +++ b/include/boost/date_time/date_generators.hpp @@ -0,0 +1,270 @@ +#ifndef DATE_TIME_DATE_GENERATORS_HPP__ +#define DATE_TIME_DATE_GENERATORS_HPP__ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ +/*! @file date_generators.hpp + Definition and implementation of date algorithm templates +*/ + +#include "boost/date_time/date.hpp" + +namespace boost { +namespace date_time { + + + //! Generates a date by applying the year to the given month and day. + /*! + *Example usage: + *@code + * partial_date pd(Jan,1); + * date d = pd.get_date(2002);//2002-Jan-01 + *@endcode + * \ingroup date_alg + */ + template + class partial_date { + public: + typedef typename date_type::calendar_type calendar_type; + typedef typename calendar_type::day_type day_type; + typedef typename calendar_type::month_type month_type; + typedef typename calendar_type::year_type year_type; + typedef typename date_type::duration_type duration_type; + partial_date(month_type m, day_type d) : + month_(m), + day_(d) + {} + //! Return a concrete date when provided with a year specific year. + date_type get_date(year_type y) const + { + return date_type(y, month_, day_); + } + date_type operator()(year_type y) const + { + return date_type(y, month_, day_); + } + + + private: + month_type month_; + day_type day_; + }; + + + //! Useful generator functor for finding holidays + /*! Based on the idea in Cal. Calc. for finding holidays that are + * the 'first Monday of September'. + * The algorithm here basically guesses for the first + * day of the month. Then finds the first day of the correct + * type. That is, if the first of the month is a Tuesday + * and it needs Wenesday then we simply increment by a day + * and then we can add the length of a week until we get + * to the 'nth kday'. There are probably more efficient + * algorithms based on using a mod 7, but this one works + * reasonably well for basic applications. + * \ingroup date_alg + */ + template + class nth_kday_of_month { + public: + typedef typename date_type::calendar_type calendar_type; + typedef typename calendar_type::day_of_week_type day_of_week_type; + typedef typename calendar_type::month_type month_type; + typedef typename calendar_type::year_type year_type; + typedef typename date_type::duration_type duration_type; + enum week_num {first=1, second, third, fourth, fifth}; + nth_kday_of_month(week_num week_no, + day_of_week_type dow, + month_type m) : + month_(m), + wn_(week_no), + dow_(dow) + {} + //! Return a concrete date when provided with a year specific year. + date_type get_date(year_type y) const + { + date_type d(y, month_, 1); //first day of month + duration_type one_day(1); + duration_type one_week(7); + while (dow_ != d.day_of_week()) { + d = d + one_day; + } + int week = 1; + while (week < wn_) { + d = d + one_week; + week++; + } + return d; + } + private: + month_type month_; + week_num wn_; + day_of_week_type dow_; + }; + + //! Useful generator functor for finding holidays and daylight savings + /*! Similar to nth_kday_of_month, but requires less paramters + * \ingroup date_alg + */ + template + class first_kday_of_month { + public: + typedef typename date_type::calendar_type calendar_type; + typedef typename calendar_type::day_of_week_type day_of_week_type; + typedef typename calendar_type::month_type month_type; + typedef typename calendar_type::year_type year_type; + typedef typename date_type::duration_type duration_type; + //!Specify the first 'Sunday' in 'April' spec + /*!@param dow The day of week, eg: Sunday, Monday, etc + * @param month The month of the year, eg: Jan, Feb, Mar, etc + */ + first_kday_of_month(day_of_week_type dow, month_type month) : + month_(month), + dow_(dow) + {} + //! Return a concrete date when provided with a year specific year. + date_type get_date(year_type year) const + { + date_type d(year, month_,1); + duration_type one_day(1); + while (dow_ != d.day_of_week()) { + d = d + one_day; + } + return d; + } + private: + month_type month_; + day_of_week_type dow_; + }; + + + + //! Calculate something like Last Sunday of January + /*! Useful generator functor for finding holidays and daylight savings + * Get the last day of the month and then calculate the difference + * to the last previous day. + * \ingroup date_alg + */ + template + class last_kday_of_month { + public: + typedef typename date_type::calendar_type calendar_type; + typedef typename calendar_type::day_of_week_type day_of_week_type; + typedef typename calendar_type::month_type month_type; + typedef typename calendar_type::year_type year_type; + typedef typename date_type::duration_type duration_type; + //!Specify the date spec like 'Sunday' in 'April' spec + /*!@param dow The day of week, eg: Sunday, Monday, etc + * @param month The month of the year, eg: Jan, Feb, Mar, etc + */ + last_kday_of_month(day_of_week_type dow, month_type month) : + month_(month), + dow_(dow) + {} + //! Return a concrete date when provided with a year specific year. + date_type get_date(year_type year) const + { + date_type d(year, month_, calendar_type::end_of_month_day(year,month_)); + duration_type one_day(1); + while (dow_ != d.day_of_week()) { + d = d - one_day; + } + return d; + } + private: + month_type month_; + day_of_week_type dow_; + }; + + + //! Calculate something like "First Sunday after Jan 1,2002 + /*! Date generator that takes a date and finds kday after + *@code + typedef boost::date_time::first_kday_after firstkdayafter; + firstkdayafter fkaf(Monday); + fkaf.get_date(date(2002,Feb,1)); + @endcode + * \ingroup date_alg + */ + template + class first_kday_after { + public: + typedef typename date_type::calendar_type calendar_type; + typedef typename calendar_type::day_of_week_type day_of_week_type; + typedef typename date_type::duration_type duration_type; + first_kday_after(day_of_week_type dow) : + dow_(dow) + {} + //! Return next kday given. + date_type get_date(date_type start_day) const + { + duration_type one_day(1); + date_type d = start_day + one_day; + while (dow_ != d.day_of_week()) { + d = d + one_day; + } + return d; + } + + private: + day_of_week_type dow_; + }; + + //! Calculate something like "First Sunday before Jan 1,2002 + /*! Date generator that takes a date and finds kday after + *@code + typedef boost::date_time::first_kday_before firstkdaybefore; + firstkdaybefore fkbf(Monday); + fkbf.get_date(date(2002,Feb,1)); + @endcode + * \ingroup date_alg + */ + template + class first_kday_before { + public: + typedef typename date_type::calendar_type calendar_type; + typedef typename calendar_type::day_of_week_type day_of_week_type; + typedef typename date_type::duration_type duration_type; + first_kday_before(day_of_week_type dow) : + dow_(dow) + {} + //! Return next kday given. + date_type get_date(date_type start_day) const + { + duration_type one_day(1); + date_type d = start_day - one_day; + while (dow_ != d.day_of_week()) { + d = d - one_day; + } + return d; + } + + private: + day_of_week_type dow_; + }; + + +} } //namespace date_time + + +/* + * Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided as is without express or implied warranty. + * + * + * Author: Jeff Garland (jeff@CrystalClearSoftware.com) + * Created: Sun Sep 9 17:20:39 2001 + * + */ + + +#endif diff --git a/include/boost/date_time/date_iterator.hpp b/include/boost/date_time/date_iterator.hpp new file mode 100644 index 0000000..78230f9 --- /dev/null +++ b/include/boost/date_time/date_iterator.hpp @@ -0,0 +1,98 @@ +#ifndef DATE_ITERATOR_HPP___ +#define DATE_ITERATOR_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include + +namespace boost { +namespace date_time { + //! An iterator over dates with varying resolution (day, week, month, year, etc) + enum date_resolutions {day, week, months, year, decade, century, NumDateResolutions}; + + //! Base date iterator type + /*! This class provides the skeleton for the creation of iterators. + * New and interesting interators can be created by plugging in a new + * function that derives the next value from the current state. + * generation of various types of -based information. + * + * Template Parameters + * + * date_type + * + * The date_type is a concrete date_type. The date_type must + * define a duration_type and a calendar_type. + */ + template + class date_itr_base { + // works, but benefit unclear at the moment + // class date_itr_base : public std::iterator{ + public: + typedef typename date_type::duration_type duration_type; + typedef date_type value_type; + typedef std::input_iterator_tag iterator_category; + + date_itr_base(date_type d) : current_(d) {} + virtual ~date_itr_base() {}; + date_itr_base& operator++() + { + current_ = current_ + get_offset(current_); + return *this; + }; + virtual duration_type get_offset(const date_type& current) const=0; + date_type operator*() {return current_;}; + date_type* operator->() {return ¤t_;}; + bool operator< (const date_type& d) {return current_ < d;} + bool operator<= (const date_type& d) {return current_ <= d;} + bool operator> (const date_type& d) {return current_ > d;} + bool operator>= (const date_type& d) {return current_ >= d;} + bool operator== (const date_type& d) {return current_ == d;} + bool operator!= (const date_type& d) {return current_ != d;} + private: + date_type current_; + }; + + //! Overrides the base date iterator providing hook for functors + /* + * offset_functor + * + * The offset functor must define a get_offset function that takes the + * current point in time and calculates and offset. + * + */ + template + class date_itr : public date_itr_base { + public: + typedef typename date_type::duration_type duration_type; + date_itr(date_type d, int factor=1) : + date_itr_base(d), + of_(factor) + {} + virtual duration_type get_offset(const date_type& current) const + { + return of_.get_offset(current); + } + private: + offset_functor of_; + }; + + + +} } //namespace date_time + +/* Copyright (c) 2000, 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/date_names_put.hpp b/include/boost/date_time/date_names_put.hpp new file mode 100644 index 0000000..05ed886 --- /dev/null +++ b/include/boost/date_time/date_names_put.hpp @@ -0,0 +1,230 @@ +#ifndef DATE_TIME_DATE_NAMES_PUT_HPP___ +#define DATE_TIME_DATE_NAMES_PUT_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +#include "boost/config.hpp" //sets BOOST_NO_STD_LOCALE + +//This file basically becomes a noop if locales are not supported +#ifndef BOOST_NO_STD_LOCALE + +#include "boost/date_time/special_defs.hpp" +#include "boost/date_time/date_defs.hpp" +#include + + +namespace boost { +namespace date_time { + + //! Output facet base class for gregorian dates. + /*! This class is a base class for date facets used to localize the + * names of months and the names of days in the week. + * + * Requirements of Config + * - define an enumeration month_enum that enumerates the months. + * The enumeration should be '1' based eg: Jan==1 + * - define as_short_string and as_long_string + * + * (see langer & kreft p334). + * + */ + template > + class date_names_put : public std::locale::facet + { + public: + date_names_put() {}; + typedef OutputIterator iter_type; + typedef typename Config::month_type month_type; + typedef typename Config::month_enum month_enum; + typedef typename Config::weekday_enum weekday_enum; + typedef typename Config::special_value_enum special_value_enum; + //typedef typename Config::format_type format_type; + typedef std::basic_string string_type; + + static std::locale::id id; + void put_special_value(iter_type& oitr, special_value_enum sv) const + { + do_put_special_value(oitr, sv); + } + void put_month_short(iter_type& oitr, month_enum moy) const + { + do_put_month_short(oitr, moy); + } + void put_month_long(iter_type& oitr, month_enum moy) const + { + do_put_month_long(oitr, moy); + } + void put_weekday_short(iter_type& oitr, weekday_enum wd) const + { + do_put_weekday_short(oitr, wd); + } + void put_weekday_long(iter_type& oitr, weekday_enum wd) const + { + do_put_weekday_long(oitr, wd); + } + bool has_date_sep_chars() const + { + return do_has_date_sep_chars(); + } + void year_sep_char(iter_type& oitr) const + { + do_year_sep_char(oitr); + } + //! char between year-month + void month_sep_char(iter_type& oitr) const + { + do_month_sep_char(oitr); + } + //! Char to separate month-day + void day_sep_char(iter_type& oitr) const + { + do_day_sep_char(oitr); + } + + protected: + //! Default facet implementation uses month_type defaults + virtual void do_put_month_short(iter_type& oitr, month_enum moy) const + { + month_type gm(moy); + put_string(oitr, gm.as_short_string()); + } + //! Default facet implementation uses month_type defaults + virtual void do_put_month_long(iter_type& oitr, + month_enum moy) const + { + month_type gm(moy); + put_string(oitr, gm.as_long_string()); + } + //! Default facet implementation for special value types + virtual void do_put_special_value(iter_type& oitr, special_value_enum sv) const + { + switch (sv) { + case not_a_date_time: + { + put_string(oitr, "not-a-date-time"); + break; + } + case pos_infin: + { + put_string(oitr, "+infinity"); + break; + } + case neg_infin: + { + put_string(oitr, "-infinity"); + break; + } + } + } + virtual void do_put_weekday_short(iter_type& oitr, weekday_enum wd) const + { + } + virtual void do_put_weekday_long(iter_type& oitr, weekday_enum wd) const + { + } + virtual bool do_has_date_sep_chars() const + { + return true; + } + virtual void do_year_sep_char(iter_type& oitr) const + { + put_string(oitr, "-"); + } + //! char between year-month + virtual void do_month_sep_char(iter_type& oitr) const + { + put_string(oitr, "-"); + } + //! Char to separate month-day + virtual void do_day_sep_char(iter_type& oitr) const + { + put_string(oitr, "-"); + } + + void put_string(iter_type& oi, const char* const s) const + { + string_type s1(s); + typename string_type::iterator si,end; + for (si=s1.begin(), end=s1.end(); si!=end; si++, oi++) { + *oi = *si; + } + } + }; + + + //! An date name output facet that takes an array of char* to define strings + template > + class all_date_names_put : public date_names_put + { + public: + all_date_names_put(const charT* const month_short_names[], + const charT* const month_long_names[], + const charT* const special_value_names[], + const charT* const weekday_short_names[], + const charT* const weekday_long_names[]) : + month_short_names_(month_short_names), + month_long_names_(month_long_names), + special_value_names_(special_value_names), + weekday_short_names_(weekday_short_names), + weekday_long_names_(weekday_long_names) + {}; + typedef OutputIterator iter_type; + typedef typename Config::month_enum month_enum; + typedef typename Config::weekday_enum weekday_enum; + typedef typename Config::special_value_enum special_value_enum; + + protected: + //! Generic facet that takes array of chars + virtual void do_put_month_short(iter_type& oitr, month_enum moy) const + { + put_string(oitr, month_short_names_[moy-1]); + } + //! Long month names + virtual void do_put_month_long(iter_type& oitr, month_enum moy) const + { + put_string(oitr, month_long_names_[moy-1]); + } + //! Special values names + virtual void do_put_special_value(iter_type& oitr, special_value_enum sv) const + { + put_string(oitr, special_value_names_[sv]); + } + virtual void do_put_weekday_short(iter_type& oitr, weekday_enum wd) const + { + put_string(oitr, weekday_short_names_[wd]); + } + virtual void do_put_weekday_long(iter_type& oitr, weekday_enum wd) const + { + put_string(oitr, weekday_long_names_[wd]); + } + private: + const char* const* month_short_names_; + const char* const* month_long_names_; + const char* const* special_value_names_; + const char* const* weekday_short_names_; + const char* const* weekday_long_names_; + }; + +} } //namespace boost::date_time + +#endif //BOOST_NO_STD_LOCALE + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif diff --git a/include/boost/date_time/date_parsing.hpp b/include/boost/date_time/date_parsing.hpp new file mode 100644 index 0000000..f617f93 --- /dev/null +++ b/include/boost/date_time/date_parsing.hpp @@ -0,0 +1,103 @@ + +#ifndef _DATE_TIME_DATE_PARSING_HPP___ +#define _DATE_TIME_DATE_PARSING_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/tokenizer.hpp" +#include "boost/lexical_cast.hpp" + + +namespace boost { + +namespace date_time { + + + //! Generic function to parse a delimited date (eg: 2002-02-10) + template + date_type + parse_date(const std::string& s) + { + typedef typename date_type::year_type year_type; + int pos = 0; + typename date_type::ymd_type ymd(year_type::min(),1,1); + boost::tokenizer > tok(s); + for(boost::tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ + int i = boost::lexical_cast(*beg); + switch(pos) { + case 0: ymd.year = i; break; + case 1: ymd.month = i; break; + case 2: ymd.day = i; break; + }; + pos++; + } + return date_type(ymd); + } + + //! Generic function to parse undelimited date (eg: 20020201) + template + date_type + parse_undelimited_date(const std::string& s) + { + int offsets[] = {4,2,2}; + int pos = 0; + typedef typename date_type::year_type year_type; + typename date_type::ymd_type ymd(year_type::min(),1,1); + boost::offset_separator osf(offsets, offsets+3); + boost::tokenizer tok(s, osf); + for(boost::tokenizer::iterator ti=tok.begin(); ti!=tok.end();++ti){ + int i = boost::lexical_cast(*ti); + // std::cout << i << std::endl; + switch(pos) { + case 0: ymd.year = i; break; + case 1: ymd.month = i; break; + case 2: ymd.day = i; break; + }; + pos++; + } + return date_type(ymd); + } + + + template + date_type + parse_date2(const std::string& s) + { + //using namespace boost; + int pos = 0; + typedef typename date_type::year_type year_type; + typename date_type::ymd_type ymd(year_type::min(),1,1); + boost::char_delimiters_separator delim("DT"); + boost::tokenizer > tok(s); + for(boost::tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ + int i = boost::lexical_cast(*beg); + switch(pos) { + case 0: ymd.year = i; break; + case 1: ymd.month = i; break; + case 2: ymd.day = i; break; + }; + pos++; + } + return date_type(ymd); + } + + +} } //namespace date_time + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/dst_rules.hpp b/include/boost/date_time/dst_rules.hpp new file mode 100644 index 0000000..e4f61fe --- /dev/null +++ b/include/boost/date_time/dst_rules.hpp @@ -0,0 +1,266 @@ + +#ifndef DATE_TIME_DST_RULES_HPP__ +#define DATE_TIME_DST_RULES_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! @file dst_rules.hpp + Contains template class to provide static dst rule calculations +*/ + +#include "boost/date_time/date_generators.hpp" +#include "boost/date_time/period.hpp" +#include "boost/date_time/date_defs.hpp" +#include + +namespace boost { +namespace date_time { + + enum time_is_dst_result {is_not_in_dst, is_in_dst, + ambiguous, invalid_time_label}; + + + //! Generic functions to calculate dst transition information + template + class dst_calculator + { + public: + typedef time_duration_type_ time_duration_type; + typedef date_type_ date_type; + + //! Check the local time offset when on dst start day + /*! On this dst transition, the time label between + * the transition boundary and the boudary + the offset + * are invalid times. If before the boundary then still + * not in dst. + *@param time_of_day Time offset in the day for the local time + *@param dst_start_offset_minutes Local day offset for start of dst + *@param dst_length_minutes Number of minutes to adjust clock forward + *@retval status of time label w.r.t. dst + */ + static time_is_dst_result + process_local_dst_start_day(const time_duration_type& time_of_day, + unsigned int dst_start_offset_minutes, + long dst_length_minutes) + { + // std::cout << "here" << std::endl; + if (time_of_day < time_duration_type(0,dst_start_offset_minutes,0)) { + return is_not_in_dst; + } + long offset = dst_start_offset_minutes + dst_length_minutes; + if (time_of_day >= time_duration_type(0,offset,0)) { + return is_in_dst; + } + return invalid_time_label; + } + + //! Check the local time offset when on the last day of dst + /*! This is the calculation for the DST end day. On that day times + * prior to the conversion time - dst_length (1 am in US) are still + * in dst. Times between the above and the switch time are + * ambiguous. Times after the start_offset are not in dst. + *@param time_of_day Time offset in the day for the local time + *@param dst_end_offset_minutes Local time of day for end of dst + *@retval status of time label w.r.t. dst + */ + static time_is_dst_result + process_local_dst_end_day(const time_duration_type& time_of_day, + unsigned int dst_end_offset_minutes, + long dst_length_minutes) + { + //in US this will be 60 so offset in day is 1,0,0 + int offset = dst_end_offset_minutes-dst_length_minutes; + if (time_of_day < time_duration_type(0,offset,0)) { + return is_in_dst; + } + if (time_of_day >= time_duration_type(0,dst_end_offset_minutes,0)) { + return is_not_in_dst; + } + return ambiguous; + } + + //! Calculates if the given local time is dst or not + /*! Determines if the time is really in DST or not. Also checks for + * invalid and ambiguous. + * @param current_day The day to check for dst + * @param time_of_day Time offset within the day to check + * @param dst_start_day Starting day of dst for the given locality + * @param dst_start_offset_minutes Offset within day for dst + * boundary (eg 120 for US which is 02:00:00) + * @param dst_end_day Ending day of dst for the given locality + * @param dst_end_offset_minutes Offset within day for dst + * boundary (eg 120 for US which is 02:00:00) + * @param dst_length_minutes Length of dst adjusment (eg: 60 for US) + * @retval The time is either ambiguous, invalid, in dst, or not in dst + */ + static time_is_dst_result + local_is_dst(const date_type& current_day, + const time_duration_type& time_of_day, + const date_type& dst_start_day, + unsigned int dst_start_offset_minutes, + const date_type& dst_end_day, + unsigned int dst_end_offset_minutes, + long dst_length_minutes) + { + //in northern hemisphere dst is in the middle of the year + if (dst_start_day < dst_end_day) { + if ((current_day > dst_start_day) && (current_day < dst_end_day)) { + return is_in_dst; + } + if ((current_day < dst_start_day) || (current_day > dst_end_day)) { + return is_not_in_dst; + } + } + else {//southern hemisphere dst is at begining /end of year + if ((current_day < dst_start_day) && (current_day > dst_end_day)) { + return is_not_in_dst; + } + if ((current_day > dst_start_day) || (current_day < dst_end_day)) { + return is_in_dst; + } + } + + if (current_day == dst_start_day) { + return process_local_dst_start_day(time_of_day, + dst_start_offset_minutes, + dst_length_minutes); + } + + if (current_day == dst_end_day) { + return process_local_dst_end_day(time_of_day, + dst_end_offset_minutes, + dst_length_minutes); + } + //you should never reach this statement + return invalid_time_label; + } + + }; + + + //! Class to calculate dst boundaries for US time zones + /* + */ + template //1 hour == 60 min in US + class us_dst_rules + { + public: + typedef time_duration_type_ time_duration_type; + typedef date_type_ date_type; + typedef typename date_type::year_type year_type; + typedef typename date_type::calendar_type calendar_type; + typedef date_time::last_kday_of_month lkday; + typedef date_time::first_kday_of_month fkday; + typedef dst_calculator dstcalc; + + //! Calculates if the given local time is dst or not + /*! Determines if the time is really in DST or not. Also checks for + * invalid and ambiguous. + * @retval The time is either ambiguous, invalid, in dst, or not in dst + */ + static time_is_dst_result local_is_dst(const date_type& d, + const time_duration_type& td) + { + + year_type y = d.year(); + date_type dst_start = local_dst_start_day(y); + date_type dst_end = local_dst_end_day(y); + return dstcalc::local_is_dst(d,td, + dst_start,dst_start_offset_minutes, + dst_end, dst_start_offset_minutes, + dst_length_minutes); + + } + + + static bool is_dst_boundary_day(date_type d) + { + year_type y = d.year(); + return ((d == local_dst_start_day(y)) || + (d == local_dst_end_day(y))); + } + + static date_type local_dst_start_day(year_type year) + { + //first sunday in april + fkday fsia(Sunday, gregorian::Apr); + return fsia.get_date(year); + } + + static date_type local_dst_end_day(year_type year) + { + //last sunday in october + lkday lsio(Sunday, gregorian::Oct); + return lsio.get_date(year); + } + + static time_duration_type dst_offset() + { + return time_duration_type(0,dst_length_minutes,0); + } + + }; + + + + //! Used for local time adjustments in places that don't use dst + template + class null_dst_rules + { + public: + typedef time_duration_type_ time_duration_type; + typedef date_type_ date_type; + + + //! Calculates if the given local time is dst or not + /*! @retval Always is_not_in_dst since this is for zones without dst + */ + static time_is_dst_result local_is_dst(const date_type&, + const time_duration_type&) + { + return is_not_in_dst; + } + + //! Calculates if the given utc time is in dst + static time_is_dst_result utc_is_dst(const date_type&, + const time_duration_type&) + { + return is_not_in_dst; + } + + static bool is_dst_boundary_day(date_type d) + { + return false; + } + + static time_duration_type dst_offset() + { + return time_duration_type(0,0,0); + } + + }; + + +} } //namespace date_time + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif diff --git a/include/boost/date_time/gregorian/formatters.hpp b/include/boost/date_time/gregorian/formatters.hpp new file mode 100644 index 0000000..614b0b5 --- /dev/null +++ b/include/boost/date_time/gregorian/formatters.hpp @@ -0,0 +1,111 @@ +#ifndef GREGORIAN_FORMATTERS_HPP___ +#define GREGORIAN_FORMATTERS_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/gregorian/gregorian_types.hpp" +#include "boost/date_time/gregorian/greg_facet.hpp" +#include "boost/date_time/date_formatting.hpp" +#include "boost/date_time/iso_format.hpp" +#include "boost/date_time/date_format_simple.hpp" + +namespace boost { +namespace gregorian { + + + + //! To YYYY-mmm-DD string where mmm 3 char month name. Example: 2002-Jan-01 + /*!\ingroup date_format + */ + inline std::string to_simple_string(const date& d) { + return date_time::date_formatter::date_to_string(d); + } + + //! Convert date period to simple string. Example: [2002-Jan-01/2002-Jan-02] + /*!\ingroup date_format + */ + inline std::string to_simple_string(const date_period& d) { + std::string s("["); + std::string d1(date_time::date_formatter::date_to_string(d.begin())); + std::string d2(date_time::date_formatter::date_to_string(d.last())); + return std::string("[" + d1 + "/" + d2 + "]"); + } + + //! Date period to iso standard format CCYYMMDD/CCYYMMDD. Example: 20021225/20021231 + /*!\ingroup date_format + */ + inline std::string to_iso_string(const date_period& d) { + std::string s(date_time::date_formatter::date_to_string(d.begin())); + return s + "/" + date_time::date_formatter::date_to_string(d.last()); + } + + + //! Convert to iso extended format string CCYY-MM-DD. Example 2002-12-31 + /*!\ingroup date_format + */ + inline std::string to_iso_extended_string(const date& d) { + return date_time::date_formatter::date_to_string(d); + } + + //! Convert to iso standard string YYYYMMDD. Example: 20021231 + /*!\ingroup date_format + */ + inline std::string to_iso_string(const date& d) { + return date_time::date_formatter::date_to_string(d); + } + + + + inline std::string to_sql_string(const date& d) + { + date::ymd_type ymd = d.year_month_day(); + std::ostringstream ss; + ss << ymd.year << "-" + << std::setw(2) << std::setfill('0') + << ymd.month + << "-" + << std::setw(2) << std::setfill('0') + << ymd.day; + return ss.str(); + } + +} } //namespace gregorian + + + + + + + + + + + + + + + + + + + + + + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/gregorian/greg_calendar.hpp b/include/boost/date_time/gregorian/greg_calendar.hpp new file mode 100644 index 0000000..e0c0fc6 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_calendar.hpp @@ -0,0 +1,52 @@ +#ifndef GREGORIAN_GREGORIAN_CALENDAR_HPP__ +#define GREGORIAN_GREGORIAN_CALENDAR_HPP__ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/gregorian/greg_weekday.hpp" +#include "boost/date_time/gregorian/greg_day_of_year.hpp" +#include "boost/date_time/gregorian_calendar.hpp" +#include "boost/date_time/gregorian/greg_ymd.hpp" +#include "boost/date_time/int_adapter.hpp" + +namespace boost { +namespace gregorian { + + //!An internal date representation that includes infinities, not a date + typedef date_time::int_adapter fancy_date_rep; + + //! Gregorian calendar for this implementation, hard work in the base + class gregorian_calendar : + public date_time::gregorian_calendar_base { + public: + //! Type to hold a weekday (eg: Sunday, Monday,...) + typedef greg_weekday day_of_week_type; + //! Internal date representation that handles infinity, not a date + typedef fancy_date_rep date_rep_type; + //! Date rep implements the traits stuff as well + typedef fancy_date_rep date_traits_type; + + + private: + }; + +} } //namespace gregorian + + +/* Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif + diff --git a/include/boost/date_time/gregorian/greg_date.hpp b/include/boost/date_time/gregorian/greg_date.hpp new file mode 100644 index 0000000..2908c4b --- /dev/null +++ b/include/boost/date_time/gregorian/greg_date.hpp @@ -0,0 +1,90 @@ +#ifndef GREG_DATE_HPP___ +#define GREG_DATE_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/date.hpp" +#include "boost/date_time/special_defs.hpp" +#include "boost/date_time/gregorian/greg_calendar.hpp" +#include "boost/date_time/gregorian/greg_duration.hpp" + + +namespace boost { +namespace gregorian { + + //bring special enum values into the namespace + using date_time::special_values; + using date_time::not_special; + using date_time::neg_infin; + using date_time::pos_infin; + using date_time::not_a_date_time; + using date_time::max_date_time; + using date_time::min_date_time; + + //! A date type based on gregorian_calendar + /*! This class is the primary interface for programming with + greogorian dates. The is a lightweight type that can be + freely passed by value. All comparison operators are + supported. + \ingroup date_basics + */ + class date : public date_time::date + { + public: + typedef gregorian_calendar::year_type year_type; + typedef gregorian_calendar::month_type month_type; + typedef gregorian_calendar::day_type day_type; + typedef gregorian_calendar::ymd_type ymd_type; + typedef gregorian_calendar::date_rep_type date_rep_type; + typedef gregorian_calendar::date_int_type date_int_type; + typedef date_duration duration_type; + //! Main constructor with year, month, day + date(year_type year, month_type month, day_type day) + : date_time::date(year, month, day) + {} + //! Constructor from a ymd_type structure + explicit date(const ymd_type& ymd) + : date_time::date(ymd) + {} + //! Needed copy constructor + date(const date_int_type& rhs): + date_time::date(rhs) + {} + //! Needed copy constructor + date(date_rep_type rhs): + date_time::date(rhs) + {} + //! Constructor for infinities, not a date, max and min date + explicit date(special_values sv): + date_time::date(date_rep_type::from_special(sv)) + {} + //! Return the day number from the calendar + date_int_type day_number() const + { + return days_; + } + + private: + + }; + + + +} } //namespace gregorian + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_day.hpp b/include/boost/date_time/gregorian/greg_day.hpp new file mode 100644 index 0000000..d977ada --- /dev/null +++ b/include/boost/date_time/gregorian/greg_day.hpp @@ -0,0 +1,59 @@ +#ifndef GREG_DAY_HPP___ +#define GREG_DAY_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/constrained_value.hpp" +#include + +namespace boost { +namespace gregorian { + + //! Exception type for gregorian day of month (1..31) + struct bad_day_of_month : public std::out_of_range + { + bad_day_of_month() : + std::out_of_range("Day of month value is out of range 1..31") + {} + }; + //! Policy class that declares error handling and day of month ranges + typedef CV::simple_exception_policy greg_day_policies; + + //! Generated represetation for gregorian day of month + typedef CV::constrained_value greg_day_rep; + + //! Represent a day of the month (range 1 - 31) + /*! This small class allows for simple conversion an integer value into + a day of the month for a standard gregorian calendar. The type + is automatically range checked so values outside of the range 1-31 + will cause a bad_day_of_month exception + */ + class greg_day : public greg_day_rep { + public: + greg_day(unsigned short day_of_month) : greg_day_rep(day_of_month) {} + unsigned short as_number() const {return value_;} + operator unsigned short() const {return value_;} + private: + + }; + + + +} } //namespace gregorian + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_day_of_year.hpp b/include/boost/date_time/gregorian/greg_day_of_year.hpp new file mode 100644 index 0000000..4319970 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_day_of_year.hpp @@ -0,0 +1,44 @@ +#ifndef GREG_DAY_OF_YEAR_HPP___ +#define GREG_DAY_OF_YEAR_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/constrained_value.hpp" +#include + +namespace boost { +namespace gregorian { + + //! Exception type for day of year (1..366) + struct bad_day_of_year : public std::out_of_range + { + bad_day_of_year() : + std::out_of_range("Day of year value is out of range 1..366") + {} + }; + + //! A day of the year range (1..366) + typedef CV::simple_exception_policy greg_day_of_year_policies; + + //! Define a range representation type for the day of the year 1..366 + typedef CV::constrained_value greg_day_of_year_rep; + + +} } //namespace gregorian + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_duration.hpp b/include/boost/date_time/gregorian/greg_duration.hpp new file mode 100644 index 0000000..1acf250 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_duration.hpp @@ -0,0 +1,41 @@ +#ifndef GREG_DURATION_HPP___ +#define GREG_DURATION_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/date_duration.hpp" +#include "boost/date_time/int_adapter.hpp" + + +namespace boost { +namespace gregorian { + + //!An internal date representation that includes infinities, not a date + //typedef date_time::int_adapter date_duration_rep; + typedef long date_duration_rep; + + //! Durations in days for gregorian system + /*! \ingroup date_basics + */ + typedef date_time::date_duration date_duration; + // typedef date_time::date_duration date_duration; + typedef date_duration days; + +} } //namespace gregorian + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_facet.hpp b/include/boost/date_time/gregorian/greg_facet.hpp new file mode 100644 index 0000000..79b6da6 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_facet.hpp @@ -0,0 +1,76 @@ +#ifndef GREGORIAN_FORMATTERS_HPP___ +#define GREGORIAN_FORMATTERS_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/gregorian/gregorian_types.hpp" +#include "boost/date_time/date_names_put.hpp" +#include "boost/date_time/date_formatting_locales.hpp" + +//This file basically becomes a noop if locales are not supported +#ifndef BOOST_NO_STD_LOCALE + +namespace boost { +namespace gregorian { + + //! Configuration of the output facet + struct greg_facet_config + { + typedef boost::gregorian::greg_month month_type; + typedef boost::date_time::special_values special_value_enum; + typedef boost::gregorian::months_of_year month_enum; + typedef boost::date_time::weekdays weekday_enum; + }; + + typedef boost::date_time::date_names_put greg_base_facet; + + template + std::basic_ostream& + operator<<(std::basic_ostream& os, const date& d) + { + typedef boost::date_time::ostream_date_formatter greg_ostream_formatter; + greg_ostream_formatter::date_put(d, os); + return os; + } + + +} } //namespace gregorian + +#endif + + + + + + + + + + + + + + + + + + + + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/gregorian/greg_month.hpp b/include/boost/date_time/gregorian/greg_month.hpp new file mode 100644 index 0000000..d044110 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_month.hpp @@ -0,0 +1,62 @@ +#ifndef GREG_MONTH_HPP___ +#define GREG_MONTH_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/constrained_value.hpp" +#include + + +namespace boost { +namespace gregorian { + + + //! Simple enum to allow for nice programming with Jan, Feb, etc + enum months_of_year {Jan=1,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,NotAMonth,NumMonths}; + + //! Exception thrown if a greg_month is constructed with a value out of range + struct bad_month : public std::out_of_range + { + bad_month() : std::out_of_range("Month number is out of range 1..12") {} + }; + //! Build a policy class for the greg_month_rep + typedef CV::simple_exception_policy greg_month_policies; + //! A constrained range that implements the gregorian_month rules + typedef CV::constrained_value greg_month_rep; + + + //! Wrapper class to represent months in gregorian based calendar + class greg_month : public greg_month_rep { + public: + typedef months_of_year month_enum; + //! Construct a month from the months_of_year enumeration + greg_month(months_of_year theMonth) : greg_month_rep(theMonth) {} + //! Construct from a short value + greg_month(short theMonth) : greg_month_rep(theMonth) {} + //! Convert the value back to a short + operator unsigned short() const {return value_;} + //! Returns month as number from 1 to 12 + unsigned short as_number() const {return value_;} + month_enum as_enum() const {return static_cast(value_);} + const char* as_short_string() const; + const char* as_long_string() const; + }; + +} } //namespace gregorian + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_weekday.hpp b/include/boost/date_time/gregorian/greg_weekday.hpp new file mode 100644 index 0000000..aa594ea --- /dev/null +++ b/include/boost/date_time/gregorian/greg_weekday.hpp @@ -0,0 +1,64 @@ +#ifndef GREG_WEEKDAY_HPP___ +#define GREG_WEEKDAY_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/constrained_value.hpp" +#include "boost/date_time/date_defs.hpp" +#include + +namespace boost { +namespace gregorian { + + //bring enum values into the namespace + using date_time::Sunday; + using date_time::Monday; + using date_time::Tuesday; + using date_time::Wednesday; + using date_time::Thursday; + using date_time::Friday; + using date_time::Saturday; + + + //! Exception that flags that a weekday number is incorrect + struct bad_weekday : public std::out_of_range + { + bad_weekday() : std::out_of_range("Weekday os out of range 0..6") {} + }; + typedef CV::simple_exception_policy greg_weekday_policies; + typedef CV::constrained_value greg_weekday_rep; + + + //! Represent a day within a week (range 0==Sun to 6==Sat) + class greg_weekday : public greg_weekday_rep { + public: + greg_weekday(unsigned short day_of_week_num) : + greg_weekday_rep(day_of_week_num) + {} + + unsigned short as_number() const {return value_;} + const char* as_short_string() const; + const char* as_long_string() const; + + }; + + + +} } //namespace gregorian + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_year.hpp b/include/boost/date_time/gregorian/greg_year.hpp new file mode 100644 index 0000000..13d04a7 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_year.hpp @@ -0,0 +1,59 @@ +#ifndef GREG_YEAR_HPP___ +#define GREG_YEAR_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/constrained_value.hpp" +#include + +namespace boost { +namespace gregorian { + + //! Exception type for gregorian year + struct bad_year : public std::out_of_range + { + bad_year() : + std::out_of_range("Year is out of valid range: 1400..10000") + {} + }; + //! Policy class that declares error handling gregorian year type + typedef CV::simple_exception_policy greg_year_policies; + + //! Generated representation for gregorian year + typedef CV::constrained_value greg_year_rep; + + //! Represent a day of the month (range 1900 - 10000) + /*! This small class allows for simple conversion an integer value into + a year for the gregorian calendar. This currently only allows a + range of 1900 to 10000. Both ends of the range are a bit arbitrary + at the moment, but they are the limits of current testing of the + library. As such they may be increased in the future. + */ + class greg_year : public greg_year_rep { + public: + greg_year(unsigned short year) : greg_year_rep(year) {} + operator unsigned short() const {return value_;} + private: + + }; + + + +} } //namespace gregorian + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/gregorian/greg_ymd.hpp b/include/boost/date_time/gregorian/greg_ymd.hpp new file mode 100644 index 0000000..f0f3481 --- /dev/null +++ b/include/boost/date_time/gregorian/greg_ymd.hpp @@ -0,0 +1,40 @@ +#ifndef DATE_TIME_GREG_YMD_HPP__ +#define DATE_TIME_GREG_YMD_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/year_month_day.hpp" +#include "boost/date_time/special_defs.hpp" +#include "boost/date_time/gregorian/greg_day.hpp" +#include "boost/date_time/gregorian/greg_year.hpp" +#include "boost/date_time/gregorian/greg_month.hpp" + +namespace boost { +namespace gregorian { + + typedef date_time::year_month_day_base greg_year_month_day; + + + +} } //namespace gregorian + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif + diff --git a/include/boost/date_time/gregorian/gregorian.hpp b/include/boost/date_time/gregorian/gregorian.hpp new file mode 100644 index 0000000..7c7d05a --- /dev/null +++ b/include/boost/date_time/gregorian/gregorian.hpp @@ -0,0 +1,32 @@ +#ifndef GREGORIAN_HPP__ +#define GREGORIAN_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ +/*! @file gregorian.hpp + Single file header that provides overall include for all elements of + the gregorian date-time system. This includes the various types + defined, but also other functions for formatting and parsing. +*/ + + +#include "boost/date_time/gregorian/gregorian_types.hpp" +#include "boost/date_time/gregorian/formatters.hpp" +#include "boost/date_time/gregorian/greg_facet.hpp" +#include "boost/date_time/gregorian/parsers.hpp" + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/gregorian/gregorian_types.hpp b/include/boost/date_time/gregorian/gregorian_types.hpp new file mode 100644 index 0000000..5e05c57 --- /dev/null +++ b/include/boost/date_time/gregorian/gregorian_types.hpp @@ -0,0 +1,77 @@ +#ifndef _GREGORIAN_TYPES_HPP__ +#define _GREGORIAN_TYPES_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ +/*! @file gregorian_types.hpp + Single file header that defines most of the types for the gregorian + date-time system. +*/ + + +#include "boost/date_time/date.hpp" +#include "boost/date_time/period.hpp" +#include "boost/date_time/gregorian/greg_calendar.hpp" +#include "boost/date_time/gregorian/greg_duration.hpp" +#include "boost/date_time/gregorian/greg_date.hpp" +#include "boost/date_time/date_generators.hpp" +#include "boost/date_time/date_clock_device.hpp" +#include "boost/date_time/date_iterator.hpp" +#include "boost/date_time/adjust_functors.hpp" + +namespace boost { + +//! Gregorian date system based on date_time components +/*! This date system defines a full complement of types including + * a date, date_duration, date_period, day_clock, and a + * day_iterator. + */ +namespace gregorian { + //! Date periods for the gregorian system + /*!\ingroup date_basics + */ + typedef date_time::period date_period; + //! A date generation object type + typedef date_time::partial_date partial_date; + //! A clock to get the current day from the local computer + /*!\ingroup date_basics + */ + typedef date_time::day_clock day_clock; + + //! Base date_iterator type for gregorian types. + /*!\ingroup date_basics + */ + typedef date_time::date_itr_base date_iterator; + + //! A day level iterator + /*!\ingroup date_basics + */ + typedef date_time::date_itr, + date> day_iterator; + //! A week level iterator + /*!\ingroup date_basics + */ + typedef date_time::date_itr, + date> week_iterator; + //! A month level iterator + /*!\ingroup date_basics + */ + typedef date_time::date_itr, + date> month_iterator; +} } //namespace gregorian + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/gregorian/parsers.hpp b/include/boost/date_time/gregorian/parsers.hpp new file mode 100644 index 0000000..3850c3e --- /dev/null +++ b/include/boost/date_time/gregorian/parsers.hpp @@ -0,0 +1,62 @@ +#ifndef GREGORIAN_PARSERS_HPP___ +#define GREGORIAN_PARSERS_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/gregorian/gregorian_types.hpp" +#include "boost/date_time/date_parsing.hpp" + + +namespace boost { +namespace gregorian { + + //! From delimited date string where with order year-month-day eg: 2002-1-25 + inline date from_string(std::string s) { + return date_time::parse_date(s); + } + + //! From iso type date string where with order year-month-day eg: 20020125 + inline date from_undelimited_string(std::string s) { + return date_time::parse_undelimited_date(s); + } + +} } //namespace gregorian + + + + + + + + + + + + + + + + + + + + + + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/gregorian_calendar.hpp b/include/boost/date_time/gregorian_calendar.hpp new file mode 100644 index 0000000..b49f742 --- /dev/null +++ b/include/boost/date_time/gregorian_calendar.hpp @@ -0,0 +1,63 @@ +#ifndef DATE_TIME_GREGORIAN_CALENDAR_HPP__ +#define DATE_TIME_GREGORIAN_CALENDAR_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +namespace boost { +namespace date_time { + + + //! An implementation of the Gregorian calendar + template + class gregorian_calendar_base { + public: + //! define a type a date split into components + typedef ymd_type_ ymd_type; + //! define a type for representing months + typedef typename ymd_type::month_type month_type; + //! define a type for representing days + typedef typename ymd_type::day_type day_type; + //! Type to hold a stand alone year value (eg: 2002) + typedef typename ymd_type::year_type year_type; + //! Define the integer type to use for internal calculations + typedef date_int_type_ date_int_type; + + + static unsigned short day_of_week(const ymd_type& ymd); + //static unsigned short day_of_year(date_rep_type); + static date_int_type day_number(const ymd_type& ymd); + static ymd_type from_day_number(date_int_type); + static bool is_leap_year(year_type); + static unsigned short end_of_month_day(year_type y, month_type m); + static ymd_type epoch(); + static unsigned short days_in_week(); + + private: + }; + + + +} } //namespace + +#ifdef DATE_TIME_INLINE +#include "gregorian_calendar.ipp" +#endif + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif + diff --git a/include/boost/date_time/gregorian_calendar.ipp b/include/boost/date_time/gregorian_calendar.ipp new file mode 100644 index 0000000..2027c65 --- /dev/null +++ b/include/boost/date_time/gregorian_calendar.ipp @@ -0,0 +1,140 @@ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#ifdef DATE_TIME_INLINE + #undef DATE_TIME_INLINE + #define DATE_TIME_INLINE inline +#else + #define DATE_TIME_INLINE +#endif + +namespace boost { +namespace date_time { + //! Return the day of the week (0==Sunday, 1==Monday, etc) + /*! Converts a the ymd_type into a day of the week number + */ + template + DATE_TIME_INLINE + unsigned short + gregorian_calendar_base::day_of_week(const ymd_type& ymd) + { + unsigned short a = (14-ymd.month)/12; + unsigned short y = ymd.year - a; + unsigned short m = ymd.month + 12*a - 2; + unsigned short d = (ymd.day + y + (y/4) - (y/100) + (y/400) + (31*m)/12) % 7; + //std::cout << year << "-" << month << "-" << day << " is day: " << d << "\n"; + return d; + } + + //! Convert a ymd_type into a day number + /*! The day number is an absolute number of days since the start of count + */ + template + DATE_TIME_INLINE + date_int_type_ + gregorian_calendar_base::day_number(const ymd_type& ymd) + { + unsigned short a = (14-ymd.month)/12; + unsigned short y = ymd.year + 4800 - a; + unsigned short m = ymd.month + 12*a - 3; + unsigned long d = ymd.day + ((153*m + 2)/5) + 365*y + (y/4) - (y/100) + (y/400) - 32045; + return d; + } + + //! Change a day number into a ymd_type structure + /*! + * + */ + template + DATE_TIME_INLINE + ymd_type_ + gregorian_calendar_base::from_day_number(date_int_type dayNumber) + { + date_int_type a = dayNumber + 32044; + date_int_type b = (4*a + 3)/146097; + date_int_type c = a-((146097*b)/4); + date_int_type d = (4*c + 3)/1461; + date_int_type e = c - (1461*d)/4; + date_int_type m = (5*e + 2)/153; + unsigned short day = e - ((153*m + 2)/5) + 1; + unsigned short month = m + 3 - 12 * (m/10); + date_int_type year = 100*b + d - 4800 + (m/10); + //std::cout << year << "-" << month << "-" << day << "\n"; + + return ymd_type(year,month,day); + } + + + //! Determine if the provided year is a leap year + /*! + *@return true if year is a leap year, false otherwise + */ + template + DATE_TIME_INLINE + bool + gregorian_calendar_base::is_leap_year(year_type year) + { + //divisible by 4, not if divisible by 100, but true if divisible by 400 + return (!(year % 4)) && ((year % 100) || (!(year % 400))); + } + + //! Calculate the last day of the month + /*! Find the day which is the end of the month given year and month + * No error checking is performed. + */ + template + DATE_TIME_INLINE + unsigned short + gregorian_calendar_base::end_of_month_day(year_type year, + month_type month) + { + // switch (month.as_number()) { + switch (month) { + case 2: + if (is_leap_year(year)) {return 29;} + else {return 28;}; + case 4: + case 6: + case 9: + case 11: + return 30; + default: + return 31; + }; + + } + + //! Provide the ymd_type specification for the calandar start + template + DATE_TIME_INLINE + ymd_type_ + gregorian_calendar_base::epoch() + { + return ymd_type(1400,1,1); + } + + //! Defines length of a week for week calculations + template + DATE_TIME_INLINE + unsigned short + gregorian_calendar_base::days_in_week() + { + return 7; + } + + +} } //namespace gregorian + +/* Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ diff --git a/include/boost/date_time/int_adapter.hpp b/include/boost/date_time/int_adapter.hpp new file mode 100644 index 0000000..d75aa1c --- /dev/null +++ b/include/boost/date_time/int_adapter.hpp @@ -0,0 +1,212 @@ +#ifndef _DATE_TIME_INT_ADAPTER_HPP__ +#define _DATE_TIME_INT_ADAPTER_HPP__ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +#include "boost/limits.hpp" //work around compilers without limits +#include "boost/date_time/special_defs.hpp" + +namespace boost { +namespace date_time { + +//! Adapter to create integer types with +-infinity, and not a value +/*! This class is used internally in counted date/time representations. + * It adds the floating point like features of infinities and + * not a number. + */ + +template +class int_adapter { +public: + typedef int_type_ int_type; + int_adapter(int_type v) : + value_(v) + {} + static bool has_infinity() + { + return true; + } + static const int_adapter pos_infinity() + { + return ::std::numeric_limits::max(); + } + static const int_adapter neg_infinity() + { + return ::std::numeric_limits::min(); + } + static const int_adapter not_a_number() + { + return ::std::numeric_limits::max()-1; + } + static int_adapter max() + { + return ::std::numeric_limits::max()-2; + } + static int_adapter min() + { + return ::std::numeric_limits::min()+1; + } + static int_adapter from_special(special_values sv) + { + switch (sv) { + case not_a_date_time: return not_a_number(); + case neg_infin: return neg_infinity(); + case pos_infin: return pos_infinity(); + case max_date_time: return max(); + case min_date_time: return min(); + default: return not_a_number(); + } + + } + static bool is_inf(int_type v) + { + return (v == neg_infinity().as_number() || + v == pos_infinity().as_number()); + } + static bool is_neg_infinity(int_type v) + { + return (v == neg_infinity().as_number()); + } + static bool is_pos_infinity(int_type v) + { + return (v == pos_infinity().as_number()); + } + static bool is_not_a_number(int_type v) + { + return (v == not_a_number().as_number()); + } + //! Returns either special value type or is_not_special + static special_values to_special(int_type v) + { + if (is_not_a_number(v)) return not_a_date_time; + if (is_neg_infinity(v)) return neg_infin; + if (is_pos_infinity(v)) return pos_infin; + return not_special; + } + + + //-3 leaves room for representations of infinity and not a date + static int_type maxcount() + { + return ::std::numeric_limits::max()-3; + } + bool is_infinity() const + { + return (value_ == neg_infinity().as_number() || + value_ == pos_infinity().as_number()); + } + bool is_nan() const + { + return (value_ == not_a_number().as_number()); + } + bool operator==(const int_adapter& rhs) const + { + return value_ == rhs.value_; + } + bool operator!=(const int_adapter& rhs) const + { + return value_ != rhs.value_; + } + bool operator<(const int_adapter& rhs) const + { + return value_ < rhs.value_; + } + bool operator>(const int_adapter& rhs) const + { + return value_ > rhs.value_; + } + int_type as_number() const + { + return value_; + } + //! Returns either special value type or is_not_special + special_values as_special() const + { + return int_adapter::to_special(value_); + } + //creates nasty ambiguities +// operator int_type() const +// { +// return value_; +// } + int_adapter operator+(const int_adapter& rhs) const + { + if (is_nan() || rhs.is_nan()) { + return int_adapter(not_a_number()); + } + if (is_infinity()) { + return *this; + } + if (rhs.is_infinity()) { + return rhs; + } + return value_ + rhs.value_; + } + + int_adapter operator+(int_type rhs) const + { + if (is_nan()) { + return int_adapter(not_a_number()); + } + if (is_infinity()) { + return *this; + } + return value_ + rhs; + } + + int_adapter operator-(const int_adapter& rhs) const + { + if (is_nan() || rhs.is_nan()) { + return int_adapter(not_a_number()); + } + if (is_infinity()) { + return *this; + } + if (rhs.is_infinity()) { + return rhs; + } + return int_adapter(value_ - rhs.value_); + } + + int_adapter operator-(int_type rhs) const + { + if (is_nan()) { + return int_adapter(not_a_number()); + } + if (is_infinity()) { + return *this; + } + return int_adapter(value_ - rhs); + } + + + +private: + int_type value_; +}; + +} } //namespace date_time + +/* + * Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided as is without express or implied warranty. + * + * + * Author: Jeff Garland (jeff@CrystalClearSoftware.com) + * Created: Sat Sep 8 19:37:11 2001 + * + */ + + +#endif diff --git a/include/boost/date_time/iso_format.hpp b/include/boost/date_time/iso_format.hpp new file mode 100644 index 0000000..252a85b --- /dev/null +++ b/include/boost/date_time/iso_format.hpp @@ -0,0 +1,177 @@ +#ifndef ISO_FORMAT_HPP___ +#define ISO_FORMAT_HPP___ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/parse_format_base.hpp" + +namespace boost { +namespace date_time { + +//! Class to provide common iso formatting spec +class iso_format_base { +public: + //! Describe month format -- its an integer in iso format + static month_format_spec month_format() + { + return month_as_integer; + } + + //! String used printed is date is invalid + static const char* not_a_date() + { //20010102 + return "NotADate"; + } + //! String used to for positive infinity value + static const char* pos_infinity() + { + return "+infin "; + } + //! String used to for positive infinity value + static const char* neg_infinity() + { + return "-infin "; + } + + //! ISO char for a year -- used in durations + static char year_sep_char() + { + return 'Y'; + } + //! ISO char for a month + static char month_sep_char() + { + return '-'; + } + //! ISO char for a day + static char day_sep_char() + { + return '-'; + } + //! char for minute + static char hour_sep_char() + { + return ':'; + } + //! char for minute + static char minute_sep_char() + { + return ':'; + } + //! char for second + static char second_sep_char() + { + return ':'; + } + //! ISO char for a period + static char period_start_char() + { + return 'P'; + } + //! Used in time in mixed strings to set start of time + static char time_start_char() + { + return 'T'; + } + + //! Used in mixed strings to identify start of a week number + static char week_start_char() + { + return 'W'; + } + + //! Separators for periods + static char period_sep_char() + { + return '/'; + } + //! Separator for hh:mm:ss + static char time_sep_char() + { + return ':'; + } + //! Preferred Separator for hh:mm:ss,decimal_fraction + static char fractional_time_sep_char() + { + return ','; + } + + static bool is_component_sep(char sep) + { + switch(sep) { + case 'H': + case 'M': + case 'S': + case 'W': + case 'T': + case 'Y': + case 'D':return true; + default: + return false; + } + } + + static bool is_fractional_time_sep(char sep) + { + switch(sep) { + case ',': + case '.': return true; + default: return false; + } + } + static bool is_timezone_sep(char sep) + { + switch(sep) { + case '+': + case '-': return true; + default: return false; + } + } + static char element_sep_char() + { + return '-'; + } + +}; + + +//! Format description for iso normal YYYYMMDD +class iso_format : public iso_format_base { +public: + //! The ios standard format doesn't use char separators + static bool has_date_sep_chars() + { + return false; + } +}; + +//! Extended format uses seperators YYYY-MM-DD +class iso_extended_format : public iso_format_base { +public: + //! Extended format needs char separators + static bool has_date_sep_chars() + { + return true; + } + +}; + +} } //namespace date_time + +/* Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + + +#endif diff --git a/include/boost/date_time/local_time_adjustor.hpp b/include/boost/date_time/local_time_adjustor.hpp new file mode 100644 index 0000000..22f4c0a --- /dev/null +++ b/include/boost/date_time/local_time_adjustor.hpp @@ -0,0 +1,222 @@ + +#ifndef DATE_TIME_LOCAL_TIME_ADJUSTOR_HPP__ +#define DATE_TIME_LOCAL_TIME_ADJUSTOR_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! @file local_time_adjustor.hpp + Time adjustment calculations for local times +*/ + +#include "boost/date_time/date_generators.hpp" +#include "boost/date_time/dst_rules.hpp" +#include + +namespace boost { +namespace date_time { + + + //! Provides a base offset adjustment from utc + template + class utc_adjustment + { + public: + static time_duration_type local_to_utc_base_offset() + { + time_duration_type td(hours,minutes,0); + return td.invert_sign(); + } + static time_duration_type utc_to_local_base_offset() + { + return time_duration_type(hours,minutes,0); + } + }; + + + + //! Allow sliding utc adjustment with fixed dst rules + template + class dynamic_local_time_adjustor : public dst_rules + { + public: + typedef typename time_type::time_duration_type time_duration_type; + typedef typename time_type::date_type date_type; + + dynamic_local_time_adjustor(time_duration_type utc_offset) : + utc_offset_(utc_offset) + {} + + //! Presumes local time + time_duration_type utc_offset(bool is_dst) + { + if (is_dst) { + return utc_offset_ + dst_offset(); + } + else { + return utc_offset_; + } + + } + private: + time_duration_type utc_offset_; + + }; + + + + //! Embed the rules for local time adjustments at compile time + template + class static_local_time_adjustor: public dst_rules, public utc_offset_rules + { + public: + typedef typename time_type::time_duration_type time_duration_type; + typedef typename time_type::date_type date_type; + + //! Calculates the offset from a utc time to local based on dst and utc offset + /*! @param t UTC time to calculate offset to local time + * This adjustment depends on the following observations about the + * workings of the DST boundary offset. Since UTC time labels are + * monotonically increasing we can determine if a given local time + * is in DST or not and therefore adjust the offset appropriately. + * + * The logic is as follows. Starting with UTC time use the offset to + * create a label for an non-dst adjusted local time. Then call + * dst_rules::local_is_dst with the non adjust local time. The + * results of this function will either unabiguously decide that + * the initial local time is in dst or return an illegal or + * ambiguous result. An illegal result only occurs at the end + * of dst (where labels are skipped) and indicates that dst has + * ended. An ambiguous result means that we need to recheck by + * making a dst adjustment and then rechecking. If the dst offset + * is added to the utc time and the recheck proves non-ambiguous + * then we are past the boundary. If it is still ambiguous then + * we are ahead of the boundary and dst is still in effect. + * + * TODO -- check if all dst offsets are positive. If not then + * the algorithm needs to check for this and reverse the + * illegal/ambiguous logic. + */ + static time_duration_type utc_to_local_offset(const time_type& t) + { + //get initial local time guess by applying utc offset + time_type initial = t + utc_to_local_base_offset(); + time_is_dst_result dst_flag = + dst_rules::local_is_dst(initial.date(), initial.time_of_day()); + switch(dst_flag) { + case is_in_dst: return utc_to_local_base_offset() + dst_offset(); + case is_not_in_dst: return utc_to_local_base_offset(); + case invalid_time_label:return utc_to_local_base_offset() + dst_offset(); + case ambiguous: { + time_type retry = initial + dst_offset(); + dst_flag = dst_rules::local_is_dst(retry.date(), retry.time_of_day()); + //if still ambibuous then the utc time still translates to a dst time + if (dst_flag == ambiguous) { + return utc_to_local_base_offset() + dst_offset(); + } + // we are past the dst boundary + else { + return utc_to_local_base_offset(); + } + } + }//case + //TODO better excpetion type + throw std::out_of_range("Unreachable case"); + + } + + //! Get the offset to UTC given a local time + static time_duration_type local_to_utc_offset(const time_type& t, + date_time::dst_flags dst=date_time::calculate) + { + switch (dst) { + case is_dst: + return local_to_utc_base_offset() - dst_offset(); + case not_dst: + return local_to_utc_base_offset(); + case calculate: + time_is_dst_result res = + dst_rules::local_is_dst(t.date(), t.time_of_day()); + switch(res) { + case is_in_dst: return local_to_utc_base_offset() - dst_offset(); + case is_not_in_dst: return local_to_utc_base_offset(); + case ambiguous: return local_to_utc_base_offset(); + case invalid_time_label: throw std::out_of_range("Time label invalid"); + } + } + throw std::out_of_range("Time label invalid"); + } + + + private: + + }; + + void dummy_to_prevent_msvc6_ice(); //why ask why? + + //! Template that simplifies the creation of local time calculator + /*! Use this template to create the timezone to utc convertors as required. + * + * This class will also work for other regions that don't use dst and + * have a utc offset which is an integral number of hours. + * + * Template Parameters + * -time_type -- Time class to use + * -utc_offset -- Number hours local time is adjust from utc + * -use_dst -- true (default) if region uses dst, false otherwise + * For example: + * @code + * //eastern timezone is utc-5 + typedef date_time::us_local_adjustor us_eastern; + typedef date_time::us_local_adjustor us_central; + typedef date_time::us_local_adjustor us_mountain; + typedef date_time::us_local_adjustor us_pacific; + typedef date_time::us_local_adjustor us_arizona; + @endcode + + */ + template + class local_adjustor + { + public: + typedef typename time_type::time_duration_type time_duration_type; + typedef typename time_type::date_type date_type; + typedef static_local_time_adjustor > dst_adjustor; + //! Convert a utc time to local time + static time_type utc_to_local(const time_type& t) + { + time_duration_type td = dst_adjustor::utc_to_local_offset(t); + return t + td; + } + //! Convert a local time to utc + static time_type local_to_utc(const time_type& t, + date_time::dst_flags dst=date_time::calculate) + { + time_duration_type td = dst_adjustor::local_to_utc_offset(t, dst); + return t + td; + } + }; + + +} } //namespace date_time + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif diff --git a/include/boost/date_time/parse_format_base.hpp b/include/boost/date_time/parse_format_base.hpp new file mode 100644 index 0000000..f56d31d --- /dev/null +++ b/include/boost/date_time/parse_format_base.hpp @@ -0,0 +1,34 @@ + +#ifndef DATE_TIME_PARSE_FORMAT_BASE_HPP___ +#define DATE_TIME_PARSE_FORMAT_BASE_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +namespace boost { +namespace date_time { + + //! Enum for distinguishing parsing and formatting options + enum month_format_spec {month_as_integer, month_as_short_string, + month_as_long_string}; + + enum ymd_order_spec {ymd_order_iso, //order is year-month-day + ymd_order_dmy, //day-month-year + ymd_order_us}; //order is month-day-year + + +} }//namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif diff --git a/include/boost/date_time/period.hpp b/include/boost/date_time/period.hpp new file mode 100644 index 0000000..31a0b5a --- /dev/null +++ b/include/boost/date_time/period.hpp @@ -0,0 +1,253 @@ + +#ifndef PERIOD_HPP___ +#define PERIOD_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! \file period.hpp + This file contain the implementation of the period abstraction. This is + basically the same idea as a range. Although this class is intended for + use in the time library, it is pretty close to general enough for other + numeric uses. + +*/ + +#include "boost/operators.hpp" + + +namespace boost { +namespace date_time { + //!Provides generalized period type useful in date-time systems + /*!This template uses a class to represent a time point within the period + and another class to represent a duration. As a result, this class is + not appropriate for use when the number and duration representation + are the same (eg: in the regular number domain). + + A period can be specified by providing either the starting point and + a duration or the starting point and the last point. A period + will always have a duration of at least 1 and it's start will always + be before or eqaul to the last. + + In the case that the begin and last are the same, the period has a + length of one unit. For example, suppose this is a period of days. + That is, each "point" represents a single day. If the start and the + last is the same day then the period represents that single day for + a length of one. The same applies if each "point" represents a month + or a year. The way to think of this is that the granularity of the + point_rep class is similar to the ticks on a ruler. The more ticks, + the finer the resolution of a range that can be defined. A range + defined on a ruler with 1cm resolution between the 1cm mark and the + 2cm mark is 1cm long. In the ruler range, the 1cm mark is in the + range while the 2cm mark is not. + + While the ruler analogy useful, it is not how date ranges are naturally + thought about (at least by me). That is, it is more natural to think + of a date as including up to the end of the second time point. So when + I say day 1 to day 2 I usually mean from the beginning of day 1 to the + end of day 2. + + The best way to handle periods is usually to provide a start point and + a duration. So, day1 + 7 days is a week period which includes all of the + first day and 6 more days (eg: Sun to Sat). + + */ + template + class period + : boost::less_than_comparable + , boost::equality_comparable< period + > > + { + public: + period(point_rep begin, point_rep last); + period(point_rep begin, duration_rep len); + point_rep begin() const; + point_rep end() const; + point_rep last() const; + bool is_null() const; + bool operator==(const period& rhs) const; + bool operator<(const period& rhs) const; + void shift(const duration_rep& d); + bool contains(const point_rep& point) const; + bool contains(const period& other) const; + bool intersects(const period& other) const; + period intersection(const period& other) const; + period merge(const period& other) const; + private: + point_rep begin_; + point_rep last_; + }; + + //! create a period from begin to last eg: [begin,end) + /*! If last <= begin then the period will is defined as null + */ + template + inline + period::period(point_rep begin, + point_rep end) : + begin_(begin), + last_(end - duration_rep::unit()) + {} + + //! create a period as [begin, begin+len) + /*! If len is <= 0 then the period will be defined as null + */ + template + inline + period::period(point_rep begin, duration_rep len) : + begin_(begin), + last_(begin + len-duration_rep::unit()) + {} + + + //! Return the first element in the period + template + inline + point_rep period::begin() const + { + return begin_; + } + + //! Return one past the last element + template + inline + point_rep period::end() const + { + return last_ + duration_rep::unit(); + } + + //! Return the last item in the period + template + inline + point_rep period::last() const + { + return last_; + } + + //! True if period is ill formed + template + inline + bool period::is_null() const + { + return last_ <= begin_; + } + + //! Equality operator + template + inline + bool period::operator==(const period& rhs) const + { + return ((begin_ == rhs.begin_) && + (last_ == rhs.last_)); + } + + //! Strict as defined by rhs.last <= lhs.last + template + inline + bool period::operator<(const period& rhs) const + { + return (last_ <= rhs.begin_); + } + + + //! Shift the start and end by the specified amount + template + inline + void period::shift(const duration_rep& d) + { + begin_ = begin_ + d; + last_ = last_ + d; + } + + //! True if the point is inside the period + template + inline + bool period::contains(const point_rep& point) const + { + return ((point >= begin_) && + (point <= last_)); + } + + + //! True if this period fully contains (or equals) the other period + template + inline + bool period::contains(const period& other) const + { + return ((begin_ <= other.begin_) && (last_ >= other.last_)); + } + + + //! True if the periods overlap in any way + template + inline + bool period::intersects(const period& other) const + { + return ( contains(other.begin_) || + other.contains(begin_) || + ((other.begin_ < begin_) && (other.last_ >= begin_)));// || + // ((begin_ < other.begin_) && (last_ <= other.last_))); + + } + + //! Returns the period of intersection or invalid range no intersection + template + inline + period + period::intersection(const period& other) const + { + if (begin_ > other.begin_) { + if (last_ <= other.last_) { //case2 + return *this; + } + //case 1 + return period(begin_, other.end()); + + } + else { + if (last_ <= other.last_) { //case3 + return period(other.begin_, this->end()); + } + //case4 + return other; + } + //unreachable + } + + //! Returns the union of intersecting periods -- or null period + /*! + */ + template + inline + period + period::merge(const period& other) const + { + if (this->intersects(other)) { + if (begin_ < other.begin_) { + return period(begin_, last_ > other.last_ ? this->end() : other.end()); + } + + return period(other.begin_, last_ > other.last_ ? this->end() : other.end()); + + } + return period(begin_,begin_); // no intersect return null + } + + +} } //namespace date_time + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/posix_time/posix_time.hpp b/include/boost/date_time/posix_time/posix_time.hpp new file mode 100644 index 0000000..c4e014e --- /dev/null +++ b/include/boost/date_time/posix_time/posix_time.hpp @@ -0,0 +1,30 @@ +#ifndef POSIX_TIME_HPP___ +#define POSIX_TIME_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ +//!@file Global header file to get all of posix time types + +#include "boost/date_time/posix_time/ptime.hpp" +#include "boost/date_time/posix_time/time_formatters.hpp" +#include "boost/date_time/posix_time/time_parsers.hpp" + + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + diff --git a/include/boost/date_time/posix_time/posix_time_config.hpp b/include/boost/date_time/posix_time/posix_time_config.hpp new file mode 100644 index 0000000..f5ce073 --- /dev/null +++ b/include/boost/date_time/posix_time/posix_time_config.hpp @@ -0,0 +1,146 @@ +#ifndef POSIX_TIME_CONFIG_HPP___ +#define POSIX_TIME_CONFIG_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/time_duration.hpp" +#include "boost/date_time/time_resolution_traits.hpp" +#include "boost/date_time/gregorian/gregorian_types.hpp" +#include "boost/date_time/wrapping_int.hpp" +#include "boost/limits.hpp" +//force the definition of INT64_C macro used in posix_time_system +#ifndef __STDC_CONSTANT_MACROS +#define __STDC_CONSTANT_MACROS +# if __GNUC__ >= 2 +# undef BOOST_HAS_STDINT_H +# endif +#endif +#include "boost/cstdint.hpp" +#include +#include //for MCW 7.2 std::abs(long long) + +namespace boost { +namespace posix_time { + +//Remove the following line if you want 64 bit millisecond resolution time +//#define BOOST_GDTL_POSIX_TIME_STD_CONFIG + +#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG + // set up conditional test compilations +#define BOOST_DATE_TIME_HAS_MILLISECONDS +#define BOOST_DATE_TIME_HAS_MICROSECONDS +#define BOOST_DATE_TIME_HAS_NANOSECONDS + typedef date_time::time_resolution_traits time_res_traits; +#else + // set up conditional test compilations +#define BOOST_DATE_TIME_HAS_MILLISECONDS +#define BOOST_DATE_TIME_HAS_MICROSECONDS +#undef BOOST_DATE_TIME_HAS_NANOSECONDS + typedef date_time::time_resolution_traits time_res_traits; + + +// #undef BOOST_GDTL_HAS_MILLISECONDS +// #undef BOOST_GDTL_HAS_MICROSECONDS +// #undef BOOST_GDTL_HAS_NANOSECONDS +// typedef date_time::time_resolution_traits time_res_traits; + +#endif + + + //! Base time duration type + /*! \ingroup time_basics + */ + class time_duration : + public date_time::time_duration + { + public: + typedef time_res_traits rep_type; + typedef time_res_traits::day_type day_type; + typedef time_res_traits::hour_type hour_type; + typedef time_res_traits::min_type min_type; + typedef time_res_traits::sec_type sec_type; + typedef time_res_traits::fractional_seconds_type fractional_seconds_type; + typedef time_res_traits::tick_type tick_type; + time_duration(hour_type hour, + min_type min, + sec_type sec, + fractional_seconds_type fs=0) : + date_time::time_duration(hour,min,sec,fs) + {} + time_duration() : + date_time::time_duration(0,0,0) + {} + //Give duration access to ticks constructor -- hide from users + friend class date_time::time_duration; + private: + explicit time_duration(tick_type ticks) : + date_time::time_duration(ticks) + {} + }; + +#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG + + //! Simple implementation for the time rep + struct simple_time_rep + { + typedef gregorian::date date_type; + typedef time_duration time_duration_type; + simple_time_rep(date_type d, time_duration_type tod) : + day(d), + time_of_day(tod) + {} + date_type day; + time_duration_type time_of_day; + }; + + class posix_time_system_config + { + public: + typedef simple_time_rep time_rep_type; + typedef gregorian::date date_type; + typedef gregorian::date_duration date_duration_type; + typedef time_duration time_duration_type; + typedef time_res_traits::tick_type int_type; + typedef time_res_traits resolution_traits; + static const boost::int64_t tick_per_second = 1000000000; + }; + +#else + + class millisec_posix_time_system_config + { + public: + typedef boost::int64_t time_rep_type; + typedef gregorian::date date_type; + typedef gregorian::date_duration date_duration_type; + typedef time_duration time_duration_type; + typedef time_res_traits::tick_type int_type; + typedef time_res_traits resolution_traits; + static const boost::int64_t tick_per_second = 1000000; + }; + +#endif + +} }//namespace posix_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + + diff --git a/include/boost/date_time/posix_time/posix_time_duration.hpp b/include/boost/date_time/posix_time/posix_time_duration.hpp new file mode 100644 index 0000000..084db48 --- /dev/null +++ b/include/boost/date_time/posix_time/posix_time_duration.hpp @@ -0,0 +1,100 @@ +#ifndef POSIX_TIME_DURATION_HPP___ +#define POSIX_TIME_DURATION_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/posix_time/posix_time_config.hpp" + +namespace boost { +namespace posix_time { + + //! Allows expression of durations as an hour count + /*! \ingroup time_basics + */ + class hours : public time_duration + { + public: + explicit hours(long h) : + time_duration(h,0,0) + {} + }; + + //! Allows expression of durations as a minute count + /*! \ingroup time_basics + */ + class minutes : public time_duration + { + public: + explicit minutes(long m) : + time_duration(0,m,0) + {} + }; + + //! Allows expression of durations as a seconds count + /*! \ingroup time_basics + */ + class seconds : public time_duration + { + public: + explicit seconds(long s) : + time_duration(0,0,s) + {} + }; + + + +#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) + + //! Allows expression of durations as milli seconds + /*! \ingroup time_basics + */ + typedef date_time::subsecond_duration millisec; + + //! Allows expression of durations as micro seconds + /*! \ingroup time_basics + */ + typedef date_time::subsecond_duration microsec; + + //! Allows expression of durations as nano seconds + /*! \ingroup time_basics + */ + typedef date_time::subsecond_duration nanosec; + + +#endif + +#if defined(BOOST_DATE_TIME_HAS_MICROSECONDS) && (!defined(BOOST_GDTL_HAS_NANOSECONDS)) + + //! Allows expression of durations as milli seconds + /*! \ingroup time_basics + */ + typedef date_time::subsecond_duration millisec; + + //! Allows expression of durations as micro seconds + /*! \ingroup time_basics + */ + typedef date_time::subsecond_duration microsec; + +#endif + + + +} }//namespace posix_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + diff --git a/include/boost/date_time/posix_time/posix_time_system.hpp b/include/boost/date_time/posix_time/posix_time_system.hpp new file mode 100644 index 0000000..0359968 --- /dev/null +++ b/include/boost/date_time/posix_time/posix_time_system.hpp @@ -0,0 +1,72 @@ + + +#ifndef POSIX_TIME_SYSTEM_HPP___ +#define POSIX_TIME_SYSTEM_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/posix_time/posix_time_config.hpp" +#include "boost/date_time/time_system_split.hpp" +#include "boost/date_time/time_system_counted.hpp" + + +namespace boost { +namespace posix_time { + +#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG + + typedef date_time::split_timedate_system posix_time_system; + +#else + + typedef date_time::counted_time_rep int64_time_rep; + typedef date_time::counted_time_system posix_time_system; + +#endif + +} }//namespace posix_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/include/boost/date_time/posix_time/posix_time_types.hpp b/include/boost/date_time/posix_time/posix_time_types.hpp new file mode 100644 index 0000000..46099ba --- /dev/null +++ b/include/boost/date_time/posix_time/posix_time_types.hpp @@ -0,0 +1,56 @@ +#ifndef POSIX_TIME_TYPES_HPP___ +#define POSIX_TIME_TYPES_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/time_clock.hpp" +//#include "date_time/high_precision_clock.hpp" +#include "boost/date_time/posix_time/ptime.hpp" +#include "boost/date_time/posix_time/posix_time_duration.hpp" +#include "boost/date_time/posix_time/posix_time_system.hpp" +#include "boost/date_time/posix_time/time_period.hpp" +#include "boost/date_time/time_iterator.hpp" +#include "boost/date_time/dst_rules.hpp" + +namespace boost { + +//!Defines a non-adjusted time system with nano-second resolution and stable calculation properties +namespace posix_time { + + //! Iterator over a defined time duration + /*! \ingroup time_basics + */ + typedef date_time::time_itr time_iterator; + //! A time clock that has a resolution of one second + /*! \ingroup time_basics + */ + typedef date_time::second_clock second_clock; + // typedef date_time::high_precision_clock high_precision_clock; + + //! Define a dst null dst rule for the posix_time system + typedef date_time::null_dst_rules no_dst; + //! Define US dst rule calculator for the posix_time system + typedef date_time::us_dst_rules us_dst; + + +} } //namespace posix_time + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + diff --git a/include/boost/date_time/posix_time/ptime.hpp b/include/boost/date_time/posix_time/ptime.hpp new file mode 100644 index 0000000..f7a5e16 --- /dev/null +++ b/include/boost/date_time/posix_time/ptime.hpp @@ -0,0 +1,55 @@ +#ifndef POSIX_PTIME_HPP___ +#define POSIX_PTIME_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/posix_time/posix_time_system.hpp" +#include "boost/date_time/time.hpp" + +namespace boost { + +namespace posix_time { + + //! Time type with no timezone or other adjustments + /*! \ingroup time_basics + */ + class ptime : public date_time::base_time + { + public: + typedef posix_time_system time_system_type; + typedef time_system_type::time_rep_type time_rep_type; + typedef time_system_type::time_duration_type time_duration_type; + typedef ptime time_type; + //! Construct with date and offset in day + ptime(gregorian::date d,time_duration_type td) : date_time::base_time(d,td) + {} + //! Construct a time at start of the given day (midnight) + explicit ptime(gregorian::date d) : date_time::base_time(d,time_duration_type(0,0,0)) + {} + //! Copy from time_rep + ptime(const time_rep_type& rhs): + date_time::base_time(rhs) + {} + }; + + + +} }//namespace posix_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + diff --git a/include/boost/date_time/posix_time/time_formatters.hpp b/include/boost/date_time/posix_time/time_formatters.hpp new file mode 100644 index 0000000..6697ceb --- /dev/null +++ b/include/boost/date_time/posix_time/time_formatters.hpp @@ -0,0 +1,129 @@ +#ifndef POSIXTIME_FORMATTERS_HPP___ +#define POSIXTIME_FORMATTERS_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/iso_format.hpp" +#include "boost/date_time/date_format_simple.hpp" +#include "boost/date_time/posix_time/posix_time_types.hpp" + + +namespace boost { + +namespace posix_time { + + //! Time duration to string hh::mm::ss.fffffff. Example: 10:09:03.0123456 + /*!\ingroup time_format + */ + inline std::string to_simple_string(time_duration td) { + std::ostringstream ss; + ss << std::setw(2) << std::setfill('0') << td.hours() << ":"; + ss << std::setw(2) << std::setfill('0') << td.minutes() << ":"; + ss << std::setw(2) << std::setfill('0') << td.seconds(); + //TODO the following is totally non-generic, yelling FIXME +#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 + boost::int64_t frac_sec = td.fractional_seconds(); +// JDG [7/6/02 VC++ compatibility] + char buff[32]; + _i64toa(frac_sec, buff, 10); +#else + time_duration::fractional_seconds_type frac_sec = td.fractional_seconds(); +#endif + if (frac_sec != 0) { + ss << "." << std::setw(time_duration::num_fractional_digits()) + << std::setfill('0') + +// JDG [7/6/02 VC++ compatibility] +#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 + << buff; +#else + << frac_sec; +#endif + } + return ss.str(); + } + + //! Time duration in iso format hhmmss,fffffff Example: 10:09:03,0123456 + /*!\ingroup time_format + */ + inline std::string to_iso_string(time_duration td) { + std::ostringstream ss; + ss << std::setw(2) << std::setfill('0') << td.hours(); + ss << std::setw(2) << std::setfill('0') << td.minutes(); + ss << std::setw(2) << std::setfill('0') << td.seconds(); + //TODO the following is totally non-generic, yelling FIXME +#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 + boost::int64_t frac_sec = td.fractional_seconds(); + // JDG [7/6/02 VC++ compatibility] + char buff[32]; + _i64toa(frac_sec, buff, 10); +#else + time_duration::fractional_seconds_type frac_sec = td.fractional_seconds(); +#endif + if (frac_sec != 0) { + ss << "." << std::setw(time_duration::num_fractional_digits()) + << std::setfill('0') + +// JDG [7/6/02 VC++ compatibility] +#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 + << buff; +#else + << frac_sec; +#endif + } + return ss.str(); + } + + //! Time to simple format CCYY-mmm-dd hh:mm:ss.fffffff + /*!\ingroup time_format + */ + inline std::string to_simple_string(ptime t) { + std::string ts = gregorian::to_simple_string(t.date()) + " "; + return ts + to_simple_string(t.time_of_day()); + } + + //! Convert to string of form [YYYY-mmm-DD HH:MM::SS.ffffff/YYYY-mmm-DD HH:MM::SS.fffffff] + /*!\ingroup time_format + */ + inline std::string to_simple_string(time_period tp) { + std::string d1(to_simple_string(tp.begin())); + std::string d2(to_simple_string(tp.last())); + return std::string("[" + d1 + "/" + d2 +"]"); + } + + //! Convert iso short form YYYYMMDDTHHMMSS where T is the date-time separator + /*!\ingroup time_format + */ + inline std::string to_iso_string(ptime t) { + std::string ts = gregorian::to_iso_string(t.date()) + "T"; + return ts + to_iso_string(t.time_of_day()); + } + + //! Convert to form YYYY-MM-DDTHH:MM:SS where T is the date-time separator + /*!\ingroup time_format + */ + inline std::string to_iso_extended_string(ptime t) { + std::string ts = gregorian::to_iso_extended_string(t.date()) + "T"; + return ts + to_simple_string(t.time_of_day()); + } + + +} } //namespace posix_time + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/posix_time/time_parsers.hpp b/include/boost/date_time/posix_time/time_parsers.hpp new file mode 100644 index 0000000..8dbc42e --- /dev/null +++ b/include/boost/date_time/posix_time/time_parsers.hpp @@ -0,0 +1,42 @@ +#ifndef POSIXTIME_PARSERS_HPP___ +#define POSIXTIME_PARSERS_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/time_parsing.hpp" +#include "boost/date_time/posix_time/posix_time_types.hpp" + + +namespace boost { + +namespace posix_time { + + inline time_duration duration_from_string(const std::string& s) { + return date_time::parse_delimited_time_duration(s); + } + + inline ptime time_from_string(const std::string& s) { + return date_time::parse_delimited_time(s, ' '); + } + + + +} } //namespace posix_time + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ +#endif + diff --git a/include/boost/date_time/posix_time/time_period.hpp b/include/boost/date_time/posix_time/time_period.hpp new file mode 100644 index 0000000..db0e107 --- /dev/null +++ b/include/boost/date_time/posix_time/time_period.hpp @@ -0,0 +1,37 @@ +#ifndef POSIX_TIME_PERIOD_HPP___ +#define POSIX_TIME_PERIOD_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/date_time/period.hpp" +#include "boost/date_time/posix_time/posix_time_duration.hpp" +#include "boost/date_time/posix_time/ptime.hpp" + +namespace boost { +namespace posix_time { + + //! Time period type + /*! \ingroup time_basics + */ + typedef date_time::period time_period; + + +} }//namespace posix_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif + diff --git a/include/boost/date_time/special_defs.hpp b/include/boost/date_time/special_defs.hpp new file mode 100644 index 0000000..3dac27d --- /dev/null +++ b/include/boost/date_time/special_defs.hpp @@ -0,0 +1,32 @@ +#ifndef DATE_TIME_SPECIAL_DEFS_HPP__ +#define DATE_TIME_SPECIAL_DEFS_HPP__ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +namespace boost { +namespace date_time { + + enum special_values {not_a_date_time, + neg_infin, pos_infin, + min_date_time, max_date_time, + not_special}; + + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif + diff --git a/include/boost/date_time/testfrmwk.hpp b/include/boost/date_time/testfrmwk.hpp new file mode 100644 index 0000000..de2505b --- /dev/null +++ b/include/boost/date_time/testfrmwk.hpp @@ -0,0 +1,74 @@ + +#ifndef TEST_FRMWK_HPP___ +#define TEST_FRMWK_HPP___ +/* + * Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * + * Author: Jeff Garland + */ + + +#include +#include + +//! Really simple test framework for counting and printing +class TestStats +{ +public: + static TestStats& instance() {static TestStats ts; return ts;} + void addPassingTest() {testcount_++; passcount_++;} + void addFailingTest() {testcount_++;} + unsigned int testcount() const {return testcount_;} + unsigned int passcount() const {return passcount_;} + void print(std::ostream& out = std::cout) const + { + out << testcount_ << " Tests Executed: " ; + if (passcount() != testcount()) { + out << (testcount() - passcount()) << " FAILURES"; + } + else { + out << "All Succeeded" << std::endl; + } + out << std::endl; + } +private: + TestStats() : testcount_(0), passcount_(0) {} + unsigned int testcount_; + unsigned int passcount_; +}; + + +bool check(const std::string& testname, bool testcond) +{ + TestStats& stat = TestStats::instance(); + if (testcond) { + std::cout << "Pass :: " << testname << " " << std::endl; + stat.addPassingTest(); + return true; + } + else { + stat.addFailingTest(); + std::cout << "FAIL :: " << testname << " " << std::endl; + return false; + } +}; + + +int printTestStats() +{ + TestStats& stat = TestStats::instance(); + stat.print(); + return stat.testcount() - stat.passcount(); +}; + +#endif diff --git a/include/boost/date_time/time.hpp b/include/boost/date_time/time.hpp new file mode 100644 index 0000000..a0fc422 --- /dev/null +++ b/include/boost/date_time/time.hpp @@ -0,0 +1,156 @@ + +#ifndef DATE_TIME_TIME_HPP___ +#define DATE_TIME_TIME_HPP___ +/* Copyright (c) 2000, 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! @file time.hpp + This file contains the interface for the time associated classes. +*/ +#include "boost/date_time/time_defs.hpp" +#include "boost/operators.hpp" +#include + +namespace boost { +namespace date_time { + + //! Representation of a precise moment in time, including the date. + /*! + This class is a skeleton for the interface of a temporal type + with a resolution is higher than a day. It is intended that + this class be the base class and that the actual time + class be derived using the BN pattern. In this way, the derived + class can make decisions such as 'should there be a default constructor' + and what should it set its value to, should there be optional constructors + say allowing only an time_durations that generate a time from a clock,etc. + So, in fact multiple time types can be created for a time_system with + different construction policies, and all of them can perform basic + operations by only writing a copy constructor. Finally, compiler + errors are also shorter. + + The real behavior of the time class is provided by the time_system + template parameter. This class must provide all the logic + for addition, subtraction, as well as define all the interface + types. + + */ + + template + class base_time + : boost::less_than_comparable > + { + public: + typedef T time_type; + typedef typename time_system::time_rep_type time_rep_type; + typedef typename time_system::date_type date_type; + typedef typename time_system::date_duration_type date_duration_type; + typedef typename time_system::time_duration_type time_duration_type; + //typedef typename time_system::hms_type hms_type; + + base_time(const date_type& day, + const time_duration_type& td, + dst_flags dst=not_dst) : + time_(time_system::get_time_rep(day, td, dst)) + {} + base_time(const time_rep_type& rhs) : + time_(rhs) + {} + date_type date() const + { + return time_system::get_date(time_); + } + time_duration_type time_of_day() const + { + return time_system::get_time_of_day(time_); + } + std::string zone_name() const + { + return time_system::zone_name(time_); + } + //TODO add these special functions +// //! check to see if date is not a value +// bool is_not_a_date() const +// { +// return traits_type::is_not_a_number(days_); +// } +// //! check to see if date is one of the infinity values +// bool is_infinity() const +// { +// return traits_type::is_infinity(days_); +// } + +// //! check to see if date is greater than all possible dates +// bool is_pos_infinity() const +// { +// return traits_type::is_pos_infinity(days_); +// } +// //! check to see if date is greater than all possible dates +// bool is_neg_infinity() const +// { +// return traits_type::is_neg_infinity(days_); +// } + + //!Equality operator -- others generated by boost::equality_comparable + bool operator==(const time_type& rhs) const + { + return time_system::is_equal(time_,rhs.time_); + } + //!Equality operator -- others generated by boost::less_than_comparable + bool operator<(const time_type& rhs) const + { + return time_system::is_less(time_,rhs.time_); + } + //! add date durations + time_type operator+(const date_duration_type& dd) const + { + return time_system::add_days(time_, dd); + } + //! subtract date durations + time_type operator-(const date_duration_type& dd) const + { + return time_system::subtract_days(time_, dd); + } + //! subtract time durations + time_type operator-(const time_duration_type& rhs) const + { + return time_system::subtract_time_duration(time_, rhs); + } + //! difference between to times + time_duration_type operator-(const time_type& rhs) const + { + return time_system::subtract_times(time_, rhs.time_); + } + //! add time durations + time_type operator+(const time_duration_type& td) const + { + return time_type(time_system::add_time_duration(time_, td)); + } + + protected: + time_rep_type time_; + }; + + + + + +} } //namespace date_time::boost + +/* Copyright (c) 2000,2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif diff --git a/include/boost/date_time/time_clock.hpp b/include/boost/date_time/time_clock.hpp new file mode 100644 index 0000000..9cc0504 --- /dev/null +++ b/include/boost/date_time/time_clock.hpp @@ -0,0 +1,76 @@ + +#ifndef DATE_TIME_TIME_CLOCK_HPP___ +#define DATE_TIME_TIME_CLOCK_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +/*! @file time_clock.hpp + This file contains the interface for clock devices. +*/ + +#include "boost/date_time/c_time.hpp" + +namespace boost { +namespace date_time { + + + //! A clock providing time level services based on C time_t capabilities + /*! This clock provides resolution to the 1 second level + */ + template + class second_clock + { + public: + // typedef typename time_type::date_type date_type; + typedef typename time_type::time_duration_type time_duration_type; + + static time_type local_time() + { + ::std::time_t t; + ::std::time(&t); + ::std::tm* curr = ::std::localtime(&t); + return create_time(curr); + } + + //! Get the current day in universal date as a ymd_type + static time_type universal_time() + { + + ::std::time_t t; + ::std::time(&t); + ::std::tm* curr= ::std::gmtime(&t); + return create_time(curr); + } + + private: + static time_type create_time(::std::tm* current) + { + date_type d(current->tm_year + 1900, + current->tm_mon + 1, + current->tm_mday); + time_duration_type td(current->tm_hour, + current->tm_min, + current->tm_sec); + return time_type(d,td); + } + + }; + + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/time_defs.hpp b/include/boost/date_time/time_defs.hpp new file mode 100644 index 0000000..dce0b3b --- /dev/null +++ b/include/boost/date_time/time_defs.hpp @@ -0,0 +1,49 @@ + +#ifndef DATE_TIME_TIME_PRECISION_LIMITS_HPP +#define DATE_TIME_TIME_PRECISION_LIMITS_HPP + +/* Copyright (c) 2000, 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +/*! \file time_defs.hpp + This file contains nice definitions for handling the resoluion of various time + reprsentations. +*/ + +namespace boost { +namespace date_time { + + //!Defines some nice types for handling time level resolutions + enum time_resolutions {sec, tenth, hundreth, milli, micro, nano, NumResolutions }; + + //! Flags for daylight savings or summer time + enum dst_flags {not_dst, is_dst, calculate}; + + + //Todo move resolution strings + //!A resolution adjustment table which corresponds to the name table + // static const unsigned long resolution_adjust[NumResolutions] = {1,10,100,1000,1000000,1000000000 }; + //!Some strings for the various resolutions + //const char* const resolution_names[NumResolutions] = {"Second", "Tenth", "Hundreth", "Milli", "Micro", "Nano"}; + + +} } //namespace date_time + +/* Copyright (c) 2000,2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + + +#endif diff --git a/include/boost/date_time/time_duration.hpp b/include/boost/date_time/time_duration.hpp new file mode 100644 index 0000000..f01aebf --- /dev/null +++ b/include/boost/date_time/time_duration.hpp @@ -0,0 +1,151 @@ +#ifndef DATE_TIME_TIME_DURATION_HPP___ +#define DATE_TIME_TIME_DURATION_HPP___ +/* Copyright (c) 2000 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/operators.hpp" +#include "boost/date_time/time_defs.hpp" + +//Work around compilers that don't have std::abs +#if (__GNUC__ <= 3)|| (defined(BOOST_MSVC) && _MSC_VER <= 1200) +# define BOOST_NO_LONG_LONG_ABS +#endif + +#if defined(BOOST_NO_LONG_LONG_ABS) +namespace std +{ + template // JDG [7/6/02 made a template] + inline T abs(T x) + { + return x < 0 ? -x : x; + } +} +#endif + + +namespace boost { +namespace date_time { + + //! Represents some amount of elapsed time measure to a given resolution + /*! + + */ + template + class time_duration + : boost::less_than_comparable > + { + public: + typedef T duration_type; //the subclass + typedef typename rep_type::day_type day_type; + typedef typename rep_type::hour_type hour_type; + typedef typename rep_type::min_type min_type; + typedef typename rep_type::sec_type sec_type; + typedef typename rep_type::fractional_seconds_type fractional_seconds_type; + typedef typename rep_type::tick_type tick_type; + + time_duration() : ticks_(0) {} + time_duration(hour_type hours, + min_type minutes, + sec_type seconds=0, + fractional_seconds_type frac_sec = 0) : + ticks_(rep_type::to_tick_count(hours,minutes,seconds,frac_sec)) + {} + + //! Returns smallest representable duration + static duration_type unit() + { + return duration_type(0,0,0,1); + } + static time_resolutions resolution() + { + return rep_type::resolution(); + } + //! Returns number of hours in the duration + hour_type hours() const + { + return (ticks_ / (3600*rep_type::res_adjust())); + } + //! Returns normalized number of minutes + min_type minutes() const + { + return std::abs(((ticks() / (60*rep_type::res_adjust())) % 60)); + } + //! Returns normalized number of seconds + sec_type seconds() const + { + return std::abs((ticks()/rep_type::res_adjust()) % 60); + } + //! Returns count of fractional seconds at given resolution + fractional_seconds_type fractional_seconds() const + { + return std::abs((ticks()%rep_type::res_adjust())); + } + //! Returns number of possible digits in fractional seconds + static unsigned short num_fractional_digits() + { + return rep_type::num_fractional_digits(); + } + duration_type invert_sign() const + { + return duration_type(-ticks_); + } + bool is_negative() const + { + return ticks_ < 0; + } + bool operator<(const time_duration& rhs) const + { + return ticks_ < rhs.ticks_; + } + bool operator==(const time_duration& rhs) const + { + return ticks_ == rhs.ticks_; + } + duration_type operator-(const duration_type& d) const + { + return duration_type(ticks_ - d.ticks_); + } + duration_type operator+(const duration_type& d) const + { + return duration_type(ticks_ + d.ticks_); + } + tick_type ticks() const { return ticks_;}; + + protected: + explicit time_duration(tick_type in) : ticks_(in) {}; + tick_type ticks_; + }; + + //! Template for instantiating derived adjusting durations + template + class subsecond_duration : public base_duration + { + public: + explicit subsecond_duration(long ss) : + base_duration(0,0,0,ss*adjustment) + {} + }; + + + +} } //namespace date_time + + +/* Copyright (c) 2000 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + + +#endif diff --git a/include/boost/date_time/time_iterator.hpp b/include/boost/date_time/time_iterator.hpp new file mode 100644 index 0000000..8d35129 --- /dev/null +++ b/include/boost/date_time/time_iterator.hpp @@ -0,0 +1,54 @@ +#ifndef DATE_TIME_TIME_ITERATOR_HPP___ +#define DATE_TIME_TIME_ITERATOR_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +namespace boost { +namespace date_time { + + + //! Simple time iterator skeleton class + template + class time_itr { + public: + typedef typename time_type::time_duration_type time_duration_type; + time_itr(time_type t, time_duration_type d) : current_(t), offset_(d) {}; + time_itr& operator++() + { + current_ = current_ + offset_; + return *this; + }; + time_type operator*() {return current_;}; + time_type* operator->() {return ¤t_;}; + bool operator< (const time_type& t) {return current_ < t;}; + bool operator<= (const time_type& t) {return current_ <= t;}; + bool operator!= (const time_type& t) {return current_ != t;}; + bool operator== (const time_type& t) {return current_ == t;}; + bool operator> (const time_type& t) {return current_ > t;}; + bool operator>= (const time_type& t) {return current_ >= t;}; + + private: + time_type current_; + time_duration_type offset_; + }; + + + +} }//namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/time_parsing.hpp b/include/boost/date_time/time_parsing.hpp new file mode 100644 index 0000000..fc9d403 --- /dev/null +++ b/include/boost/date_time/time_parsing.hpp @@ -0,0 +1,109 @@ + +#ifndef _DATE_TIME_TIME_PARSING_HPP___ +#define _DATE_TIME_TIME_PARSING_HPP___ +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include "boost/tokenizer.hpp" +#include "boost/lexical_cast.hpp" +#include "boost/date_time/date_parsing.hpp" +#include "boost/cstdint.hpp" + + +namespace boost { +namespace date_time { + + + template + inline + time_duration + parse_delimited_time_duration(const std::string& s) + { + unsigned short hour=0, min=0, sec =0; + boost::int64_t fs=0; + int pos = 0; + boost::tokenizer > tok(s); + for(boost::tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ + switch(pos) { + case 0: { + hour = boost::lexical_cast(*beg); + break; + } + case 1: { + min = boost::lexical_cast(*beg); + break; + } + case 2: { + sec = boost::lexical_cast(*beg); + break; + }; + case 3: { + //Works around a bug in MSVC 6 library that does not support + //operator>> thus meaning lexical_cast will fail to compile. +#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 + fs = _atoi64(beg->c_str()); +#else + fs = boost::lexical_cast(*beg); +#endif + break; + } + }//switch + pos++; + } + return time_duration(hour, min, sec, fs); + } + + //TODO this could use some error checking! + inline + bool + split(const std::string& s, + char sep, + std::string& first, + std::string& second) + { + int sep_pos = s.find(sep); + first = s.substr(0,sep_pos); + second = s.substr(sep_pos+1); + return true; + } + + template + inline + time_type + parse_delimited_time(const std::string& s, char sep) + { + typedef typename time_type::time_duration_type time_duration; + typedef typename time_type::date_type date_type; + + //split date/time on a unique delimiter char such as ' ' or 'T' + std::string date_string, tod_string; + split(s, sep, date_string, tod_string); + //call parse_date with first string + date_type d = parse_date(date_string); + //call parse_time_duration with remaining string + time_duration td = parse_delimited_time_duration(tod_string); + //construct a time + return time_type(d, td); + + } + + +} }//namespace date_time + + + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif diff --git a/include/boost/date_time/time_resolution_traits.hpp b/include/boost/date_time/time_resolution_traits.hpp new file mode 100644 index 0000000..b183439 --- /dev/null +++ b/include/boost/date_time/time_resolution_traits.hpp @@ -0,0 +1,77 @@ + +#ifndef DATE_TIME_TIME_RESOLUTION_TRAITS_HPP +#define DATE_TIME_TIME_RESOLUTION_TRAITS_HPP + +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +#include "boost/date_time/time_defs.hpp" +#include "boost/cstdint.hpp" + +namespace boost { +namespace date_time { + + template + class time_resolution_traits { + public: + typedef frac_sec_type fractional_seconds_type; + typedef frac_sec_type tick_type; + typedef v_type day_type; + typedef v_type hour_type; + typedef v_type min_type; + typedef v_type sec_type; + + //Would like this to be frac_sec_type, but some compilers complain + static const boost::int32_t ticks_per_second = resolution_adjust; + + static time_resolutions resolution() + { + return res; + } + static unsigned short num_fractional_digits() + { + return frac_digits; + } + static fractional_seconds_type res_adjust() + { + return resolution_adjust; + } + static tick_type to_tick_count(hour_type hours, + min_type minutes, + sec_type seconds, + fractional_seconds_type fs) + { + return (((hours*3600) + (minutes*60) + seconds)*res_adjust()) + fs; + } + + }; + + typedef time_resolution_traits milli_res; + typedef time_resolution_traits micro_res; + typedef time_resolution_traits nano_res; + + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + + +#endif diff --git a/include/boost/date_time/time_system_counted.hpp b/include/boost/date_time/time_system_counted.hpp new file mode 100644 index 0000000..fcf1e75 --- /dev/null +++ b/include/boost/date_time/time_system_counted.hpp @@ -0,0 +1,149 @@ + +#ifndef DATE_TIME_TIME_SYSTEM_COUNTED_HPP +#define DATE_TIME_TIME_SYSTEM_COUNTED_HPP + +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +#include "boost/date_time/time_defs.hpp" +#include + + +namespace boost { +namespace date_time { + + //! Time representation that uses a single integer count + template + struct counted_time_rep + { + typedef typename config::int_type int_type; + typedef typename config::date_type date_type; + typedef typename date_type::duration_type date_duration_type; + typedef typename date_type::calendar_type calendar_type; + typedef typename date_type::ymd_type ymd_type; + typedef typename config::time_duration_type time_duration_type; + typedef typename config::resolution_traits resolution_traits; + + counted_time_rep(const date_type& d, const time_duration_type& tod) + { + time_count_ = (d.day_number() * frac_sec_per_day()) + tod.ticks(); + } + explicit counted_time_rep(int_type count) : + time_count_(count) + {} + date_type date() const + { + typename calendar_type::date_int_type dc = day_count(); + //std::cout << "time_rep here:" << dc << std::endl; + ymd_type ymd = calendar_type::from_day_number(dc); + return date_type(ymd); + } + int_type day_count() const + { + return time_count_ / frac_sec_per_day(); + } + int_type time_count() const + { + return time_count_; + } + int_type tod() const + { + return time_count_ % frac_sec_per_day(); + } + static int_type frac_sec_per_day() + { + int_type seconds_per_day = 60*60*24; + int_type fractional_sec_per_sec(resolution_traits::res_adjust()); + return seconds_per_day*fractional_sec_per_sec; + } + private: + int_type time_count_; + }; + + //! An unadjusted time system implementation. + template + class counted_time_system + { + public: + typedef time_rep time_rep_type; + typedef typename time_rep_type::time_duration_type time_duration_type; + typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type; + typedef typename time_rep_type::date_type date_type; + typedef typename time_rep_type::date_duration_type date_duration_type; + + static time_rep_type get_time_rep(const date_type& day, + const time_duration_type& tod, + date_time::dst_flags) + { + return time_rep_type(day, tod); + } + static date_type get_date(const time_rep_type& val) + { + return val.date(); + } + static time_duration_type get_time_of_day(const time_rep_type& val) + { + return time_duration_type(0,0,0,val.tod()); + } + static std::string zone_name(const time_rep_type&) + { + return ""; + } + static bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs) + { + return (lhs.time_count() == rhs.time_count()); + } + static bool is_less(const time_rep_type& lhs, const time_rep_type& rhs) + { + return (lhs.time_count() < rhs.time_count()); + } + static time_rep_type add_days(const time_rep_type& base, + const date_duration_type& dd) + { + return time_rep_type(base.time_count() + (dd.days() * time_rep_type::frac_sec_per_day())); + } + static time_rep_type subtract_days(const time_rep_type& base, + const date_duration_type& dd) + { + return time_rep_type(base.time_count() - (dd.days() * time_rep_type::frac_sec_per_day())); + } + static time_rep_type subtract_time_duration(const time_rep_type& base, + const time_duration_type& td) + { + return time_rep_type(base.time_count() - td.ticks()); + } + static time_rep_type add_time_duration(const time_rep_type& base, + time_duration_type td) + { + return time_rep_type(base.time_count() + td.ticks()); + } + static time_duration_type subtract_times(const time_rep_type& lhs, + const time_rep_type& rhs) + { + fractional_seconds_type fs = lhs.time_count() - rhs.time_count(); + return time_duration_type(0,0,0,fs); + } + + }; + + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + + +#endif diff --git a/include/boost/date_time/time_system_split.hpp b/include/boost/date_time/time_system_split.hpp new file mode 100644 index 0000000..9d12a82 --- /dev/null +++ b/include/boost/date_time/time_system_split.hpp @@ -0,0 +1,124 @@ + +#ifndef DATE_TIME_TIME_SYSTEM_SPLIT_HPP +#define DATE_TIME_TIME_SYSTEM_SPLIT_HPP + +/* Copyright (c) 2002 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +#include + +namespace boost { +namespace date_time { + + //! An unadjusted time system implementation. + template + class split_timedate_system + { + public: + typedef typename config::time_rep_type time_rep_type; + typedef typename config::date_type date_type; + typedef typename config::time_duration_type time_duration_type; + typedef typename config::date_duration_type date_duration_type; + typedef typename config::int_type int_type; + typedef typename config::resolution_traits resolution_traits; + + //86400 is number of seconds in a day... + typedef date_time::wrapping_int wrap_int_type; + + static time_rep_type get_time_rep(const date_type& day, + const time_duration_type& tod, + date_time::dst_flags) + { + return time_rep_type(day, tod); + } + static date_type get_date(const time_rep_type& val) + { + return date_type(val.day); + } + static time_duration_type get_time_of_day(const time_rep_type& val) + { + return time_duration_type(val.time_of_day); + } + static std::string zone_name(const time_rep_type&) + { + return ""; + } + static bool is_equal(const time_rep_type& lhs, const time_rep_type& rhs) + { + return ((lhs.day == rhs.day) && (lhs.time_of_day == rhs.time_of_day)); + // return true; + } + static bool is_less(const time_rep_type& lhs, const time_rep_type& rhs) + { + if (lhs.day < rhs.day) return true; + if (lhs.day > rhs.day) return false; + return (lhs.time_of_day < rhs.time_of_day); + } + static time_rep_type add_days(const time_rep_type& base, + const date_duration_type& dd) + { + return time_rep_type(base.day+dd, base.time_of_day); + } + static time_rep_type subtract_days(const time_rep_type& base, + const date_duration_type& dd) + { + return time_rep_type(base.day-dd, base.time_of_day); + } + static time_rep_type subtract_time_duration(const time_rep_type& base, + const time_duration_type& td) + { + wrap_int_type day_offset(base.time_of_day.ticks()); + date_duration_type day_overflow(day_offset.subtract(td.ticks())); +// std::cout << "sub: " << base.time_of_day.ticks() << "|" +// << day_offset.as_int() << "|" +// << day_overflow.days() << std::endl; + return time_rep_type(base.day-day_overflow, + time_duration_type(0,0,0,day_offset.as_int())); + } + static time_rep_type add_time_duration(const time_rep_type& base, + time_duration_type td) + { + if (td.is_negative()) { + time_duration_type td1 = td.invert_sign(); + return subtract_time_duration(base,td1); + } + wrap_int_type day_offset(base.time_of_day.ticks()); + int_type doff = day_offset.add(td.ticks()); +// std::cout << "day overflow: " << doff << std::endl; +// std::cout << "ticks: " << td.ticks() << std::endl; + date_duration_type day_overflow(doff); +// std::cout << "base: " << to_simple_string(base.day) << std::endl; +// std::cout << "overflow " << day_overflow.days() << std::endl; + return time_rep_type(base.day+day_overflow, + time_duration_type(0,0,0,day_offset.as_int())); + } + static time_duration_type subtract_times(const time_rep_type& lhs, + const time_rep_type& rhs) + { + date_duration_type dd = lhs.day - rhs.day; + time_duration_type td(dd.days()*24,0,0); //days * 24 hours + time_duration_type td2 = lhs.time_of_day - rhs.time_of_day; + return td+td2; + // return time_rep_type(base.day-dd, base.time_of_day); + } + + }; + +} } //namespace date_time + +/* Copyright (c) 2002 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + */ + +#endif diff --git a/include/boost/date_time/wrapping_int.hpp b/include/boost/date_time/wrapping_int.hpp new file mode 100644 index 0000000..2da6ae2 --- /dev/null +++ b/include/boost/date_time/wrapping_int.hpp @@ -0,0 +1,137 @@ +#ifndef _DATE_TIME_WRAPPING_INT_HPP__ +#define _DATE_TIME_WRAPPING_INT_HPP__ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + + +namespace boost { +namespace date_time { + +//! A wrapping integer used to support time durations +/*! In composite date and time types this type is used to + * wrap at the day boundary. + * + */ +template +class wrapping_int { +public: + typedef int_type_ int_type; + //typedef overflow_type_ overflow_type; + static int_type wrap_value() {return wrap_val;} + //!Add, return true if wrapped + wrapping_int(int_type v) : value_(v) {}; + //! Explicit converion method + int_type as_int() const {return value_;} + operator int_type() const {return value_;} + int_type add(int_type v) + { + //take the mod here and assign it.... + int_type remainder = v % wrap_val; + int_type overflow = v / wrap_val; + value_ += remainder; + if ((value_) >= wrap_val) { + value_ -= wrap_val; + overflow++; + } + return overflow; + } + int_type subtract(int_type v) + { + //take the mod here and assign it.... + int_type remainder = v % wrap_val; + int_type underflow = v / wrap_val; + +// std::cout << "wi :" << value_ << "|" +// << v << "|" +// << underflow << "|" +// << remainder << "|" +// << wrap_val << std::endl; + if (remainder > value_) { + underflow++; + // value_ = remainder - value_; + value_ = wrap_val - (remainder-value_); + } + else { + value_ -= remainder; + //value_ = wrap_val-(remainder-value_); + // value_ = wrap_val -(value_-remainder); + } +// std::cout << "wi final uf: " << underflow +// << " value: " << value_ << std::endl; + return underflow; + } + +private: + int_type value_; + +}; + + +//! A wrapping integer used to wrap around at the top +/*! Bad name, quick impl to fix a bug -- fix later!! + * This allows the wrap to restart at a value other than 0. + * Currently this only works if wrap_min == 1 + */ +template +class wrapping_int2 { +public: + typedef int_type_ int_type; + static unsigned long wrap_value() {return wrap_max;} + static unsigned long min_value() {return wrap_min;} + //!Add, return true if wrapped + wrapping_int2(int_type v) : value_(v) {}; + //! Explicit converion method + int_type as_int() const {return value_;} + operator int_type() const {return value_;} + int_type add(int_type v) + { + //take the mod here and assign it.... + int_type remainder = v % wrap_max; + int_type overflow = v / wrap_max; +// std::cout << "wi2: " << value_ << "|" +// << v << "|" +// << remainder << "|" +// << wrap_max << "|" +// << wrap_min << std::endl; + value_ += remainder; + if ((value_) > wrap_max) { + overflow++; + value_ -= (wrap_max - wrap_min + 1); + } +// std::cout << "wi2 final: " +// << overflow << "|" +// << value_ << std::endl; + return overflow; + } + +private: + int_type value_; + +}; + + + +} } //namespace date_time + +/* + * Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided as is without express or implied warranty. + * + * + * Author: Jeff Garland (jeff@CrystalClearSoftware.com) + * Created: Sat Sep 8 19:37:11 2001 + * + */ + + +#endif diff --git a/include/boost/date_time/year_month_day.hpp b/include/boost/date_time/year_month_day.hpp new file mode 100644 index 0000000..7543dad --- /dev/null +++ b/include/boost/date_time/year_month_day.hpp @@ -0,0 +1,52 @@ +#ifndef YearMonthDayBase_HPP__ +#define YearMonthDayBase_HPP__ +/* Copyright (c) 2001 CrystalClear Software, Inc. + * Disclaimer & Full Copyright at end of file + * Author: Jeff Garland + */ + +namespace boost { +namespace date_time { + +//! Allow rapid creation of ymd triples of different types +template +struct year_month_day_base { + year_month_day_base(YearType year, + MonthType month, + DayType day); + YearType year; + MonthType month; + DayType day; + typedef YearType year_type; + typedef MonthType month_type; + typedef DayType day_type; +}; + + +//! A basic constructor +template +inline +year_month_day_base::year_month_day_base(YearType y, + MonthType m, + DayType d) : + year(y), + month(m), + day(d) +{} + +} }//namespace date_time + +/* Copyright (c) 2001 + * CrystalClear Software, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. CrystalClear Software makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +#endif + diff --git a/src/gregorian/greg_month.cpp b/src/gregorian/greg_month.cpp index 0194dab..e8d1a83 100644 --- a/src/gregorian/greg_month.cpp +++ b/src/gregorian/greg_month.cpp @@ -5,13 +5,13 @@ * Author: Jeff Garland */ -#include "boost/gdtl/gregorian/greg_month.hpp" -#include "boost/gdtl/gregorian/greg_facet.hpp" -#include "boost/gdtl/date_format_simple.hpp" -#include "boost/gdtl/gregorian/formatters.hpp" +#include "boost/date_time/gregorian/greg_month.hpp" +#include "boost/date_time/gregorian/greg_facet.hpp" +#include "boost/date_time/date_format_simple.hpp" +#include "boost/date_time/gregorian/formatters.hpp" namespace boost { -namespace gdtl { +namespace date_time { #ifndef BOOST_NO_STD_LOCALE diff --git a/src/gregorian/greg_weekday.cpp b/src/gregorian/greg_weekday.cpp index 0c5f59e..e8fb110 100644 --- a/src/gregorian/greg_weekday.cpp +++ b/src/gregorian/greg_weekday.cpp @@ -5,7 +5,7 @@ * Author: Jeff Garland */ -#include "boost/gdtl/gregorian/greg_weekday.hpp" +#include "boost/date_time/gregorian/greg_weekday.hpp" namespace boost { namespace gregorian { diff --git a/src/gregorian/gregorian_types.cpp b/src/gregorian/gregorian_types.cpp index 15834d7..7356585 100644 --- a/src/gregorian/gregorian_types.cpp +++ b/src/gregorian/gregorian_types.cpp @@ -35,7 +35,7 @@ Calculate the number of days till new years */ /*! @example print_month.cpp - Simple utility to print out days of the month with the days of a month. Demontstrates date iteration (gdtl::date_itr). + Simple utility to print out days of the month with the days of a month. Demontstrates date iteration (date_time::date_itr). */ /*! @example dates_as_strings.cpp Various parsing and output of strings. diff --git a/test/gregorian/testcurrent_day.cpp b/test/gregorian/testcurrent_day.cpp index 2d78856..e7a45e0 100644 --- a/test/gregorian/testcurrent_day.cpp +++ b/test/gregorian/testcurrent_day.cpp @@ -1,5 +1,5 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include int diff --git a/test/gregorian/testdate.cpp b/test/gregorian/testdate.cpp index 6911333..432a31b 100644 --- a/test/gregorian/testdate.cpp +++ b/test/gregorian/testdate.cpp @@ -1,7 +1,7 @@ #include -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() diff --git a/test/gregorian/testdate_duration.cpp b/test/gregorian/testdate_duration.cpp index 71e66ef..37154fc 100644 --- a/test/gregorian/testdate_duration.cpp +++ b/test/gregorian/testdate_duration.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" #include diff --git a/test/gregorian/testdate_iterator.cpp b/test/gregorian/testdate_iterator.cpp index a1135b3..f2918e5 100644 --- a/test/gregorian/testdate_iterator.cpp +++ b/test/gregorian/testdate_iterator.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" #include void test_base_iterator(boost::gregorian::date end, @@ -29,11 +29,11 @@ main() std::cout << data << std::endl; - typedef boost::gdtl::day_functor dfg; + typedef boost::date_time::day_functor dfg; { const date DayAnswers[] = {date(2000,Jan,20),date(2000,Jan,22),date(2000,Jan,24)}; - boost::gdtl::date_itr ditr(date(2000,Jan,20),2); + boost::date_time::date_itr ditr(date(2000,Jan,20),2); int i=0; for (; ditr < date(2000,Jan,25); ++ditr) { //std::cout << *ditr << " "; @@ -43,10 +43,10 @@ main() check("day iterator -- 2 days", i == 3); // check the number of iterations } - typedef boost::gdtl::week_functor wfg; + typedef boost::date_time::week_functor wfg; { const date WeekAnswers[] = {date(2000,Jan,20),date(2000,Jan,27),date(2000,Feb,3)}; - boost::gdtl::date_itr ditr(date(2000,Jan,20)); + boost::date_time::date_itr ditr(date(2000,Jan,20)); int i=0; for (; ditr < date(2000,Feb,6); ++ditr) { //std::cout << *ditr << " "; @@ -58,7 +58,7 @@ main() { const date WeekAnswers[] = {date(2000,Jan,20),date(2000,Feb,3)}; - boost::gdtl::date_itr ditr(date(2000,Jan,20),2); + boost::date_time::date_itr ditr(date(2000,Jan,20),2); int i=0; for (; ditr < date(2000,Feb,6); ++ditr) { //std::cout << *ditr << " "; @@ -70,7 +70,7 @@ main() { const date WeekAnswers[] = {date(2000,Jan,20),date(2000,Feb,3), date(2000,Feb,17)}; - boost::gdtl::date_itr ditr(date(2000,Jan,20),2); + boost::date_time::date_itr ditr(date(2000,Jan,20),2); int i=0; for (; ditr < date(2000,Feb,20); ++ditr) { //std::cout << *ditr << " "; @@ -80,7 +80,7 @@ main() check("week iterator -- 2 weeks", i == 3); } - typedef boost::gdtl::month_functor mfg; + typedef boost::date_time::month_functor mfg; { const date MonthAnswers[] = { date(2000,Jan,1),date(2000,Feb,1),date(2000,Mar,1),date(2000,Apr,1), @@ -89,7 +89,7 @@ main() date(2001,Jan,1) }; - boost::gdtl::date_itr ditr(date(2000,Jan,1)); + boost::date_time::date_itr ditr(date(2000,Jan,1)); int i = 0; try { for (; ditr < date(2001,Jan,2); ++ditr) { @@ -113,7 +113,7 @@ main() date(2001,Jan,31) }; - boost::gdtl::date_itr ditr(date(2000,Jan,31)); + boost::date_time::date_itr ditr(date(2000,Jan,31)); int i = 0; try { for (; ditr < date(2001,Feb,1); ++ditr) { @@ -140,7 +140,7 @@ main() date(2001,Jan,31) }; - boost::gdtl::date_itr ditr(date(2000,Feb,29)); + boost::date_time::date_itr ditr(date(2000,Feb,29)); int i = 0; try { for (; ditr < date(2001,Feb,1); ++ditr) { @@ -167,7 +167,7 @@ main() date(2001,Jan,28) }; - boost::gdtl::date_itr ditr(date(2000,Feb,28)); + boost::date_time::date_itr ditr(date(2000,Feb,28)); int i = 0; try { for (; ditr < date(2001,Feb,1); ++ditr) { @@ -186,7 +186,7 @@ main() } } - typedef boost::gdtl::year_functor yfg; + typedef boost::date_time::year_functor yfg; { const date YearAnswers[] = { date(2000,Jan,1),date(2001,Jan,1),date(2002,Jan,1),date(2003,Jan,1), @@ -194,7 +194,7 @@ main() date(2008,Jan,1),date(2009,Jan,1),date(2010,Jan,1) }; - boost::gdtl::date_itr d3(date(2000,Jan,1)); + boost::date_time::date_itr d3(date(2000,Jan,1)); int i = 0; for (; d3 < date(2010,Jan,2); ++d3) { //std::cout << *d3 << " "; @@ -210,7 +210,7 @@ main() date(2008,Jan,1),date(2010,Jan,1) }; - boost::gdtl::date_itr d3(date(2000,Jan,1),2); + boost::date_time::date_itr d3(date(2000,Jan,1),2); int i = 0; for (; d3 < date(2010,Jan,2); ++d3) { //std::cout << *d3 << " "; diff --git a/test/gregorian/testfacet.cpp b/test/gregorian/testfacet.cpp index df4f565..654043c 100644 --- a/test/gregorian/testfacet.cpp +++ b/test/gregorian/testfacet.cpp @@ -2,11 +2,11 @@ #include #include -#include "boost/gdtl/gregorian/greg_month.hpp" -#include "boost/gdtl/gregorian/greg_facet.hpp" -#include "boost/gdtl/date_format_simple.hpp" -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/greg_month.hpp" +#include "boost/date_time/gregorian/greg_facet.hpp" +#include "boost/date_time/date_format_simple.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" const char* const de_short_month_names[]={"Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez", "NAM"}; @@ -33,9 +33,9 @@ main() using namespace boost::gregorian; typedef greg_facet_config facet_config; - typedef boost::gdtl::all_date_names_put date_facet; - typedef boost::gdtl::date_names_put date_facet_base; - typedef boost::gdtl::ostream_month_formatter month_formatter; + typedef boost::date_time::all_date_names_put date_facet; + typedef boost::date_time::date_names_put date_facet_base; + typedef boost::date_time::ostream_month_formatter month_formatter; date_facet gdnp(de_short_month_names, de_long_month_names, de_special_value_names, de_long_weekday_names, @@ -49,24 +49,24 @@ main() ss.str(""); //reset string stream greg_month m(Oct); - month_formatter::format_month(m, ss, gdnp, boost::gdtl::month_as_short_string); + month_formatter::format_month(m, ss, gdnp, boost::date_time::month_as_short_string); check("check german short month: " + ss.str(), ss.str() == std::string("Okt")); ss.str(""); //reset string stream - month_formatter::format_month(m, ss, gdnp, boost::gdtl::month_as_long_string); + month_formatter::format_month(m, ss, gdnp, boost::date_time::month_as_long_string); check("check german long month: " + ss.str(), ss.str() == std::string("Oktober")); greg_year_month_day ymd(2002,Oct,1); - typedef boost::gdtl::ostream_ymd_formatter ymd_formatter; + typedef boost::date_time::ostream_ymd_formatter ymd_formatter; ss.str(""); //reset string stream ymd_formatter::ymd_put(ymd, ss, gdnp); check("check ymd: " + ss.str(), ss.str() == std::string("2002-Okt-01")); - typedef boost::gdtl::ostream_date_formatter datef; + typedef boost::date_time::ostream_date_formatter datef; std::stringstream os; date d1(2002, Oct, 1); @@ -91,7 +91,7 @@ main() de_long_weekday_names)); check("facet registered here", - std::has_facet >(global2)); + std::has_facet >(global2)); std::stringstream os2; os2.imbue(global2); diff --git a/test/gregorian/testformatters.cpp b/test/gregorian/testformatters.cpp index 820813e..83475e9 100644 --- a/test/gregorian/testformatters.cpp +++ b/test/gregorian/testformatters.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() @@ -27,15 +27,15 @@ main() // std::stringstream os; // typedef boost::gregorian::date::ymd_type ymd_type; -// typedef boost::gdtl::ymd_formatter ymdf; +// typedef boost::date_time::ymd_formatter ymdf; // ymd_type ymd = d1.year_month_day(); // ymdf::ymd_put(ymd, os); // check("ostream low level check string", // os.str() == std::string("2002-Jan-02")); -// typedef boost::gdtl::date_formatter datef; +// typedef boost::date_time::date_formatter datef; // os.str(""); // datef::date_to_ostream(d1, os); // check("ostream low level check string", diff --git a/test/gregorian/testgenerators.cpp b/test/gregorian/testgenerators.cpp index 71c214d..073a34c 100644 --- a/test/gregorian/testgenerators.cpp +++ b/test/gregorian/testgenerators.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" #include int @@ -15,7 +15,7 @@ main() d = pd.get_date(2001); check("Partial date getdate", date(2001,1,1) == d); - typedef boost::gdtl::last_kday_of_month lastkday; + typedef boost::date_time::last_kday_of_month lastkday; //Find last Sunday in Feb lastkday lsif(Sunday, Feb); @@ -26,7 +26,7 @@ main() lastkday lfif(Friday, Feb); check("Last kday", date(2002,Feb,22) == lfif.get_date(2002)); - typedef boost::gdtl::first_kday_of_month firstkday; + typedef boost::date_time::first_kday_of_month firstkday; firstkday fsif(Sunday, Feb); std::cout << to_simple_string(fsif.get_date(2002)) << std::endl; //24th @@ -36,7 +36,7 @@ main() firstkday ffif(Friday, Feb); check("First kday", date(2002,Feb,1) == ffif.get_date(2002)); - typedef boost::gdtl::first_kday_after firstkdayafter; + typedef boost::date_time::first_kday_after firstkdayafter; firstkdayafter fkaf(Monday); std::cout << to_simple_string(fkaf.get_date(date(2002,Feb,1))) << std::endl; //feb 4 @@ -45,7 +45,7 @@ main() check("kday after",date(2002,Feb,7) == fkaf2.get_date(date(2002,Feb,1))); check("kday after",date(2002,Feb,28)== fkaf2.get_date(date(2002,Feb,21))); - typedef boost::gdtl::first_kday_before firstkdaybefore; + typedef boost::date_time::first_kday_before firstkdaybefore; firstkdaybefore fkbf(Monday); std::cout << to_simple_string(fkaf.get_date(date(2002,Feb,10))) << std::endl; //feb 4 diff --git a/test/gregorian/testgreg_cal.cpp b/test/gregorian/testgreg_cal.cpp index cc5fa92..66aab50 100644 --- a/test/gregorian/testgreg_cal.cpp +++ b/test/gregorian/testgreg_cal.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/greg_calendar.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/greg_calendar.hpp" +#include "boost/date_time/testfrmwk.hpp" #include diff --git a/test/gregorian/testgreg_day.cpp b/test/gregorian/testgreg_day.cpp index 8943ceb..cea2512 100644 --- a/test/gregorian/testgreg_day.cpp +++ b/test/gregorian/testgreg_day.cpp @@ -1,8 +1,8 @@ -#include "boost/gdtl/gregorian/greg_day.hpp" -#include "boost/gdtl/gregorian/greg_weekday.hpp" -#include "boost/gdtl/gregorian/greg_day_of_year.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/greg_day.hpp" +#include "boost/date_time/gregorian/greg_weekday.hpp" +#include "boost/date_time/gregorian/greg_day_of_year.hpp" +#include "boost/date_time/testfrmwk.hpp" #include diff --git a/test/gregorian/testgreg_month.cpp b/test/gregorian/testgreg_month.cpp index 02bf6e2..b4a81c7 100644 --- a/test/gregorian/testgreg_month.cpp +++ b/test/gregorian/testgreg_month.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/greg_month.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/greg_month.hpp" +#include "boost/date_time/testfrmwk.hpp" #include diff --git a/test/gregorian/testgreg_year.cpp b/test/gregorian/testgreg_year.cpp index ede36d5..842624d 100644 --- a/test/gregorian/testgreg_year.cpp +++ b/test/gregorian/testgreg_year.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/greg_year.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/greg_year.hpp" +#include "boost/date_time/testfrmwk.hpp" #include diff --git a/test/gregorian/testparse_date.cpp b/test/gregorian/testparse_date.cpp index 52d45de..e8a5856 100644 --- a/test/gregorian/testparse_date.cpp +++ b/test/gregorian/testparse_date.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" #include #include @@ -50,7 +50,7 @@ main() try { std::string s2("2001-14-1"); //oops should be <= 12 - boost::gregorian::date bad_month(boost::gdtl::parse_date(s2)); + boost::gregorian::date bad_month(boost::date_time::parse_date(s2)); check("check bad month", false); //fail the test //The line below won't execute, but make the compiler think //we are using bad day.... @@ -79,7 +79,7 @@ main() std::string ad("2001/10/09"); - date d2(boost::gdtl::parse_date(ad)); + date d2(boost::date_time::parse_date(ad)); check("check american date", d2 == date(2001,Oct,9)); } catch(std::exception& e) { diff --git a/test/gregorian/testperiod.cpp b/test/gregorian/testperiod.cpp index e29ff15..c0f6dd7 100644 --- a/test/gregorian/testperiod.cpp +++ b/test/gregorian/testperiod.cpp @@ -1,5 +1,5 @@ -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/testfrmwk.hpp" #include int main() diff --git a/test/posix_time/testc_local_adjustor.cpp b/test/posix_time/testc_local_adjustor.cpp index d395c70..d5fb652 100644 --- a/test/posix_time/testc_local_adjustor.cpp +++ b/test/posix_time/testc_local_adjustor.cpp @@ -1,7 +1,7 @@ -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/c_local_time_adjustor.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/c_local_time_adjustor.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() @@ -12,7 +12,7 @@ main() //These are a compile check / test. They have to be hand inspected //b/c they depend on the TZ settings of the machine and hence it is //unclear what the results will be - typedef boost::gdtl::c_local_adjustor local_adj; + typedef boost::date_time::c_local_adjustor local_adj; ptime t1(date(2002,Jan,1), hours(7)+millisec(5)); std::cout << "UTC <--> TZ Setting of Machine -- No DST" << std::endl; diff --git a/test/posix_time/testclock.cpp b/test/posix_time/testclock.cpp index 5c60a28..447dd50 100644 --- a/test/posix_time/testclock.cpp +++ b/test/posix_time/testclock.cpp @@ -1,5 +1,5 @@ -#include "boost/gdtl/posix_time/posix_time.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" #include int diff --git a/test/posix_time/testdst_rules.cpp b/test/posix_time/testdst_rules.cpp index 5d70c52..68ed279 100644 --- a/test/posix_time/testdst_rules.cpp +++ b/test/posix_time/testdst_rules.cpp @@ -1,7 +1,7 @@ -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/dst_rules.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/dst_rules.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() @@ -13,7 +13,7 @@ main() //The following defines the US dst boundaries, except that the //start and end dates are hard coded. - typedef boost::gdtl::us_dst_rules us_dst; + typedef boost::date_time::us_dst_rules us_dst; date dst_start(2002,Apr, 7); date dst_end(2002,Oct, 27); @@ -31,37 +31,37 @@ main() check("dst boundary", us_dst::is_dst_boundary_day(dst_start)); check("dst boundary", us_dst::is_dst_boundary_day(dst_end)); check("check if time is dst -- not", - us_dst::local_is_dst(t.date(), t.time_of_day())==boost::gdtl::is_not_in_dst); + us_dst::local_is_dst(t.date(), t.time_of_day())==boost::date_time::is_not_in_dst); check("label on dst boundary invalid", - us_dst::local_is_dst(t3a.date(),t3a.time_of_day())==boost::gdtl::invalid_time_label); + us_dst::local_is_dst(t3a.date(),t3a.time_of_day())==boost::date_time::invalid_time_label); check("label on dst boundary invalid", - us_dst::local_is_dst(t3b.date(),t3b.time_of_day())==boost::gdtl::invalid_time_label); + us_dst::local_is_dst(t3b.date(),t3b.time_of_day())==boost::date_time::invalid_time_label); check("check if time is dst -- not", - us_dst::local_is_dst(t4.date(),t4.time_of_day())==boost::gdtl::is_not_in_dst); + us_dst::local_is_dst(t4.date(),t4.time_of_day())==boost::date_time::is_not_in_dst); check("check if time is dst -- yes", - us_dst::local_is_dst(t5.date(),t5.time_of_day())==boost::gdtl::is_in_dst); + us_dst::local_is_dst(t5.date(),t5.time_of_day())==boost::date_time::is_in_dst); check("check if time is dst -- not", - us_dst::local_is_dst(t6.date(),t6.time_of_day())==boost::gdtl::is_in_dst); + us_dst::local_is_dst(t6.date(),t6.time_of_day())==boost::date_time::is_in_dst); check("check if time is dst -- ambig", - us_dst::local_is_dst(t7.date(),t7.time_of_day())==boost::gdtl::ambiguous); + us_dst::local_is_dst(t7.date(),t7.time_of_day())==boost::date_time::ambiguous); check("check if time is dst -- ambig", - us_dst::local_is_dst(t8.date(),t8.time_of_day())==boost::gdtl::ambiguous); + us_dst::local_is_dst(t8.date(),t8.time_of_day())==boost::date_time::ambiguous); check("check if time is dst -- not", - us_dst::local_is_dst(t9.date(),t9.time_of_day())==boost::gdtl::is_not_in_dst); + us_dst::local_is_dst(t9.date(),t9.time_of_day())==boost::date_time::is_not_in_dst); //Now try a local without dst - typedef boost::gdtl::null_dst_rules no_dst_adj; + typedef boost::date_time::null_dst_rules no_dst_adj; check("check null dst rules", - no_dst_adj::local_is_dst(t4.date(),t4.time_of_day())==boost::gdtl::is_not_in_dst); + no_dst_adj::local_is_dst(t4.date(),t4.time_of_day())==boost::date_time::is_not_in_dst); check("check null dst rules", - no_dst_adj::local_is_dst(t5.date(),t5.time_of_day())==boost::gdtl::is_not_in_dst); + no_dst_adj::local_is_dst(t5.date(),t5.time_of_day())==boost::date_time::is_not_in_dst); check("check null dst rules", - no_dst_adj::utc_is_dst(t4.date(),t4.time_of_day())==boost::gdtl::is_not_in_dst); + no_dst_adj::utc_is_dst(t4.date(),t4.time_of_day())==boost::date_time::is_not_in_dst); check("check null dst rules", - no_dst_adj::utc_is_dst(t5.date(),t5.time_of_day())==boost::gdtl::is_not_in_dst); + no_dst_adj::utc_is_dst(t5.date(),t5.time_of_day())==boost::date_time::is_not_in_dst); //Try a southern hemisphere adjustment calculation @@ -73,73 +73,73 @@ main() date dst_start2(2002,Oct,27); //last Sunday in Oct date dst_end2(2002,Mar,31); //last Sunday in March - typedef boost::gdtl::dst_calculator dstcalc; + typedef boost::date_time::dst_calculator dstcalc; //clearly not in dst - boost::gdtl::time_is_dst_result a1 = + boost::date_time::time_is_dst_result a1 = dstcalc::local_is_dst(date(2002,May,1),hours(3), dst_start2, 120, dst_end2, 120, 60); - check("check southern not dst", a1==boost::gdtl::is_not_in_dst); + check("check southern not dst", a1==boost::date_time::is_not_in_dst); - boost::gdtl::time_is_dst_result a2 = + boost::date_time::time_is_dst_result a2 = dstcalc::local_is_dst(date(2002,Jan,1),hours(3), dst_start2, 120, dst_end2, 120, 60); - check("check southern is dst", a2==boost::gdtl::is_in_dst); + check("check southern is dst", a2==boost::date_time::is_in_dst); - boost::gdtl::time_is_dst_result a3 = + boost::date_time::time_is_dst_result a3 = dstcalc::local_is_dst(date(2002,Oct,28),hours(3), dst_start2, 120, dst_end2, 120, 60); - check("check southern is dst", a3==boost::gdtl::is_in_dst); - boost::gdtl::time_is_dst_result a4 = + check("check southern is dst", a3==boost::date_time::is_in_dst); + boost::date_time::time_is_dst_result a4 = dstcalc::local_is_dst(date(2002,Oct,27),time_duration(1,59,59), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-not dst", a4==boost::gdtl::is_not_in_dst); - boost::gdtl::time_is_dst_result a5 = + check("check southern boundary-not dst", a4==boost::date_time::is_not_in_dst); + boost::date_time::time_is_dst_result a5 = dstcalc::local_is_dst(date(2002,Oct,27),hours(3), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-is dst", a5==boost::gdtl::is_in_dst); - boost::gdtl::time_is_dst_result a6 = + check("check southern boundary-is dst", a5==boost::date_time::is_in_dst); + boost::date_time::time_is_dst_result a6 = dstcalc::local_is_dst(date(2002,Oct,27),hours(2), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-invalid time", a6==boost::gdtl::invalid_time_label); - boost::gdtl::time_is_dst_result a7 = + check("check southern boundary-invalid time", a6==boost::date_time::invalid_time_label); + boost::date_time::time_is_dst_result a7 = dstcalc::local_is_dst(date(2002,Mar,31),time_duration(0,59,59), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-is dst", a7==boost::gdtl::is_in_dst); - boost::gdtl::time_is_dst_result a8 = + check("check southern boundary-is dst", a7==boost::date_time::is_in_dst); + boost::date_time::time_is_dst_result a8 = dstcalc::local_is_dst(date(2002,Mar,31),time_duration(1,0,0), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-ambiguous", a8==boost::gdtl::ambiguous); - boost::gdtl::time_is_dst_result a9 = + check("check southern boundary-ambiguous", a8==boost::date_time::ambiguous); + boost::date_time::time_is_dst_result a9 = dstcalc::local_is_dst(date(2002,Mar,31),time_duration(1,59,59), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-ambiguous", a9==boost::gdtl::ambiguous); - boost::gdtl::time_is_dst_result a10 = + check("check southern boundary-ambiguous", a9==boost::date_time::ambiguous); + boost::date_time::time_is_dst_result a10 = dstcalc::local_is_dst(date(2002,Mar,31),time_duration(2,0,0), dst_start2, 120, dst_end2, 120, 60); - check("check southern boundary-not", a10==boost::gdtl::is_not_in_dst); + check("check southern boundary-not", a10==boost::date_time::is_not_in_dst); printTestStats(); diff --git a/test/posix_time/testduration.cpp b/test/posix_time/testduration.cpp index 8108a07..577c1aa 100644 --- a/test/posix_time/testduration.cpp +++ b/test/posix_time/testduration.cpp @@ -1,8 +1,8 @@ -#include "boost/gdtl/posix_time/posix_time_duration.hpp" -#include "boost/gdtl/posix_time/time_formatters.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time_duration.hpp" +#include "boost/date_time/posix_time/time_formatters.hpp" +#include "boost/date_time/testfrmwk.hpp" int @@ -53,7 +53,7 @@ main() time_duration t8 = tenhours + time_duration(1,2,3) + fivemin; check("short hand durations add", t8 == time_duration(11,7,3)); - if (time_duration::resolution() >= boost::gdtl::micro) { + if (time_duration::resolution() >= boost::date_time::micro) { time_duration t_9(5,4,3,9876); //05:04:03.09876 check("h-m-s 5-4-3.21 hours", t_9.hours() == 5); check("h-m-s 5-4-3.21 min ", t_9.minutes() == 4); @@ -64,7 +64,7 @@ main() std::cout << to_simple_string(t_9) << std::endl; } - if (time_duration::resolution() >= boost::gdtl::tenth) { + if (time_duration::resolution() >= boost::date_time::tenth) { time_duration t_10(5,4,3,9); //05:04:03.00001 check("h-m-s 5-4-3.9 hours", t_10.hours() == 5); check("h-m-s 5-4-3.9 min ", t_10.minutes() == 4); @@ -73,12 +73,12 @@ main() std::cout << to_simple_string(t_10) << std::endl; } - if (time_duration::resolution() >= boost::gdtl::milli) { + if (time_duration::resolution() >= boost::date_time::milli) { millisec ms(9); // time_duration t_10(0,0,0,); //00:00:00.009 std::cout << "time_resolution: " << time_duration::resolution() << std::endl; std::cout << "res_adjust " << time_res_traits::res_adjust() << std::endl; - if (time_duration::resolution() == boost::gdtl::nano) { + if (time_duration::resolution() == boost::date_time::nano) { check("millisec", ms.fractional_seconds() == 9000000); } else { @@ -87,7 +87,7 @@ main() } #ifdef BOOST_GDTL_HAS_NANOSECONDS - if (time_duration::resolution() >= boost::gdtl::nano) { + if (time_duration::resolution() >= boost::date_time::nano) { nanosec ns(9); // time_duration t_10(0,0,0,); //00:00:00.00009 check("nanosec", ns.fractional_seconds() == 9); diff --git a/test/posix_time/testformatters.cpp b/test/posix_time/testformatters.cpp index 746e438..1ac5f3c 100644 --- a/test/posix_time/testformatters.cpp +++ b/test/posix_time/testformatters.cpp @@ -1,7 +1,7 @@ -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() @@ -25,7 +25,7 @@ main() #ifdef BOOST_GDTL_HAS_MILLISECONDS - if (time_duration::resolution() == boost::gdtl::milli) { + if (time_duration::resolution() == boost::date_time::milli) { ptime t4(d1,hours(1)+minutes(2)+seconds(3)+millisec(4)); std::string r3 = to_simple_string(t4); check("simple subsecond: "+r3 , @@ -36,7 +36,7 @@ main() #ifdef BOOST_GDTL_HAS_MICROSECONDS - if (time_duration::resolution() == boost::gdtl::micro) { + if (time_duration::resolution() == boost::date_time::micro) { ptime t3(d1,hours(1)+minutes(2)+seconds(3)+microsec(4)); std::string result = to_simple_string(t3); check("simple subsecond: "+result , @@ -52,7 +52,7 @@ main() #ifdef BOOST_GDTL_HAS_NANOSECONDS - if (time_duration::resolution() == boost::gdtl::nano) { + if (time_duration::resolution() == boost::date_time::nano) { ptime t2(d1,hours(12) + minutes(5) + seconds(1)); time_period p1(t1,t2); //last value in period is 12:05:00 1/10000 sec less than t2 std::string period_result("["+t1_result + "/" + d1_string + " " + "12:05:00.999999999]" ); diff --git a/test/posix_time/testiterator.cpp b/test/posix_time/testiterator.cpp index c8453ba..55f9e62 100644 --- a/test/posix_time/testiterator.cpp +++ b/test/posix_time/testiterator.cpp @@ -1,9 +1,9 @@ #include -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/testfrmwk.hpp" -#include "boost/gdtl/gregorian/formatters.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/testfrmwk.hpp" +#include "boost/date_time/gregorian/formatters.hpp" int diff --git a/test/posix_time/testlocal_adjustor.cpp b/test/posix_time/testlocal_adjustor.cpp index 41134fa..b9578c8 100644 --- a/test/posix_time/testlocal_adjustor.cpp +++ b/test/posix_time/testlocal_adjustor.cpp @@ -1,7 +1,7 @@ -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/local_time_adjustor.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/local_time_adjustor.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() @@ -12,9 +12,9 @@ main() date dst_start(2002,Apr, 7); date dst_end_day(2002,Oct, 27); - typedef boost::gdtl::utc_adjustment us_eastern_offset_adj; + typedef boost::date_time::utc_adjustment us_eastern_offset_adj; //Type that embeds rules for UTC-5 plus DST offset - typedef boost::gdtl::static_local_time_adjustor us_eastern; @@ -45,9 +45,9 @@ main() check("check local calculation", t11_local == t11_check); //should get same offset with DST flag set check("check local offset-dst flag on", - us_eastern::local_to_utc_offset(t11, boost::gdtl::is_dst) == hours(4)); + us_eastern::local_to_utc_offset(t11, boost::date_time::is_dst) == hours(4)); check("check local offset-dst flag override", - us_eastern::local_to_utc_offset(t11, boost::gdtl::not_dst) == hours(5)); + us_eastern::local_to_utc_offset(t11, boost::date_time::not_dst) == hours(5)); //Check the start of dst boundary @@ -59,7 +59,7 @@ main() us_eastern::utc_to_local_offset(u_not_dst) == hours(-5)); ptime l_in_dst(dst_start, hours(3)); //2002-Apr-07 03:00:00 1st sec of dst check("check local dst start boundary case", - us_eastern::local_to_utc_offset(l_in_dst, boost::gdtl::is_dst) == hours(4)); + us_eastern::local_to_utc_offset(l_in_dst, boost::date_time::is_dst) == hours(4)); ptime u_in_dst(dst_start, hours(7)); check("check utc dst start boundary case", us_eastern::utc_to_local_offset(u_in_dst) == hours(-4)); @@ -68,9 +68,9 @@ main() //Check the end of dst boundary ptime dst_end(dst_end_day, time_duration(1,59,59)); //2002-Oct-27 01:00:00 DST check("check local dst end boundary case - still dst", - us_eastern::local_to_utc_offset(dst_end, boost::gdtl::is_dst) == hours(4)); + us_eastern::local_to_utc_offset(dst_end, boost::date_time::is_dst) == hours(4)); check("check local dst end boundary case - still dst", - us_eastern::local_to_utc_offset(dst_end, boost::gdtl::not_dst) == hours(5)); + us_eastern::local_to_utc_offset(dst_end, boost::date_time::not_dst) == hours(5)); ptime u_dst_end1(dst_end_day, time_duration(5,59,59)); check("check utc dst end boundary case", us_eastern::utc_to_local_offset(u_dst_end1) == hours(-4)); @@ -86,10 +86,10 @@ main() //Now try a local adjustments without dst - typedef boost::gdtl::utc_adjustment us_az_offset_adj; - typedef boost::gdtl::null_dst_rules us_az_dst_adj; + typedef boost::date_time::utc_adjustment us_az_offset_adj; + typedef boost::date_time::null_dst_rules us_az_dst_adj; //Type that embeds rules for UTC-7 with no dst - typedef boost::gdtl::static_local_time_adjustor us_az; @@ -104,7 +104,7 @@ main() //Arizona timezone is utc-7 with no dst - typedef boost::gdtl::local_adjustor us_arizona; + typedef boost::date_time::local_adjustor us_arizona; ptime t7(date(2002,May,31), hours(17)); ptime t8 = us_arizona::local_to_utc(t7); @@ -112,7 +112,7 @@ main() //converted to local then back ot utc check("check us_local_adjustor", t9 == t7); - typedef boost::gdtl::local_adjustor us_eastern2; + typedef boost::date_time::local_adjustor us_eastern2; ptime t7a(date(2002,May,31), hours(17)); ptime t7b = us_eastern2::local_to_utc(t7a); @@ -127,7 +127,7 @@ main() //still experimental - typedef boost::gdtl::dynamic_local_time_adjustor lta; + typedef boost::date_time::dynamic_local_time_adjustor lta; // lta adjustor(hours(-7)); check("dst start", lta::local_dst_start_day(2002) == dst_start); check("dst end", lta::local_dst_end_day(2002) == dst_end_day); diff --git a/test/posix_time/testparse_time.cpp b/test/posix_time/testparse_time.cpp index ca426c6..f313a05 100644 --- a/test/posix_time/testparse_time.cpp +++ b/test/posix_time/testparse_time.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/testfrmwk.hpp" int @@ -16,19 +16,19 @@ main() check("parse time duration: " + s1, td1 == time_duration(12,11,10,123456789)); std::string s2("12:11:10,123456789"); - time_duration td2= boost::gdtl::parse_delimited_time_duration(s2); + time_duration td2= boost::date_time::parse_delimited_time_duration(s2); check("parse time duration: " + s2, td2 == time_duration(12,11,10,123456789)); std::string s3("12:11:10"); - time_duration td3= boost::gdtl::parse_delimited_time_duration(s3); + time_duration td3= boost::date_time::parse_delimited_time_duration(s3); check("parse time duration: " + s3, td3 == time_duration(12,11,10,0)); std::string s4("23:59:59.000000001"); - time_duration td4= boost::gdtl::parse_delimited_time_duration(s4); + time_duration td4= boost::date_time::parse_delimited_time_duration(s4); check("parse time duration: " + s4, td4 == time_duration(23,59,59)+nanosec(1)); std::string s5("23:59:59.999999999"); - time_duration td5= boost::gdtl::parse_delimited_time_duration(s5); + time_duration td5= boost::date_time::parse_delimited_time_duration(s5); check("parse time duration: " + s5, td5 == time_duration(23,59,59)+nanosec(999999999)); #endif @@ -40,19 +40,19 @@ main() check("parse time duration: " + s1, td1 == time_duration(12,11,10,123456)); std::string s2("12:11:10,123456"); - time_duration td2= boost::gdtl::parse_delimited_time_duration(s2); + time_duration td2= boost::date_time::parse_delimited_time_duration(s2); check("parse time duration: " + s2, td2 == time_duration(12,11,10,123456)); std::string s3("12:11:10"); - time_duration td3= boost::gdtl::parse_delimited_time_duration(s3); + time_duration td3= boost::date_time::parse_delimited_time_duration(s3); check("parse time duration: " + s3, td3 == time_duration(12,11,10,0)); std::string s4("23:59:59.000001"); - time_duration td4= boost::gdtl::parse_delimited_time_duration(s4); + time_duration td4= boost::date_time::parse_delimited_time_duration(s4); check("parse time duration: " + s4, td4 == time_duration(23,59,59)+microsec(1)); std::string s5("23:59:59.999999"); - time_duration td5= boost::gdtl::parse_delimited_time_duration(s5); + time_duration td5= boost::date_time::parse_delimited_time_duration(s5); check("parse time duration: " + s5, td5 == time_duration(23,59,59)+microsec(999999)); } @@ -60,7 +60,7 @@ main() std::string date_1, tod_1; std::string ts1("2002-01-20 23:59:59.000"); - boost::gdtl::split(ts1, ' ', date_1, tod_1); + boost::date_time::split(ts1, ' ', date_1, tod_1); check("split function date part of " + ts1, date_1 == std::string("2002-01-20")); check("time part of " + ts1, diff --git a/test/posix_time/testperiod.cpp b/test/posix_time/testperiod.cpp index ab08d21..8db3ef9 100644 --- a/test/posix_time/testperiod.cpp +++ b/test/posix_time/testperiod.cpp @@ -1,7 +1,7 @@ #include -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/posix_time/time_period.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/posix_time/time_period.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() { diff --git a/test/posix_time/testtime.cpp b/test/posix_time/testtime.cpp index ff9d63f..7c6499f 100644 --- a/test/posix_time/testtime.cpp +++ b/test/posix_time/testtime.cpp @@ -1,9 +1,9 @@ #include -#include "boost/gdtl/gregorian/gregorian.hpp" -#include "boost/gdtl/posix_time/posix_time.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/date_time/testfrmwk.hpp" int diff --git a/test/testconstrained_value.cpp b/test/testconstrained_value.cpp index d1600a4..d452fa0 100644 --- a/test/testconstrained_value.cpp +++ b/test/testconstrained_value.cpp @@ -1,6 +1,6 @@ -#include "boost/gdtl/constrained_value.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/constrained_value.hpp" +#include "boost/date_time/testfrmwk.hpp" #include class bad_day {}; //exception type diff --git a/test/testgregorian_calendar.cpp b/test/testgregorian_calendar.cpp index 9052852..12d008c 100644 --- a/test/testgregorian_calendar.cpp +++ b/test/testgregorian_calendar.cpp @@ -1,18 +1,18 @@ -#include "boost/gdtl/gregorian_calendar.hpp" -#include "boost/gdtl/year_month_day.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/gregorian_calendar.hpp" +#include "boost/date_time/year_month_day.hpp" +#include "boost/date_time/testfrmwk.hpp" #include int main() { - typedef boost::gdtl::year_month_day_base simple_ymd_type; - typedef boost::gdtl::gregorian_calendar_base + typedef boost::date_time::gregorian_calendar_base gregorian_calendar; // using namespace boost::gregorian; diff --git a/test/testint64_range.cpp b/test/testint64_range.cpp index d08e0fc..5392d7a 100644 --- a/test/testint64_range.cpp +++ b/test/testint64_range.cpp @@ -1,13 +1,19 @@ -//#include "gdtl/testfrmwk.hpp" +//#include "date_time/testfrmwk.hpp" #include -#include "boost/gdtl/gregorian/gregorian.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include "boost/cstdint.hpp" int main() { +#if (defined(BOOST_MSVC) && (_MSC_VER <= 1200)) // 1200 == VC++ 6.0 + //skipping tests here due to lack of operator<< support in msvc6 + std::cout << "Skipping tests on MSVC6" << std::endl; + +#else + std::cout << "int64_t max: " << std::numeric_limits::max() << std::endl; @@ -68,7 +74,8 @@ main() std::cout << "remaining usec count 3M: " << remaining_usec_count3M << std::endl; - + +#endif // std::cout << "Days from: " // << to_simple_string(d1) << " to " diff --git a/test/testint_adapter.cpp b/test/testint_adapter.cpp index 4ec20a6..13eceee 100644 --- a/test/testint_adapter.cpp +++ b/test/testint_adapter.cpp @@ -1,7 +1,7 @@ -#include "boost/gdtl/int_adapter.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/int_adapter.hpp" +#include "boost/date_time/testfrmwk.hpp" #include "boost/cstdint.hpp" #include @@ -31,11 +31,11 @@ void test_int() int_type i = int_type::neg_infinity(); check("is infinity", i.is_infinity()); - check("as_special convert", boost::gdtl::neg_infin == i.as_special() ); - check("as_special convert", boost::gdtl::neg_infin == int_type::to_special(i.as_number()) ); + check("as_special convert", boost::date_time::neg_infin == i.as_special() ); + check("as_special convert", boost::date_time::neg_infin == int_type::to_special(i.as_number()) ); i = int_type::pos_infinity(); check("is infinity", i.is_infinity()); - check("as_special convert", boost::gdtl::pos_infin == i.as_special() ); + check("as_special convert", boost::date_time::pos_infin == i.as_special() ); i = 1; check("is infinity", !i.is_infinity()); int_type j = int_type::neg_infinity(); @@ -46,7 +46,7 @@ void test_int() check("infinity equal", j == j); int_type k = 1; - check("as_special convert", boost::gdtl::not_special == k.as_special() ); + check("as_special convert", boost::date_time::not_special == k.as_special() ); check("equal", i == k); check("infinity not equal", i != int_type::neg_infinity()); check("infinity not equal", i != int_type::pos_infinity()); @@ -54,7 +54,7 @@ void test_int() check("add infinity" , l == int_type::pos_infinity()); check("add 2", (i + 2) == 3); i = int_type::not_a_number(); - check("as_special convert", boost::gdtl::not_a_date_time == i.as_special() ); + check("as_special convert", boost::date_time::not_a_date_time == i.as_special() ); check("add not a number", (i + 2) == int_type::not_a_number()); check("sub not a number", (i - 2) == int_type::not_a_number()); check("sub from infin", (l - 2) == int_type::pos_infinity()); @@ -63,21 +63,21 @@ void test_int() check("sub from 5-2 ", (5 - 2) == 3); // std::cout << i.as_number() << std::endl; check("from special ", - int_type::from_special(boost::gdtl::pos_infin) == int_type::pos_infinity()); + int_type::from_special(boost::date_time::pos_infin) == int_type::pos_infinity()); check("from special ", - int_type::from_special(boost::gdtl::neg_infin) == int_type::neg_infinity()); + int_type::from_special(boost::date_time::neg_infin) == int_type::neg_infinity()); check("from special ", - int_type::from_special(boost::gdtl::not_a_date_time) == int_type::not_a_number()); + int_type::from_special(boost::date_time::not_a_date_time) == int_type::not_a_number()); check("from special ", - int_type::from_special(boost::gdtl::min_date_time) == int_type::min()); + int_type::from_special(boost::date_time::min_date_time) == int_type::min()); check("from special ", - int_type::from_special(boost::gdtl::max_date_time) == int_type::max()); + int_type::from_special(boost::date_time::max_date_time) == int_type::max()); } int main() { - using namespace boost::gdtl; + using namespace boost::date_time; print< int_adapter >(); test_int< int_adapter >(); diff --git a/test/testtime_resolution_traits.cpp b/test/testtime_resolution_traits.cpp index 1161334..749463f 100644 --- a/test/testtime_resolution_traits.cpp +++ b/test/testtime_resolution_traits.cpp @@ -1,13 +1,13 @@ -#include "boost/gdtl/time_resolution_traits.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/time_resolution_traits.hpp" +#include "boost/date_time/testfrmwk.hpp" int main() { - using namespace boost::gdtl; + using namespace boost::date_time; check("milli traits num digits", milli_res::num_fractional_digits() == 3); check("milli traits resolution adjust", milli_res::res_adjust() == 1000); diff --git a/test/testwrapping_int.cpp b/test/testwrapping_int.cpp index 0b47eab..c0a0feb 100644 --- a/test/testwrapping_int.cpp +++ b/test/testwrapping_int.cpp @@ -1,7 +1,7 @@ -#include "boost/gdtl/wrapping_int.hpp" -#include "boost/gdtl/testfrmwk.hpp" +#include "boost/date_time/wrapping_int.hpp" +#include "boost/date_time/testfrmwk.hpp" #include "boost/cstdint.hpp" #include @@ -9,7 +9,7 @@ int main() { - using namespace boost::gdtl; + using namespace boost::date_time; wrapping_int wi(3599); check("construction/conversion", wi == 3599);