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.local_time.custom_time_zone"> 11 <title>Custom Time Zone</title> 12 13 <link linkend="custom_time_zone_intro">Introduction</link> -- 14 <link linkend="custom_time_zone_header">Header</link> -- 15 <link linkend="custom_time_zone_constr">Construction</link> -- 16 <link linkend="custom_time_zone_accessors">Accessors</link> -- 17 <link linkend="custom_time_zone_dependents">Dependent Types</link> 18 19 <anchor id="custom_time_zone_intro" /> 20 <bridgehead renderas="sect3">Introduction</bridgehead> 21 <para> 22 A custom_time_zone object is a set of data and rules that provide information about a time zone. Information such as the offset from UTC, it's name and abbreviation, as well as daylight savings rules, called <link linkend="date_time.local_time.dst_calc_rules">dst_calc_rules</link>. These rules are handled via a boost::shared_ptr<dst_calc_rules>. Not all time zones utilize daylight savings, therefore, time_zone objects can be used with a NULL-assigned shared_ptr. 23 </para> 24 <para> 25 As a convenience, a typedef for shared_ptr<dst_calc_rules> is provided. 26 <programlisting>typedef boost::shared_ptr<dst_calc_rules> local_time::dst_calc_rule_ptr;</programlisting> 27 </para> 28 <anchor id="date_time.local_time.custom_time_zone_ptr" /> 29 <para> 30 The time_zone objects are used via a boost::shared_ptr<local_time::time_zone>. As a convenience, a typedef for boost::shared_ptr<local_time::time_zone> is provided: 31 <programlisting>typedef boost::shared_ptr<time_zone> local_time::time_zone_ptr;</programlisting> 32 </para> 33 34 <anchor id="custom_time_zone_header" /> 35 <bridgehead renderas="sect3">Header</bridgehead> 36 <para> 37 The inclusion of a single header will bring in all boost::local_time types, functions, and IO operators. 38 <programlisting>#include "boost/date_time/local_time/local_time.hpp"</programlisting> 39 </para> 40 41 <anchor id="custom_time_zone_constr" /> 42 <bridgehead renderas="sect3">Construction</bridgehead> 43 <para> 44 Construction of a custom_time_zone is dependent on four objects: a 45 <link linkend="date_time.posix_time.time_duration">time_duration</link>, a <link linkend="time_zone_names">time_zone_names</link>, a <link linkend="dst_adjustment_offsets">dst_adjustment_offsets</link>, and a shared_ptr to a <link linkend="date_time.local_time.dst_calc_rules">dst_calc_rule</link>. 46 </para> 47 <para> 48 <informaltable frame="all"> 49 <tgroup cols="2"> 50 <thead> 51 <row> 52 <entry>Syntax</entry> 53 <entry>Example</entry> 54 </row> 55 </thead> 56 <tbody> 57 <row> 58 <entry valign="top"><screen>custom_time_zone(...) 59 Parameters: 60 <link linkend="time_zone_names">names</link>, 61 <link linkend="date_time.posix_time.time_duration">gmt_offset</link>, 62 <link linkend="dst_adjustment_offsets">dst_offsets</link>, 63 <link linkend="date_time.local_time.dst_calc_rules">dst_rules</link> </screen></entry> 64 <entry>See <link linkend="date_time.examples.simple_time_zone">simple_time_zone</link> example for time_zone usage</entry> 65 </row> 66 </tbody> 67 </tgroup> 68 </informaltable> 69 </para> 70 71 <anchor id="custom_time_zone_accessors" /> 72 <bridgehead renderas="sect3">Accessors</bridgehead> 73 <para> 74 <informaltable frame="all"> 75 <tgroup cols="2"> 76 <thead> 77 <row> 78 <entry valign="top" morerows="1">Syntax</entry> 79 <entry>Description</entry> 80 </row> 81 <row> 82 <entry>Example</entry> 83 </row> 84 </thead> 85 <tbody> 86 <row> 87 <entry valign="top" morerows="1"><screen>std::string dst_zone_abbrev()</screen></entry> 88 <entry>Returns the daylight savings abbreviation for the represented time zone.</entry> 89 </row> 90 <row> 91 <entry><screen>nyc_zone_sh_ptr->dst_zone_abbrev(); 92// "EDT"</screen></entry> 93 </row> 94 95 <row> 96 <entry valign="top" morerows="1"><screen>std::string std_zone_abbrev()</screen></entry> 97 <entry>Returns the standard abbreviation for the represented time zone.</entry> 98 </row> 99 <row> 100 <entry><screen>nyc_zone_sh_ptr->std_zone_abbrev(); 101// "EST"</screen></entry> 102 </row> 103 104 <row> 105 <entry valign="top" morerows="1"><screen>std::string dst_zone_name()</screen></entry> 106 <entry>Returns the daylight savings name for the represented time zone.</entry> 107 </row> 108 <row> 109 <entry><screen>nyc_zone_sh_ptr->dst_zone_name(); 110// "Eastern Daylight Time"</screen></entry> 111 </row> 112 113 <row> 114 <entry valign="top" morerows="1"><screen>std::string std_zone_name()</screen></entry> 115 <entry>Returns the standard name for the represented time zone.</entry> 116 </row> 117 <row> 118 <entry><screen>nyc_zone_sh_ptr->std_zone_name(); 119// "Eastern Standard Time"</screen></entry> 120 </row> 121 122 <row> 123 <entry valign="top" morerows="1"><screen>bool has_dst()</screen></entry> 124 <entry>Returns true when custom_time_zone's shared_ptr to dst_calc_rules is not NULL.</entry> 125 </row> 126 <row> 127 <entry><screen>nyc_zone_sh_ptr->has_dst(); 128// true 129phx_zone_sh_ptr->has_dst(); 130// false</screen> 131 </entry> 132 </row> 133 134 <row> 135 <entry valign="top" morerows="1"><screen>dst_local_start_time(...) 136 Return Type: 137 ptime 138 Parameter: 139 greg_year</screen></entry> 140 <entry>The date and time daylight savings time begins in given year. Returns not_a_date_time if this zone has no daylight savings.</entry> 141 </row> 142 <row> 143 <entry><screen>nyc_ptr->dst_local_start_time(2004); 144// 2004-Apr-04 02:00</screen></entry> 145 </row> 146 147 <row> 148 <entry valign="top" morerows="1"><screen>dst_local_end_time(...) 149 Return Type: 150 ptime 151 Parameter: 152 greg_year</screen></entry> 153 <entry>The date and time daylight savings time ends in given year. Returns not_a_date_time if this zone has no daylight savings.</entry> 154 </row> 155 <row> 156 <entry><screen>nyc_ptr->dst_local_end_time(2004); 157// 2004-Oct-31 02:00</screen></entry> 158 </row> 159 160 <row> 161 <entry valign="top" morerows="1"><screen>time_duration base_utc_offset()</screen></entry> 162 <entry>The amount of time offset from UTC (typically in hours).</entry> 163 </row> 164 <row> 165 <entry><screen>nyc_ptr->base_utc_offset(); 166// -05:00</screen></entry> 167 </row> 168 169 <row> 170 <entry valign="top" morerows="1"><screen>time_duration dst_offset()</screen></entry> 171 <entry>The amount of time shifted during daylight savings.</entry> 172 </row> 173 <row> 174 <entry><screen>nyc_zone_sh_ptr->dst_offset(); 175// 01:00</screen></entry> 176 </row> 177 178 <row> 179 <entry valign="top" morerows="1"><screen>std::string to_posix_string()</screen></entry> 180 <entry>Returns a posix time zone string representation of this time_zone object. Depending on how the time_zone object was created, the date-spec format of the string will be in either 'M' notation or 'n' notation. Every possible date-spec that can be represented in 'J' notation can also be represented in 'n' notation. The reverse is not true so only 'n' notation is used for these types of date-specs. For a detailed description of a posix time zone string see <link linkend="date_time.local_time.posix_time_zone">posix_time_zone</link>.</entry> 181 </row> 182 <row> 183 <entry><screen>nyc_ptr->to_posix_string(); 184// "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00" 185phx_ptr->to_posix_string(); 186// "MST-07" 187 </screen></entry> 188 </row> 189 </tbody> 190 </tgroup> 191 </informaltable> 192 </para> 193 194 <anchor id="custom_time_zone_dependents" /> 195 <bridgehead renderas="sect3">Dependent Types</bridgehead> 196 <link linkend="time_zone_names">Time Zone Names</link> -- 197 <link linkend="dst_adjustment_offsets">Dst Adjustment Offsets</link> -- 198 <link linkend="date_time.local_time.dst_calc_rules">Daylight Savings Calc Rules</link> 199 <anchor id="time_zone_names" /> 200 <bridgehead renderas="sect3">Time Zone Names</bridgehead> 201 <para> 202 The time_zone_names_base type is an immutable template class of four strings. One each for the name and abbreviation in standard time and daylight savings time. The time_zone_names type is a typedef of time_zone_names_base<char>. 203 </para> 204 <para> 205 <informaltable frame="all"> 206 <tgroup cols="2"> 207 <thead> 208 <row> 209 <entry valign="top" morerows="1">Syntax</entry> 210 <entry>Description</entry> 211 </row> 212 <row> 213 <entry>Example</entry> 214 </row> 215 </thead> 216 <tbody> 217 <row> 218 <entry valign="top" morerows="1"><screen>time_zone_names(...) 219 Parameters: 220 string std_name 221 string std_abbrev 222 string dst_name 223 string dst_abbrev</screen></entry> 224 <entry>The only constructor, all four strings must be provided.</entry> 225 </row> 226 <row> 227 <entry><screen>string sn("Eastern Standard Time"); 228string sa("EST"); 229string dn("Eastern Daylight Time"); 230string da("EDT"); 231time_zone_names nyc_names(sn, sa, 232 dn, da);</screen> 233 </entry> 234 </row> 235 236 <row> 237 <entry valign="top" morerows="1"><screen>std::string std_zone_name()</screen></entry> 238 <entry>Returns the standard zone name</entry> 239 </row> 240 <row> 241 <entry><screen>nyc_names.std_zone_name(); 242// "Eastern Standard Time"</screen></entry> 243 </row> 244 245 <row> 246 <entry valign="top" morerows="1"><screen>std::string std_zone_abbrev()</screen></entry> 247 <entry>Returns the standard zone abbreviation</entry> 248 </row> 249 <row> 250 <entry><screen>nyc_names.std_zone_abbrev(); 251// "EST"</screen></entry> 252 </row> 253 254 <row> 255 <entry valign="top" morerows="1"><screen>std::string dst_zone_name()</screen></entry> 256 <entry>Returns the daylight savings zone name</entry> 257 </row> 258 <row> 259 <entry><screen>nyc_names.std_zone_name(); 260// "Eastern Daylight Time"</screen></entry> 261 </row> 262 263 <row> 264 <entry valign="top" morerows="1"><screen>std::string dst_zone_abbrev()</screen></entry> 265 <entry>Returns the daylight savings zone abbreviation</entry> 266 </row> 267 <row> 268 <entry><screen>nyc_names.std_zone_abbrev(); 269// "EDT"</screen></entry> 270 </row> 271 </tbody> 272 </tgroup> 273 </informaltable> 274 </para> 275 276 <anchor id="dst_adjustment_offsets" /> 277 <bridgehead renderas="sect3">Dst Adjustment Offsets</bridgehead> 278 <para> 279 The dst_adjustment_offsets type is a collection of three <link linkend="date_time.posix_time.time_duration">time_duration</link> objects. 280 </para> 281 <para> 282 <informaltable frame="all"> 283 <tgroup cols="2"> 284 <thead> 285 <row> 286 <entry valign="top" morerows="1">Syntax</entry> 287 <entry>Description</entry> 288 </row> 289 <row> 290 <entry>Example</entry> 291 </row> 292 </thead> 293 <tbody> 294 <row> 295 <entry valign="top" morerows="1"><screen>dst_adjustment_offsets(...) 296 Parameters: 297 time_duration dst_adjust 298 time_duration start_offset 299 time_duration end_offset</screen></entry> 300 <entry>The first time_duration is the daylight savings adjustment. The second is the time which daylight savings starts on the start day. The third is the time daylight savings ends on the ending day.</entry> 301 </row> 302 <row> 303 <entry><screen> 304dst_adjustment_offsets(hours(1), 305 hours(2), 306 hours(2));</screen></entry> 307 </row> 308 </tbody> 309 </tgroup> 310 </informaltable> 311 </para> 312 313 <anchor id="date_time.local_time.dst_calc_rules" /> 314 <bridgehead renderas="sect3">Daylight Savings Calc Rules</bridgehead> 315 <para> 316 Daylight savings calc rules, named dst_calc_rules, are a series of objects that group appropriate <link linkend="date_time.gregorian.date_algorithms">date_generators</link> together to form rule sets. The individual rules objects are used via dst_calc_rule_ptr. 317 </para> 318 <para> 319 For a complete example of all five dst_calc_rule types, see: <link linkend="date_time.examples.calc_rules">calc_rules example</link>. 320 </para> 321 <para> 322 <informaltable frame="all"> 323 <tgroup cols="2"> 324 <thead> 325 <row> 326 <entry>Syntax</entry> 327 <entry>Description</entry> 328 </row> 329 </thead> 330 <tbody> 331 <row> 332 <entry valign="top"><screen>partial_date_dst_rule(...) 333 Parameters: 334 start_rule 335 end_rule</screen></entry> 336 <entry>Both the start and end rules are of type gregorian::partial_date.</entry> 337 </row> 338 <row> 339 <entry valign="top"><screen>first_last_dst_rule(...) 340 Parameters: 341 start_rule 342 end_rule</screen></entry> 343 <entry>The DST start rule is of type gregorian::first_day_of_the_week_in_month and the end rule is of type gregorian::last_day_of_the_week_in_month.</entry> 344 </row> 345 <row> 346 <entry valign="top"><screen>last_last_dst_rule(...) 347 Parameters: 348 start_rule 349 end_rule</screen></entry> 350 <entry>Both the start and end rules are of type gregorian::last_day_of_the_week_in_month.</entry> 351 </row> 352 <row> 353 <entry valign="top"><screen>nth_last_dst_rule(...) 354 Parameters: 355 start_rule 356 end_rule</screen></entry> 357 <entry>The DST start rule is of type gregorian::nth_day_of_the_week_in_month and the end rule is of type gregorian::last_day_of_the_week_in_month.</entry> 358 </row> 359 <row> 360 <entry valign="top"><screen>nth_kday_dst_rule(...) 361 Parameters: 362 start_rule 363 end_rule) 364(see note* below)</screen> 365 </entry> 366 <entry>Both rules are of type gregorian::nth_day_of_the_week_in_month.</entry> 367 </row> 368 </tbody> 369 </tgroup> 370 </informaltable> 371 <para> 372 * Note: The name "nth_kday_dst_rule" is a bit cryptic. Therefore, a more descriptive name, "nth_day_of_the_week_in_month_dst_rule", is also provided. 373 </para> 374 </para> 375 376</section> 377