File: flight.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (60 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include "boost/date_time/local_time/local_time.hpp"
#include <iostream>

/* 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).  
 *
 * 
 */

int main()
{
  using namespace boost::gregorian; 
  using namespace boost::local_time;
  using namespace boost::posix_time;


  //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;
  try {
    tz_db.load_from_file("../../data/date_time_zonespec.csv");
  }catch(const data_not_accessible& dna) {
    std::cerr << "Error with time zone data file: " << dna.what() << std::endl;
    exit(EXIT_FAILURE);
  }catch(const 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 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 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 << "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;

}


/*  Copyright 2005: CrystalClear Software, Inc
 *  http://www.crystalclearsoftware.com
 *
 *  Subject to the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 */