Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70765 - in trunk/libs/date_time/example: gregorian local_time posix_time tutorial
From: marshall_at_[hidden]
Date: 2011-03-30 18:21:19


Author: marshall
Date: 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
New Revision: 70765
URL: http://svn.boost.org/trac/boost/changeset/70765

Log:
Updated examples - Refs #4920
Text files modified:
   trunk/libs/date_time/example/gregorian/days_between_new_years.cpp | 7 ++++---
   trunk/libs/date_time/example/gregorian/days_since_year_start.cpp | 4 ++--
   trunk/libs/date_time/example/gregorian/days_till_new_year.cpp | 2 +-
   trunk/libs/date_time/example/gregorian/month_add.cpp | 16 +++++++++++-----
   trunk/libs/date_time/example/local_time/flight.cpp | 28 +++++++++++++++++++---------
   trunk/libs/date_time/example/local_time/local_date_time.cpp | 4 ++--
   trunk/libs/date_time/example/posix_time/print_hours.cpp | 8 ++++----
   trunk/libs/date_time/example/posix_time/time_math.cpp | 2 +-
   trunk/libs/date_time/example/tutorial/io_tutorial.cpp | 2 +-
   9 files changed, 45 insertions(+), 28 deletions(-)

Modified: trunk/libs/date_time/example/gregorian/days_between_new_years.cpp
==============================================================================
--- trunk/libs/date_time/example/gregorian/days_between_new_years.cpp (original)
+++ trunk/libs/date_time/example/gregorian/days_between_new_years.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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 <iostream>
+
 #include "boost/date_time/gregorian/gregorian.hpp"
+#include <iostream>
 
 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

Modified: trunk/libs/date_time/example/gregorian/days_since_year_start.cpp
==============================================================================
--- trunk/libs/date_time/example/gregorian/days_since_year_start.cpp (original)
+++ trunk/libs/date_time/example/gregorian/days_since_year_start.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -1,6 +1,6 @@
 
-#include <iostream>
 #include "boost/date_time/gregorian/gregorian.hpp"
+#include <iostream>
 
 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

Modified: trunk/libs/date_time/example/gregorian/days_till_new_year.cpp
==============================================================================
--- trunk/libs/date_time/example/gregorian/days_till_new_year.cpp (original)
+++ trunk/libs/date_time/example/gregorian/days_till_new_year.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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

Modified: trunk/libs/date_time/example/gregorian/month_add.cpp
==============================================================================
--- trunk/libs/date_time/example/gregorian/month_add.cpp (original)
+++ trunk/libs/date_time/example/gregorian/month_add.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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";
@@ -31,14 +31,20 @@
             << std::endl;
 
   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"
+ << "dependent, non-commutative, 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;
 }

Modified: trunk/libs/date_time/example/local_time/flight.cpp
==============================================================================
--- trunk/libs/date_time/example/local_time/flight.cpp (original)
+++ trunk/libs/date_time/example/local_time/flight.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -5,7 +5,7 @@
 /* This example shows a program that calculates the arrival time of a plane
  * that flys from Phoenix to New York. During the flight New York shifts
  * into daylight savings time (Phoenix doesn't because Arizona doesn't use
- * dst).
+ * DST).
  *
  *
  */
@@ -20,24 +20,34 @@
   //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 << "arrival phx time: " << phx_arrival << std::endl;
- std::cout << "arrival nyc time: " << nyc_arrival << std::endl;
+ 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;
 
 }
 

Modified: trunk/libs/date_time/example/local_time/local_date_time.cpp
==============================================================================
--- trunk/libs/date_time/example/local_time/local_date_time.cpp (original)
+++ trunk/libs/date_time/example/local_time/local_date_time.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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;
 }

Modified: trunk/libs/date_time/example/posix_time/print_hours.cpp
==============================================================================
--- trunk/libs/date_time/example/posix_time/print_hours.cpp (original)
+++ trunk/libs/date_time/example/posix_time/print_hours.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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;

Modified: trunk/libs/date_time/example/posix_time/time_math.cpp
==============================================================================
--- trunk/libs/date_time/example/posix_time/time_math.cpp (original)
+++ trunk/libs/date_time/example/posix_time/time_math.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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);

Modified: trunk/libs/date_time/example/tutorial/io_tutorial.cpp
==============================================================================
--- trunk/libs/date_time/example/tutorial/io_tutorial.cpp (original)
+++ trunk/libs/date_time/example/tutorial/io_tutorial.cpp 2011-03-30 18:21:18 EDT (Wed, 30 Mar 2011)
@@ -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("");


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