Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56456 - in branches/release: boost/date_time boost/date_time/gregorian boost/date_time/local_time boost/date_time/posix_time libs/date_time/test/gregorian
From: andrey.semashev_at_[hidden]
Date: 2009-09-28 14:10:03


Author: andysem
Date: 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
New Revision: 56456
URL: http://svn.boost.org/trac/boost/changeset/56456

Log:
Fixes #3308. Also added some missing includes.
Text files modified:
   branches/release/boost/date_time/date.hpp | 23 ++++++--
   branches/release/boost/date_time/gregorian/greg_calendar.hpp | 13 ++--
   branches/release/boost/date_time/gregorian/greg_date.hpp | 2
   branches/release/boost/date_time/gregorian_calendar.hpp | 4
   branches/release/boost/date_time/gregorian_calendar.ipp | 4
   branches/release/boost/date_time/local_time/local_date_time.hpp | 1
   branches/release/boost/date_time/posix_time/conversion.hpp | 11 ++-
   branches/release/boost/date_time/posix_time/time_formatters.hpp | 16 +++---
   branches/release/boost/date_time/posix_time/time_formatters_limited.hpp | 13 ++--
   branches/release/boost/date_time/time_facet.hpp | 1
   branches/release/libs/date_time/test/gregorian/testdate.cpp | 104 ++++++++++++++++++++--------------------
   11 files changed, 104 insertions(+), 88 deletions(-)

Modified: branches/release/boost/date_time/date.hpp
==============================================================================
--- branches/release/boost/date_time/date.hpp (original)
+++ branches/release/boost/date_time/date.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -9,9 +9,9 @@
  * $Date$
  */
 
-#include "boost/date_time/year_month_day.hpp"
-#include "boost/date_time/special_defs.hpp"
-#include "boost/operators.hpp"
+#include <boost/operators.hpp>
+#include <boost/date_time/year_month_day.hpp>
+#include <boost/date_time/special_defs.hpp>
 
 namespace boost {
 namespace date_time {
@@ -138,8 +138,19 @@
     }
     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());
+ if (!this->is_special() && !d.is_special())
+ {
+ // The duration underlying type may be wider than the date underlying type.
+ // Thus we calculate the difference in terms of two durations from some common fixed base date.
+ typedef typename duration_type::duration_rep_type duration_rep_type;
+ return duration_type(static_cast< duration_rep_type >(days_) - static_cast< duration_rep_type >(d.days_));
+ }
+ else
+ {
+ // In this case the difference will be a special value, too
+ date_rep_type val = date_rep_type(days_) - date_rep_type(d.days_);
+ return duration_type(val.as_special());
+ }
     }
     
     date_type operator-(const duration_type& dd) const
@@ -158,7 +169,7 @@
     date_rep_type day_count() const
     {
       return days_;
- };
+ }
     //allow internal access from operators
     date_type operator+(const duration_type& dd) const
     {

Modified: branches/release/boost/date_time/gregorian/greg_calendar.hpp
==============================================================================
--- branches/release/boost/date_time/gregorian/greg_calendar.hpp (original)
+++ branches/release/boost/date_time/gregorian/greg_calendar.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -9,17 +9,18 @@
  * $Date$
  */
 
-#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"
+#include <boost/cstdint.hpp>
+#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<unsigned long> fancy_date_rep;
+ typedef date_time::int_adapter<uint32_t> fancy_date_rep;
 
   //! Gregorian calendar for this implementation, hard work in the base
   class gregorian_calendar :

Modified: branches/release/boost/date_time/gregorian/greg_date.hpp
==============================================================================
--- branches/release/boost/date_time/gregorian/greg_date.hpp (original)
+++ branches/release/boost/date_time/gregorian/greg_date.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -99,7 +99,7 @@
       return day_of_year_type(doy);
     }
     //!Return the Modified Julian Day number for the date.
