]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/example/local_time/flight.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / date_time / example / local_time / flight.cpp
1
2 #include "boost/date_time/local_time/local_time.hpp"
3 #include <iostream>
4
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
8 * DST).
9 *
10 *
11 */
12
13 int main()
14 {
15 using namespace boost::gregorian;
16 using namespace boost::local_time;
17 using namespace boost::posix_time;
18
19
20 //setup some timezones for creating and adjusting local times
21 //This user editable file can be found in libs/date_time/data.
22 tz_database tz_db;
23 try {
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;
27 exit(EXIT_FAILURE);
28 }catch(const bad_field_count& bfc) {
29 std::cerr << "Error with time zone data file: " << bfc.what() << std::endl;
30 exit(EXIT_FAILURE);
31 }
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"));
35
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),
39 phx_tz,
40 local_date_time::NOT_DATE_TIME_ON_ERROR);
41 local_date_time nyc_departure = phx_departure.local_time_in(nyc_tz);
42
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);
46
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;
51
52 }
53
54
55 /* Copyright 2005: CrystalClear Software, Inc
56 * http://www.crystalclearsoftware.com
57 *
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)
60 */