2 #include "boost/date_time/local_time/local_time.hpp"
5 /* This example shows a program that calculates the arrival time of a plane
6 * that flys from Phoenix to New York. During the flight New York shifts
7 * into daylight savings time (Phoenix doesn't because Arizona doesn't use
15 using namespace boost::gregorian
;
16 using namespace boost::local_time
;
17 using namespace boost::posix_time
;
20 //setup some timezones for creating and adjusting local times
21 //This user editable file can be found in libs/date_time/data.
24 tz_db
.load_from_file("../../data/date_time_zonespec.csv");
25 }catch(const data_not_accessible
& dna
) {
26 std::cerr
<< "Error with time zone data file: " << dna
.what() << std::endl
;
28 }catch(const bad_field_count
& bfc
) {
29 std::cerr
<< "Error with time zone data file: " << bfc
.what() << std::endl
;
32 time_zone_ptr nyc_tz
= tz_db
.time_zone_from_region("America/New_York");
33 //Use a newly created time zone rule
34 time_zone_ptr
phx_tz(new posix_time_zone("MST-07:00:00"));
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),
40 local_date_time::NOT_DATE_TIME_ON_ERROR
);
41 local_date_time nyc_departure
= phx_departure
.local_time_in(nyc_tz
);
43 time_duration flight_length
= hours(4) + minutes(30);
44 local_date_time phx_arrival
= phx_departure
+ flight_length
;
45 local_date_time nyc_arrival
= phx_arrival
.local_time_in(nyc_tz
);
47 std::cout
<< "departure PHX time: " << phx_departure
<< std::endl
;
48 std::cout
<< "departure NYC time: " << nyc_departure
<< std::endl
;
49 std::cout
<< "arrival PHX time: " << phx_arrival
<< std::endl
;
50 std::cout
<< "arrival NYC time: " << nyc_arrival
<< std::endl
;
55 /* Copyright 2005: CrystalClear Software, Inc
56 * http://www.crystalclearsoftware.com
58 * Subject to the Boost Software License, Version 1.0.
59 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)