Ticket #4920: examples.diff

File examples.diff, 8.2 KB (added by Katie Chan, 12 years ago)
  • gregorian/days_between_new_years.cpp

     
    33 * New Years day of this year, and days until next New Years day.
    44 *
    55 * Expected results:
    6  * Adding together both durations will produce 366 (365 in a leap year).
     6 * Adding together both durations will produce 365 (366 in a leap year).
    77 */
     8
     9#include "boost/date_time/gregorian/gregorian.hpp"
    810#include <iostream>
    9 #include "boost/date_time/gregorian/gregorian.hpp"
    1011
    1112int
    1213main()
     
    2526  std::cout << "Days until next Jan 1: " << days_until_year_start.days()
    2627            << std::endl;
    2728  return 0;
    28 };
     29}
    2930
    3031
    3132/*  Copyright 2001-2004: CrystalClear Software, Inc
  • gregorian/days_since_year_start.cpp

     
    11
     2#include "boost/date_time/gregorian/gregorian.hpp"
    23#include <iostream>
    3 #include "boost/date_time/gregorian/gregorian.hpp"
    44
    55int
    66main()
     
    1414  std::cout << "Days since Jan 1: " << days_since_year_start.days()
    1515            << std::endl;
    1616  return 0;
    17 };
     17}
    1818
    1919/*  Copyright 2001-2004: CrystalClear Software, Inc
    2020 *  http://www.crystalclearsoftware.com
  • gregorian/days_till_new_year.cpp

     
    1515 
    1616  std::cout << "Days till new year: " << dd.days() << std::endl;
    1717  return 0;
    18 };
     18}
    1919
    2020/*  Copyright 2001-2004: CrystalClear Software, Inc
    2121 *  http://www.crystalclearsoftware.com
  • gregorian/month_add.cpp

     
    1717  date d2 = d + months(1);
    1818  date d3 = d - months(1);
    1919  std::cout << "Today is: " << to_simple_string(d) << ".\n"
    20             << "One month from today will be: " << to_simple_string(d2)
     20            << "One month from today will be: " << to_simple_string(d2) << ".\n"
    2121            << "One month ago was: " << to_simple_string(d3)
    2222            << std::endl;
    2323  std::cout << "******** Warning read this ***********************\n";
     
    3333  std::cout << "\nSo what does this mean?  It means the result of adding months is order\n"
    3434            << "dependent, non-communitive, and may create problems for applications.\n"
    3535            << "Consider: \n"
    36             << "Jan 30, 2004 + (1 month) + (1 month) != Jan 29, 2004 + (2 months)\n"
    37             << "Why not? Because Jan 30, 2004 + 1 month is Feb 29 + 1 month is Mar 29th.\n"
    38             << "while Jan 30, 2004 + 2 months is Mar 29th.\n"
     36            << "Jan 30, 2004 + (1 month) + (1 month) != Jan 30, 2004 + (2 months)\n"
     37            << "Why not? Because Jan 30, 2004 + 1 month is Feb 29 + 1 month is Mar 31st.\n"
     38            << "while Jan 30, 2004 + 2 months is Mar 30th.\n"
    3939            << "All of this clears up as long as all the starting dates before the 28th of\n"
    4040            << "the month -- then all the behavior follows classical mathematical rules.\n";
    4141 
     42  date d6(2004, Jan, 30);
     43  date d7 = d6 + months(1) + months(1);
     44  date d8 = d6 + months(2);
     45  std::cout << "2004-01-30 + (1 month) + (1 month) is: " << to_simple_string(d7) << ".\n"
     46            << "2004-01-30 + (2 months) is: " << to_simple_string(d8)
     47                        << std::endl;
    4248
    4349  return 0;
    4450}
  • local_time/flight.cpp

     
    2020  //setup some timezones for creating and adjusting local times
    2121  //This user editable file can be found in libs/date_time/data.
    2222  tz_database tz_db;
    23   tz_db.load_from_file("date_time_zonespec.csv");
     23  try {
     24    tz_db.load_from_file("../../data/date_time_zonespec.csv");
     25  }catch(data_not_accessible dna) {
     26    std::cerr << "Error with time zone data file: " << dna.what() << std::endl;
     27    exit(EXIT_FAILURE);
     28  }catch(bad_field_count bfc) {
     29    std::cerr << "Error with time zone data file: " << bfc.what() << std::endl;
     30    exit(EXIT_FAILURE);
     31  }
    2432  time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York");
    25   //Use a
     33  //Use a newly created time zone rule
    2634  time_zone_ptr phx_tz(new posix_time_zone("MST-07:00:00"));
    2735
    28   //local departure time in phoenix is 11 pm on april 2 2005
    29   // (ny changes to dst on apr 3 at 2 am)
    30   local_date_time phx_departure(date(2005, Apr, 2), hours(23),
     36  //local departure time in phoenix is 11 pm on march 13 2010
     37  // (ny changes to dst on march 14 at 2 am)
     38  local_date_time phx_departure(date(2010, Mar, 13), hours(23),
    3139                                phx_tz,
    3240                                local_date_time::NOT_DATE_TIME_ON_ERROR);
     41  local_date_time nyc_departure = phx_departure.local_time_in(nyc_tz);
    3342
    3443  time_duration flight_length = hours(4) + minutes(30);
    3544  local_date_time phx_arrival = phx_departure + flight_length;
    3645  local_date_time nyc_arrival = phx_arrival.local_time_in(nyc_tz);
    3746
    3847  std::cout << "departure phx time: " << phx_departure << std::endl;
     48  std::cout << "departure nyc time: " << nyc_departure << std::endl;
    3949  std::cout << "arrival phx time:   " << phx_arrival << std::endl;
    4050  std::cout << "arrival nyc time:   " << nyc_arrival << std::endl;
    4151
  • local_time/local_date_time.cpp

     
    2828  std::locale loc(std::locale::classic(), timefacet);
    2929 
    3030  std::cout << ny_time << std::endl;
    31   // 2004-Aug-30 00:00:00 EDT
     31  // 2004-Aug-30 10:00:00 EDT
    3232  std::cout.imbue(loc);
    3333  std::cout << ny_time << std::endl;
    34   // 2004-Aug-30 00:00:00 Eastern Daylight Time
     34  // 2004-Aug-30 10:00:00 Eastern Daylight Time
    3535
    3636  return 0;
    3737}
  • posix_time/print_hours.cpp

     
    2929  ptime now = second_clock::local_time();
    3030  //Get the date part out of the time
    3131  date today = now.date();
    32   date tommorrow = today + days(1);
    33   ptime tommorrow_start(tommorrow); //midnight
     32  date tomorrow = today + days(1);
     33  ptime tomorrow_start(tomorrow); //midnight
    3434
    3535  //iterator adds by one hour
    3636  time_iterator titr(now,hours(1));
    37   for (; titr < tommorrow_start; ++titr) {
     37  for (; titr < tomorrow_start; ++titr) {
    3838    std::cout << to_simple_string(*titr) << std::endl;
    3939  }
    4040 
    41   time_duration remaining = tommorrow_start - now;
     41  time_duration remaining = tomorrow_start - now;
    4242  std::cout << "Time left till midnight: "
    4343            << to_simple_string(remaining) << std::endl;
    4444  return 0;
  • posix_time/time_math.cpp

     
    1313  using namespace boost::gregorian;
    1414
    1515  date d(2002,Feb,1); //an arbitrary date
    16   //construct a time by adding up some durations durations
     16  //construct a time by adding up some durations
    1717  ptime t1(d, hours(5)+minutes(4)+seconds(2)+milliseconds(1));
    1818  //construct a new time by subtracting some times
    1919  ptime t2 = t1 - hours(5)- minutes(4)- seconds(2)- milliseconds(1);
  • tutorial/io_tutorial.cpp

     
    141141  period_formatter per_formatter(period_formatter::AS_OPEN_RANGE,
    142142                                 " to ", "from ", " exclusive", " inclusive" );
    143143  period_parser per_parser(period_parser::AS_OPEN_RANGE,
    144                            " to ", "from ", " exclusive" , "inclusive" );
     144                           " to ", "from ", " exclusive" , " inclusive" );
    145145 
    146146  // default output
    147147  ss.str("");