Index: gregorian/days_between_new_years.cpp =================================================================== --- gregorian/days_between_new_years.cpp (revision 66939) +++ gregorian/days_between_new_years.cpp (working copy) @@ -3,10 +3,11 @@ * New Years day of this year, and days until next New Years day. * * Expected results: - * Adding together both durations will produce 366 (365 in a leap year). + * Adding together both durations will produce 365 (366 in a leap year). */ + +#include "boost/date_time/gregorian/gregorian.hpp" #include -#include "boost/date_time/gregorian/gregorian.hpp" int main() @@ -25,7 +26,7 @@ std::cout << "Days until next Jan 1: " << days_until_year_start.days() << std::endl; return 0; -}; +} /* Copyright 2001-2004: CrystalClear Software, Inc Index: gregorian/days_since_year_start.cpp =================================================================== --- gregorian/days_since_year_start.cpp (revision 66939) +++ gregorian/days_since_year_start.cpp (working copy) @@ -1,6 +1,6 @@ +#include "boost/date_time/gregorian/gregorian.hpp" #include -#include "boost/date_time/gregorian/gregorian.hpp" int main() @@ -14,7 +14,7 @@ std::cout << "Days since Jan 1: " << days_since_year_start.days() << std::endl; return 0; -}; +} /* Copyright 2001-2004: CrystalClear Software, Inc * http://www.crystalclearsoftware.com Index: gregorian/days_till_new_year.cpp =================================================================== --- gregorian/days_till_new_year.cpp (revision 66939) +++ gregorian/days_till_new_year.cpp (working copy) @@ -15,7 +15,7 @@ std::cout << "Days till new year: " << dd.days() << std::endl; return 0; -}; +} /* Copyright 2001-2004: CrystalClear Software, Inc * http://www.crystalclearsoftware.com Index: gregorian/month_add.cpp =================================================================== --- gregorian/month_add.cpp (revision 66939) +++ gregorian/month_add.cpp (working copy) @@ -17,7 +17,7 @@ date d2 = d + months(1); date d3 = d - months(1); std::cout << "Today is: " << to_simple_string(d) << ".\n" - << "One month from today will be: " << to_simple_string(d2) + << "One month from today will be: " << to_simple_string(d2) << ".\n" << "One month ago was: " << to_simple_string(d3) << std::endl; std::cout << "******** Warning read this ***********************\n"; @@ -33,12 +33,18 @@ std::cout << "\nSo what does this mean? It means the result of adding months is order\n" << "dependent, non-communitive, and may create problems for applications.\n" << "Consider: \n" - << "Jan 30, 2004 + (1 month) + (1 month) != Jan 29, 2004 + (2 months)\n" - << "Why not? Because Jan 30, 2004 + 1 month is Feb 29 + 1 month is Mar 29th.\n" - << "while Jan 30, 2004 + 2 months is Mar 29th.\n" + << "Jan 30, 2004 + (1 month) + (1 month) != Jan 30, 2004 + (2 months)\n" + << "Why not? Because Jan 30, 2004 + 1 month is Feb 29 + 1 month is Mar 31st.\n" + << "while Jan 30, 2004 + 2 months is Mar 30th.\n" << "All of this clears up as long as all the starting dates before the 28th of\n" << "the month -- then all the behavior follows classical mathematical rules.\n"; + date d6(2004, Jan, 30); + date d7 = d6 + months(1) + months(1); + date d8 = d6 + months(2); + std::cout << "2004-01-30 + (1 month) + (1 month) is: " << to_simple_string(d7) << ".\n" + << "2004-01-30 + (2 months) is: " << to_simple_string(d8) + << std::endl; return 0; } Index: local_time/flight.cpp =================================================================== --- local_time/flight.cpp (revision 66939) +++ local_time/flight.cpp (working copy) @@ -20,22 +20,32 @@ //setup some timezones for creating and adjusting local times //This user editable file can be found in libs/date_time/data. tz_database tz_db; - tz_db.load_from_file("date_time_zonespec.csv"); + try { + tz_db.load_from_file("../../data/date_time_zonespec.csv"); + }catch(data_not_accessible dna) { + std::cerr << "Error with time zone data file: " << dna.what() << std::endl; + exit(EXIT_FAILURE); + }catch(bad_field_count bfc) { + std::cerr << "Error with time zone data file: " << bfc.what() << std::endl; + exit(EXIT_FAILURE); + } time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York"); - //Use a + //Use a newly created time zone rule time_zone_ptr phx_tz(new posix_time_zone("MST-07:00:00")); - //local departure time in phoenix is 11 pm on april 2 2005 - // (ny changes to dst on apr 3 at 2 am) - local_date_time phx_departure(date(2005, Apr, 2), hours(23), + //local departure time in phoenix is 11 pm on march 13 2010 + // (ny changes to dst on march 14 at 2 am) + local_date_time phx_departure(date(2010, Mar, 13), hours(23), phx_tz, local_date_time::NOT_DATE_TIME_ON_ERROR); + local_date_time nyc_departure = phx_departure.local_time_in(nyc_tz); time_duration flight_length = hours(4) + minutes(30); local_date_time phx_arrival = phx_departure + flight_length; local_date_time nyc_arrival = phx_arrival.local_time_in(nyc_tz); std::cout << "departure phx time: " << phx_departure << std::endl; + std::cout << "departure nyc time: " << nyc_departure << std::endl; std::cout << "arrival phx time: " << phx_arrival << std::endl; std::cout << "arrival nyc time: " << nyc_arrival << std::endl; Index: local_time/local_date_time.cpp =================================================================== --- local_time/local_date_time.cpp (revision 66939) +++ local_time/local_date_time.cpp (working copy) @@ -28,10 +28,10 @@ std::locale loc(std::locale::classic(), timefacet); std::cout << ny_time << std::endl; - // 2004-Aug-30 00:00:00 EDT + // 2004-Aug-30 10:00:00 EDT std::cout.imbue(loc); std::cout << ny_time << std::endl; - // 2004-Aug-30 00:00:00 Eastern Daylight Time + // 2004-Aug-30 10:00:00 Eastern Daylight Time return 0; } Index: posix_time/print_hours.cpp =================================================================== --- posix_time/print_hours.cpp (revision 66939) +++ posix_time/print_hours.cpp (working copy) @@ -29,16 +29,16 @@ ptime now = second_clock::local_time(); //Get the date part out of the time date today = now.date(); - date tommorrow = today + days(1); - ptime tommorrow_start(tommorrow); //midnight + date tomorrow = today + days(1); + ptime tomorrow_start(tomorrow); //midnight //iterator adds by one hour time_iterator titr(now,hours(1)); - for (; titr < tommorrow_start; ++titr) { + for (; titr < tomorrow_start; ++titr) { std::cout << to_simple_string(*titr) << std::endl; } - time_duration remaining = tommorrow_start - now; + time_duration remaining = tomorrow_start - now; std::cout << "Time left till midnight: " << to_simple_string(remaining) << std::endl; return 0; Index: posix_time/time_math.cpp =================================================================== --- posix_time/time_math.cpp (revision 66939) +++ posix_time/time_math.cpp (working copy) @@ -13,7 +13,7 @@ using namespace boost::gregorian; date d(2002,Feb,1); //an arbitrary date - //construct a time by adding up some durations durations + //construct a time by adding up some durations ptime t1(d, hours(5)+minutes(4)+seconds(2)+milliseconds(1)); //construct a new time by subtracting some times ptime t2 = t1 - hours(5)- minutes(4)- seconds(2)- milliseconds(1); Index: tutorial/io_tutorial.cpp =================================================================== --- tutorial/io_tutorial.cpp (revision 66939) +++ tutorial/io_tutorial.cpp (working copy) @@ -141,7 +141,7 @@ period_formatter per_formatter(period_formatter::AS_OPEN_RANGE, " to ", "from ", " exclusive", " inclusive" ); period_parser per_parser(period_parser::AS_OPEN_RANGE, - " to ", "from ", " exclusive" , "inclusive" ); + " to ", "from ", " exclusive" , " inclusive" ); // default output ss.str("");