Ticket #4920: examples.diff
File examples.diff, 8.2 KB (added by , 12 years ago) |
---|
-
gregorian/days_between_new_years.cpp
3 3 * New Years day of this year, and days until next New Years day. 4 4 * 5 5 * Expected results: 6 * Adding together both durations will produce 36 6 (365in a leap year).6 * Adding together both durations will produce 365 (366 in a leap year). 7 7 */ 8 9 #include "boost/date_time/gregorian/gregorian.hpp" 8 10 #include <iostream> 9 #include "boost/date_time/gregorian/gregorian.hpp"10 11 11 12 int 12 13 main() … … 25 26 std::cout << "Days until next Jan 1: " << days_until_year_start.days() 26 27 << std::endl; 27 28 return 0; 28 } ;29 } 29 30 30 31 31 32 /* Copyright 2001-2004: CrystalClear Software, Inc -
gregorian/days_since_year_start.cpp
1 1 2 #include "boost/date_time/gregorian/gregorian.hpp" 2 3 #include <iostream> 3 #include "boost/date_time/gregorian/gregorian.hpp"4 4 5 5 int 6 6 main() … … 14 14 std::cout << "Days since Jan 1: " << days_since_year_start.days() 15 15 << std::endl; 16 16 return 0; 17 } ;17 } 18 18 19 19 /* Copyright 2001-2004: CrystalClear Software, Inc 20 20 * http://www.crystalclearsoftware.com -
gregorian/days_till_new_year.cpp
15 15 16 16 std::cout << "Days till new year: " << dd.days() << std::endl; 17 17 return 0; 18 } ;18 } 19 19 20 20 /* Copyright 2001-2004: CrystalClear Software, Inc 21 21 * http://www.crystalclearsoftware.com -
gregorian/month_add.cpp
17 17 date d2 = d + months(1); 18 18 date d3 = d - months(1); 19 19 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" 21 21 << "One month ago was: " << to_simple_string(d3) 22 22 << std::endl; 23 23 std::cout << "******** Warning read this ***********************\n"; … … 33 33 std::cout << "\nSo what does this mean? It means the result of adding months is order\n" 34 34 << "dependent, non-communitive, and may create problems for applications.\n" 35 35 << "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" 39 39 << "All of this clears up as long as all the starting dates before the 28th of\n" 40 40 << "the month -- then all the behavior follows classical mathematical rules.\n"; 41 41 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; 42 48 43 49 return 0; 44 50 } -
local_time/flight.cpp
20 20 //setup some timezones for creating and adjusting local times 21 21 //This user editable file can be found in libs/date_time/data. 22 22 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 } 24 32 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 26 34 time_zone_ptr phx_tz(new posix_time_zone("MST-07:00:00")); 27 35 28 //local departure time in phoenix is 11 pm on april 2 200529 // (ny changes to dst on apr 3at 2 am)30 local_date_time phx_departure(date(20 05, 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), 31 39 phx_tz, 32 40 local_date_time::NOT_DATE_TIME_ON_ERROR); 41 local_date_time nyc_departure = phx_departure.local_time_in(nyc_tz); 33 42 34 43 time_duration flight_length = hours(4) + minutes(30); 35 44 local_date_time phx_arrival = phx_departure + flight_length; 36 45 local_date_time nyc_arrival = phx_arrival.local_time_in(nyc_tz); 37 46 38 47 std::cout << "departure phx time: " << phx_departure << std::endl; 48 std::cout << "departure nyc time: " << nyc_departure << std::endl; 39 49 std::cout << "arrival phx time: " << phx_arrival << std::endl; 40 50 std::cout << "arrival nyc time: " << nyc_arrival << std::endl; 41 51 -
local_time/local_date_time.cpp
28 28 std::locale loc(std::locale::classic(), timefacet); 29 29 30 30 std::cout << ny_time << std::endl; 31 // 2004-Aug-30 00:00:00 EDT31 // 2004-Aug-30 10:00:00 EDT 32 32 std::cout.imbue(loc); 33 33 std::cout << ny_time << std::endl; 34 // 2004-Aug-30 00:00:00 Eastern Daylight Time34 // 2004-Aug-30 10:00:00 Eastern Daylight Time 35 35 36 36 return 0; 37 37 } -
posix_time/print_hours.cpp
29 29 ptime now = second_clock::local_time(); 30 30 //Get the date part out of the time 31 31 date today = now.date(); 32 date tom morrow = today + days(1);33 ptime tom morrow_start(tommorrow); //midnight32 date tomorrow = today + days(1); 33 ptime tomorrow_start(tomorrow); //midnight 34 34 35 35 //iterator adds by one hour 36 36 time_iterator titr(now,hours(1)); 37 for (; titr < tom morrow_start; ++titr) {37 for (; titr < tomorrow_start; ++titr) { 38 38 std::cout << to_simple_string(*titr) << std::endl; 39 39 } 40 40 41 time_duration remaining = tom morrow_start - now;41 time_duration remaining = tomorrow_start - now; 42 42 std::cout << "Time left till midnight: " 43 43 << to_simple_string(remaining) << std::endl; 44 44 return 0; -
posix_time/time_math.cpp
13 13 using namespace boost::gregorian; 14 14 15 15 date d(2002,Feb,1); //an arbitrary date 16 //construct a time by adding up some durations durations16 //construct a time by adding up some durations 17 17 ptime t1(d, hours(5)+minutes(4)+seconds(2)+milliseconds(1)); 18 18 //construct a new time by subtracting some times 19 19 ptime t2 = t1 - hours(5)- minutes(4)- seconds(2)- milliseconds(1); -
tutorial/io_tutorial.cpp
141 141 period_formatter per_formatter(period_formatter::AS_OPEN_RANGE, 142 142 " to ", "from ", " exclusive", " inclusive" ); 143 143 period_parser per_parser(period_parser::AS_OPEN_RANGE, 144 " to ", "from ", " exclusive" , " inclusive" );144 " to ", "from ", " exclusive" , " inclusive" ); 145 145 146 146 // default output 147 147 ss.str("");