- long modjulian_day() const
+ date_int_type modjulian_day() const
     {
       ymd_type ymd = year_month_day();
       return gregorian_calendar::modjulian_day_number(ymd);

Modified: branches/release/boost/date_time/gregorian_calendar.hpp
==============================================================================
--- branches/release/boost/date_time/gregorian_calendar.hpp (original)
+++ branches/release/boost/date_time/gregorian_calendar.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -44,10 +44,10 @@
     //static unsigned short day_of_year(date_int_type);
     static date_int_type day_number(const ymd_type& ymd);
     static date_int_type julian_day_number(const ymd_type& ymd);
- static long modjulian_day_number(const ymd_type& ymd);
+ static date_int_type modjulian_day_number(const ymd_type& ymd);
     static ymd_type from_day_number(date_int_type);
     static ymd_type from_julian_day_number(date_int_type);
- static ymd_type from_modjulian_day_number(long);
+ static ymd_type from_modjulian_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();

Modified: branches/release/boost/date_time/gregorian_calendar.ipp
==============================================================================
--- branches/release/boost/date_time/gregorian_calendar.ipp (original)
+++ branches/release/boost/date_time/gregorian_calendar.ipp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -99,7 +99,7 @@
    */
   template<typename ymd_type_, typename date_int_type_>
   BOOST_DATE_TIME_INLINE
- long
+ date_int_type_
   gregorian_calendar_base<ymd_type_,date_int_type_>::modjulian_day_number(const ymd_type& ymd)
   {
     return julian_day_number(ymd)-2400001; //prerounded
@@ -149,7 +149,7 @@
   template<typename ymd_type_, typename date_int_type_>
   BOOST_DATE_TIME_INLINE
   ymd_type_
- gregorian_calendar_base<ymd_type_,date_int_type_>::from_modjulian_day_number(long dayNumber) {
+ gregorian_calendar_base<ymd_type_,date_int_type_>::from_modjulian_day_number(date_int_type dayNumber) {
     date_int_type jd = dayNumber + 2400001; //is 2400000.5 prerounded
     return from_julian_day_number(jd);
   }

Modified: branches/release/boost/date_time/local_time/local_date_time.hpp
==============================================================================
--- branches/release/boost/date_time/local_time/local_date_time.hpp (original)
+++ branches/release/boost/date_time/local_time/local_date_time.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -19,6 +19,7 @@
 #include <boost/date_time/dst_rules.hpp>
 #include <boost/date_time/time_zone_base.hpp>
 #include <boost/date_time/special_defs.hpp>
+#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
 
 namespace boost {
 namespace local_time {

Modified: branches/release/boost/date_time/posix_time/conversion.hpp
==============================================================================
--- branches/release/boost/date_time/posix_time/conversion.hpp (original)
+++ branches/release/boost/date_time/posix_time/conversion.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -9,11 +9,12 @@
  * $Date$
  */
 
-#include "boost/date_time/posix_time/ptime.hpp"
-#include "boost/date_time/posix_time/posix_time_duration.hpp"
-#include "boost/date_time/filetime_functions.hpp"
-#include "boost/date_time/c_time.hpp"
-#include "boost/date_time/gregorian/conversion.hpp"
+#include <boost/date_time/posix_time/ptime.hpp>
+#include <boost/date_time/posix_time/posix_time_duration.hpp>
+#include <boost/date_time/filetime_functions.hpp>
+#include <boost/date_time/c_time.hpp>
+#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
+#include <boost/date_time/gregorian/conversion.hpp>
 
 namespace boost {
 

Modified: branches/release/boost/date_time/posix_time/time_formatters.hpp
==============================================================================
--- branches/release/boost/date_time/posix_time/time_formatters.hpp (original)
+++ branches/release/boost/date_time/posix_time/time_formatters.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -9,14 +9,14 @@
  * $Date$
  */
 
-#include "boost/date_time/gregorian/gregorian.hpp"
-#include "boost/date_time/compiler_config.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"
-#include "boost/date_time/time_formatting_streams.hpp"
-
-#include "boost/date_time/time_parsing.hpp"
+#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/date_time/compiler_config.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>
+#include <boost/date_time/time_formatting_streams.hpp>
+#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
+#include <boost/date_time/time_parsing.hpp>
 
 /* NOTE: The "to_*_string" code for older compilers, ones that define
  * BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS, is located in

Modified: branches/release/boost/date_time/posix_time/time_formatters_limited.hpp
==============================================================================
--- branches/release/boost/date_time/posix_time/time_formatters_limited.hpp (original)
+++ branches/release/boost/date_time/posix_time/time_formatters_limited.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -9,12 +9,13 @@
  * $Date$
  */
 
-#include "boost/date_time/gregorian/gregorian.hpp"
-#include "boost/date_time/compiler_config.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"
-#include "boost/date_time/time_formatting_streams.hpp"
+#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/date_time/compiler_config.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>
+#include <boost/date_time/time_formatting_streams.hpp>
+#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
  
 namespace boost {
 

Modified: branches/release/boost/date_time/time_facet.hpp
==============================================================================
--- branches/release/boost/date_time/time_facet.hpp (original)
+++ branches/release/boost/date_time/time_facet.hpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -27,6 +27,7 @@
 #include <boost/date_time/date_facet.hpp>
 #include <boost/date_time/string_convert.hpp>
 #include <boost/date_time/special_defs.hpp>
+#include <boost/date_time/time_resolution_traits.hpp> // absolute_value
 
 namespace boost {
 namespace date_time {

Modified: branches/release/libs/date_time/test/gregorian/testdate.cpp
==============================================================================
--- branches/release/libs/date_time/test/gregorian/testdate.cpp (original)
+++ branches/release/libs/date_time/test/gregorian/testdate.cpp 2009-09-28 14:10:02 EDT (Mon, 28 Sep 2009)
@@ -31,12 +31,12 @@
   check("month_rep constructor", d4 == d4a);
   //std::cout << d3 << std::endl;
   //retrieval functions
- check("1900-01-01 day is 01", d1.day() == 1);
- check("1900-01-01 month is 01", d1.month() == 1);
- check("1900-01-01 year is 1900", d1.year() == 1900);
- check("2000-12-31 day is 31", d4.day() == 31);
- check("2000-12-31 month is 12", d4.month() == 12);
- check("2000-12-31 year is 2000", d4.year() == 2000);
+ check_equal("1900-01-01 day is 01", d1.day(), 1);
+ check_equal("1900-01-01 month is 01", d1.month(), 1);
+ check_equal("1900-01-01 year is 1900", d1.year(), 1900);
+ check_equal("2000-12-31 day is 31", d4.day(), 31);
+ check_equal("2000-12-31 month is 12", d4.month(), 12);
+ check_equal("2000-12-31 year is 2000", d4.year(), 2000);
   //operator<
   check("1900-01-01 is less than 2000-01-01", d1 < d2);
   check("2000-01-01 is NOT less than 2000-01-01", !(d1 < d1));
@@ -50,14 +50,14 @@
   //operator!=
   check("2000-01-01 is NOT equal to 1900-01-01", d2 != d1);
   //operator==
- check("2000-01-01 is equal 2000-01-01", d3 == d2);
+ check_equal("2000-01-01 is equal 2000-01-01", d3, d2);
   check("2000-01-01 is greater equal 2000-01-01", d3 >= d2);
   check("2000-01-01 is greater equal 2000-01-01", d3 <= d2);
 
   date::ymd_type ymd = d1.year_month_day();
- check("ymd year", ymd.year == 1900);
- check("ymd month", ymd.month == 1);
- check("ymd day", ymd.day == 1);
+ check_equal("ymd year", ymd.year, 1900);
+ check_equal("ymd month", ymd.month, 1);
+ check_equal("ymd day", ymd.day, 1);
   
   //The max function will not compile with Borland 5.5
   //Complains about must specialize basic_data<limits> ???
@@ -90,13 +90,13 @@
   date_duration twoDays(2);
   date_duration negtwoDays(-2);
   date_duration zeroDays(0);
- check("2000-03-01 - 2000-02-28 == 2 days", twoDays == (d7-d6));
- check("2000-02-28 - 2000-03-01 == - 2 days", negtwoDays == (d6-d7));
- check("2000-02-28 - 2000-02-28 == 0 days", zeroDays == (d6-d6));
- check("2000-02-28 + 2 days == 2000-03-01 ", d6 + twoDays == d7);
- check("2000-03-01 - 2 days == 2000-02-28 ", d7 - twoDays == d6);
- check("Add duration to date", date(1999,1,1) + date_duration(365) == date(2000,1,1));
- check("Add zero days", date(1999,1,1) + zeroDays == date(1999,1,1));
+ check_equal("2000-03-01 - 2000-02-28 == 2 days", twoDays, (d7-d6));
+ check_equal("2000-02-28 - 2000-03-01 == - 2 days", negtwoDays, (d6-d7));
+ check_equal("2000-02-28 - 2000-02-28 == 0 days", zeroDays, (d6-d6));
+ check_equal("2000-02-28 + 2 days == 2000-03-01 ", d6 + twoDays, d7);
+ check_equal("2000-03-01 - 2 days == 2000-02-28 ", d7 - twoDays, d6);
+ check_equal("Add duration to date", date(1999,1,1) + date_duration(365), date(2000,1,1));
+ check_equal("Add zero days", date(1999,1,1) + zeroDays, date(1999,1,1));
   //can't do this...
   //check("Add date to duration", date_duration(365) + date(1999,1,1) == date(2000,1,1));
 
@@ -117,16 +117,16 @@
   {
     date d(2003,Oct,31);
     date_duration dd1(pos_infin), dd2(neg_infin), dd3(not_a_date_time);
- check("date + inf_dur", d + dd1 == date(pos_infin));
- check("date + inf_dur", d + dd2 == date(neg_infin));
- check("date + nan_dur", d + dd3 == date(not_a_date_time));
- check("date - inf_dur", d - dd1 == date(neg_infin));
- check("date - inf_dur", d - dd2 == date(pos_infin));
- check("date - nan_dur", d - dd3 == date(not_a_date_time));
- check("inf_date + inf_dur", date(pos_infin) + dd1 == date(pos_infin));
- check("inf_date - inf_dur", date(pos_infin) - dd1 == date(not_a_date_time));
- check("inf_date + inf_dur", date(neg_infin) + dd1 == date(not_a_date_time));
- check("inf_date - inf_dur", date(neg_infin) - dd1 == date(neg_infin));
+ check_equal("date + inf_dur", d + dd1, date(pos_infin));
+ check_equal("date + inf_dur", d + dd2, date(neg_infin));
+ check_equal("date + nan_dur", d + dd3, date(not_a_date_time));
+ check_equal("date - inf_dur", d - dd1, date(neg_infin));
+ check_equal("date - inf_dur", d - dd2, date(pos_infin));
+ check_equal("date - nan_dur", d - dd3, date(not_a_date_time));
+ check_equal("inf_date + inf_dur", date(pos_infin) + dd1, date(pos_infin));
+ check_equal("inf_date - inf_dur", date(pos_infin) - dd1, date(not_a_date_time));
+ check_equal("inf_date + inf_dur", date(neg_infin) + dd1, date(not_a_date_time));
+ check_equal("inf_date - inf_dur", date(neg_infin) - dd1, date(neg_infin));
   }
 
 
@@ -213,12 +213,12 @@
   check("check infinity nad compare ", d12 != d11);
   date d13(max_date_time);
   check("check infinity - max compare ", d13 < d11);
- check("max date_time value ", d13 == date(9999,Dec, 31));
+ check_equal("max date_time value ", d13, date(9999,Dec, 31));
   std::cout << to_simple_string(d13) << std::endl;
   date d14(min_date_time);
   check("check infinity - min compare ", d14 > d10);
   std::cout << to_simple_string(d14) << std::endl;
- check("min date_time value ", d14 == date(1400,Jan, 1));
+ check_equal("min date_time value ", d14, date(1400,Jan, 1));
 
  
   date d15(1400,1,1);
@@ -227,44 +227,44 @@
 
   // most of this testing is in the gregorian_calendar tests
   std::cout << d15.julian_day() << std::endl;
- check("check julian day ", d15.julian_day() == 2232400);
- check("check modjulian day ", d15.modjulian_day() == -167601);
+ check_equal("check julian day ", d15.julian_day(), 2232400);
+ check_equal("check modjulian day ", d15.modjulian_day(), -167601);
   date d16(2004,2,29);
- check("check julian day ", d16.julian_day() == 2453065);
- check("check modjulian day ", d16.modjulian_day() == 53064);
+ check_equal("check julian day ", d16.julian_day(), 2453065);
+ check_equal("check modjulian day ", d16.modjulian_day(), 53064);
 
   // most of this testing is in the gregorian_calendar tests
   date d31(2000, Jun, 1);
- check("check iso week number ", d31.week_number() == 22);
+ check_equal("check iso week number ", d31.week_number(), 22);
   date d32(2000, Aug, 1);
- check("check iso week number ", d32.week_number() == 31);
+ check_equal("check iso week number ", d32.week_number(), 31);
   date d33(2000, Oct, 1);
- check("check iso week number ", d33.week_number() == 39);
+ check_equal("check iso week number ", d33.week_number(), 39);
   date d34(2000, Dec, 1);
- check("check iso week number ", d34.week_number() == 48);
+ check_equal("check iso week number ", d34.week_number(), 48);
   date d35(2000, Dec, 24);
- check("check iso week number ", d35.week_number() == 51);
+ check_equal("check iso week number ", d35.week_number(), 51);
   date d36(2000, Dec, 25);
- check("check iso week number ", d36.week_number() == 52);
+ check_equal("check iso week number ", d36.week_number(), 52);
   date d37(2000, Dec, 31);
- check("check iso week number ", d37.week_number() == 52);
+ check_equal("check iso week number ", d37.week_number(), 52);
   date d38(2001, Jan, 1);
- check("check iso week number ", d38.week_number() == 1);
+ check_equal("check iso week number ", d38.week_number(), 1);
 
   try {
     int dayofyear1 = d38.day_of_year();
- check("check day of year number", dayofyear1 == 1);
- check("check day of year number", d37.day_of_year() == 366);
+ check_equal("check day of year number", dayofyear1, 1);
+ check_equal("check day of year number", d37.day_of_year(), 366);
     date d39(2001,Dec,31);
- check("check day of year number", d39.day_of_year() == 365);
+ check_equal("check day of year number", d39.day_of_year(), 365);
     date d40(2000,Feb,29);
- check("check day of year number", d40.day_of_year() == 60);
+ check_equal("check day of year number", d40.day_of_year(), 60);
     date d41(1400,Jan,1);
- check("check day of year number", d41.day_of_year() == 1);
+ check_equal("check day of year number", d41.day_of_year(), 1);
     date d42(1400,Jan,1);
- check("check day of year number", d42.day_of_year() == 1);
+ check_equal("check day of year number", d42.day_of_year(), 1);
     date d43(2002,Nov,17);
- check("check day of year number", d43.day_of_year() == 321);
+ check_equal("check day of year number", d43.day_of_year(), 321);
   }
   catch(std::exception& e) {
     std::cout << e.what() << std::endl;
@@ -272,10 +272,10 @@
   }
 
   //converts to date and back -- should get same result
- check("tm conversion functions 2000-1-1", date_from_tm(to_tm(d)) == d);
- check("tm conversion functions 1900-1-1", date_from_tm(to_tm(d1)) == d1);
- check("tm conversion functions min date 1400-1-1 ", date_from_tm(to_tm(d14)) == d14);
- check("tm conversion functions max date 9999-12-31", date_from_tm(to_tm(d13)) == d13);
+ check_equal("tm conversion functions 2000-1-1", date_from_tm(to_tm(d)), d);
+ check_equal("tm conversion functions 1900-1-1", date_from_tm(to_tm(d1)), d1);
+ check_equal("tm conversion functions min date 1400-1-1 ", date_from_tm(to_tm(d14)), d14);
+ check_equal("tm conversion functions max date 9999-12-31", date_from_tm(to_tm(d13)), d13);
 
   try{
     date d(neg_infin);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk