]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/xmldoc/ex_simple_time_zone.xml
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / date_time / xmldoc / ex_simple_time_zone.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
3 "../../../tools/boostbook/dtd/boostbook.dtd">
4
5 <!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
6 Subject to the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 -->
9
10 <section id="date_time.examples.simple_time_zone">
11 <title>Simple Time Zones</title>
12
13 <para>
14 Example usage of custom_time_zone as well as posix_time_zone.
15 </para>
16 <programlisting>
17 <![CDATA[
18 /* A simple example for using a custom_time_zone and a posix_time_zone.
19 */
20
21 #include "boost/date_time/local_time/local_time.hpp"
22 #include <iostream>
23
24 int
25 main()
26 {
27 using namespace boost;
28 using namespace local_time;
29 using namespace gregorian;
30 using posix_time::time_duration;
31
32 /***** custom_time_zone *****/
33
34 // create the dependent objects for a custom_time_zone
35 time_zone_names tzn("Eastern Standard Time", "EST",
36 "Eastern Daylight Time", "EDT");
37 time_duration utc_offset(-5,0,0);
38 dst_adjustment_offsets adj_offsets(time_duration(1,0,0),
39 time_duration(2,0,0),
40 time_duration(2,0,0));
41 // rules for this zone are:
42 // start on first Sunday of April at 2 am
43 // end on last Sunday of October at 2 am
44 // so we use a first_last_dst_rule
45 first_day_of_the_week_in_month start_rule(Sunday, Apr);
46 last_day_of_the_week_in_month end_rule(Sunday, Oct);
47 shared_ptr<dst_calc_rule> nyc_rules(new first_last_dst_rule(start_rule,
48 end_rule));
49 // create more dependent objects for a non-dst custom_time_zone
50 time_zone_names tzn2("Mountain Standard Time", "MST",
51 "", ""); // no dst means empty dst strings
52 time_duration utc_offset2(-7,0,0);
53 dst_adjustment_offsets adj_offsets2(time_duration(0,0,0),
54 time_duration(0,0,0),
55 time_duration(0,0,0));
56 // no dst means we need a null pointer to the rules
57 shared_ptr<dst_calc_rule> phx_rules;
58
59 // create the custom_time_zones
60 time_zone_ptr nyc_1(new custom_time_zone(tzn, utc_offset,
61 adj_offsets, nyc_rules));
62 time_zone_ptr phx_1(new custom_time_zone(tzn2, utc_offset2,
63 adj_offsets2, phx_rules));
64
65 /***** posix_time_zone *****/
66
67 // create posix_time_zones that are the duplicates of the
68 // custom_time_zones created above. See posix_time_zone documentation
69 // for details on full zone names.
70 std::string nyc_string, phx_string;
71 nyc_string = "EST-05:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00";
72 // nyc_string = "EST-05EDT,M4.1.0,M10.5.0"; // shorter when defaults used
73 phx_string = "MST-07"; // no-dst
74 time_zone_ptr nyc_2(new posix_time_zone(nyc_string));
75 time_zone_ptr phx_2(new posix_time_zone(phx_string));
76
77
78 /***** show the sets are equal *****/
79
80 std::cout << "The first zone is in daylight savings from:\n "
81 << nyc_1->dst_local_start_time(2004) << " through "
82 << nyc_1->dst_local_end_time(2004) << std::endl;
83
84 std::cout << "The second zone is in daylight savings from:\n "
85 << nyc_2->dst_local_start_time(2004) << " through "
86 << nyc_2->dst_local_end_time(2004) << std::endl;
87
88 std::cout << "The third zone (no daylight savings):\n "
89 << phx_1->std_zone_abbrev() << " and "
90 << phx_1->base_utc_offset() << std::endl;
91
92 std::cout << "The fourth zone (no daylight savings):\n "
93 << phx_2->std_zone_abbrev() << " and "
94 << phx_2->base_utc_offset() << std::endl;
95
96 return 0;
97 }
98 ]]>
99 </programlisting>
100 </section>