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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"../../../tools/boostbook/dtd/boostbook.dtd">
<!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
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)
-->
<section id="date_time.local_time.custom_time_zone">
<title>Custom Time Zone</title>
<link linkend="custom_time_zone_intro">Introduction</link> --
<link linkend="custom_time_zone_header">Header</link> --
<link linkend="custom_time_zone_constr">Construction</link> --
<link linkend="custom_time_zone_accessors">Accessors</link> --
<link linkend="custom_time_zone_dependents">Dependent Types</link>
<anchor id="custom_time_zone_intro" />
<bridgehead renderas="sect3">Introduction</bridgehead>
<para>
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.
</para>
<para>
As a convenience, a typedef for shared_ptr<dst_calc_rules> is provided.
<programlisting>typedef boost::shared_ptr<dst_calc_rules> local_time::dst_calc_rule_ptr;</programlisting>
</para>
<anchor id="date_time.local_time.custom_time_zone_ptr" />
<para>
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:
<programlisting>typedef boost::shared_ptr<time_zone> local_time::time_zone_ptr;</programlisting>
</para>
<anchor id="custom_time_zone_header" />
<bridgehead renderas="sect3">Header</bridgehead>
<para>
The inclusion of a single header will bring in all boost::local_time types, functions, and IO operators.
<programlisting>#include "boost/date_time/local_time/local_time.hpp"</programlisting>
</para>
<anchor id="custom_time_zone_constr" />
<bridgehead renderas="sect3">Construction</bridgehead>
<para>
Construction of a custom_time_zone is dependent on four objects: a
<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>.
</para>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry>Syntax</entry>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top"><screen>custom_time_zone(...)
Parameters:
<link linkend="time_zone_names">names</link>,
<link linkend="date_time.posix_time.time_duration">gmt_offset</link>,
<link linkend="dst_adjustment_offsets">dst_offsets</link>,
<link linkend="date_time.local_time.dst_calc_rules">dst_rules</link> </screen></entry>
<entry>See <link linkend="date_time.examples.simple_time_zone">simple_time_zone</link> example for time_zone usage</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="custom_time_zone_accessors" />
<bridgehead renderas="sect3">Accessors</bridgehead>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>std::string dst_zone_abbrev()</screen></entry>
<entry>Returns the daylight savings abbreviation for the represented time zone.</entry>
</row>
<row>
<entry><screen>nyc_zone_sh_ptr->dst_zone_abbrev();
// "EDT"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string std_zone_abbrev()</screen></entry>
<entry>Returns the standard abbreviation for the represented time zone.</entry>
</row>
<row>
<entry><screen>nyc_zone_sh_ptr->std_zone_abbrev();
// "EST"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string dst_zone_name()</screen></entry>
<entry>Returns the daylight savings name for the represented time zone.</entry>
</row>
<row>
<entry><screen>nyc_zone_sh_ptr->dst_zone_name();
// "Eastern Daylight Time"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string std_zone_name()</screen></entry>
<entry>Returns the standard name for the represented time zone.</entry>
</row>
<row>
<entry><screen>nyc_zone_sh_ptr->std_zone_name();
// "Eastern Standard Time"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>bool has_dst()</screen></entry>
<entry>Returns true when custom_time_zone's shared_ptr to dst_calc_rules is not NULL.</entry>
</row>
<row>
<entry><screen>nyc_zone_sh_ptr->has_dst();
// true
phx_zone_sh_ptr->has_dst();
// false</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>dst_local_start_time(...)
Return Type:
ptime
Parameter:
greg_year</screen></entry>
<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>
</row>
<row>
<entry><screen>nyc_ptr->dst_local_start_time(2004);
// 2004-Apr-04 02:00</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>dst_local_end_time(...)
Return Type:
ptime
Parameter:
greg_year</screen></entry>
<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>
</row>
<row>
<entry><screen>nyc_ptr->dst_local_end_time(2004);
// 2004-Oct-31 02:00</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_duration base_utc_offset()</screen></entry>
<entry>The amount of time offset from UTC (typically in hours).</entry>
</row>
<row>
<entry><screen>nyc_ptr->base_utc_offset();
// -05:00</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>time_duration dst_offset()</screen></entry>
<entry>The amount of time shifted during daylight savings.</entry>
</row>
<row>
<entry><screen>nyc_zone_sh_ptr->dst_offset();
// 01:00</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string to_posix_string()</screen></entry>
<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>
</row>
<row>
<entry><screen>nyc_ptr->to_posix_string();
// "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"
phx_ptr->to_posix_string();
// "MST-07"
</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="custom_time_zone_dependents" />
<bridgehead renderas="sect3">Dependent Types</bridgehead>
<link linkend="time_zone_names">Time Zone Names</link> --
<link linkend="dst_adjustment_offsets">Dst Adjustment Offsets</link> --
<link linkend="date_time.local_time.dst_calc_rules">Daylight Savings Calc Rules</link>
<anchor id="time_zone_names" />
<bridgehead renderas="sect3">Time Zone Names</bridgehead>
<para>
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>.
</para>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>time_zone_names(...)
Parameters:
string std_name
string std_abbrev
string dst_name
string dst_abbrev</screen></entry>
<entry>The only constructor, all four strings must be provided.</entry>
</row>
<row>
<entry><screen>string sn("Eastern Standard Time");
string sa("EST");
string dn("Eastern Daylight Time");
string da("EDT");
time_zone_names nyc_names(sn, sa,
dn, da);</screen>
</entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string std_zone_name()</screen></entry>
<entry>Returns the standard zone name</entry>
</row>
<row>
<entry><screen>nyc_names.std_zone_name();
// "Eastern Standard Time"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string std_zone_abbrev()</screen></entry>
<entry>Returns the standard zone abbreviation</entry>
</row>
<row>
<entry><screen>nyc_names.std_zone_abbrev();
// "EST"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string dst_zone_name()</screen></entry>
<entry>Returns the daylight savings zone name</entry>
</row>
<row>
<entry><screen>nyc_names.std_zone_name();
// "Eastern Daylight Time"</screen></entry>
</row>
<row>
<entry valign="top" morerows="1"><screen>std::string dst_zone_abbrev()</screen></entry>
<entry>Returns the daylight savings zone abbreviation</entry>
</row>
<row>
<entry><screen>nyc_names.std_zone_abbrev();
// "EDT"</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="dst_adjustment_offsets" />
<bridgehead renderas="sect3">Dst Adjustment Offsets</bridgehead>
<para>
The dst_adjustment_offsets type is a collection of three <link linkend="date_time.posix_time.time_duration">time_duration</link> objects.
</para>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry valign="top" morerows="1">Syntax</entry>
<entry>Description</entry>
</row>
<row>
<entry>Example</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top" morerows="1"><screen>dst_adjustment_offsets(...)
Parameters:
time_duration dst_adjust
time_duration start_offset
time_duration end_offset</screen></entry>
<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>
</row>
<row>
<entry><screen>
dst_adjustment_offsets(hours(1),
hours(2),
hours(2));</screen></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<anchor id="date_time.local_time.dst_calc_rules" />
<bridgehead renderas="sect3">Daylight Savings Calc Rules</bridgehead>
<para>
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.
</para>
<para>
For a complete example of all five dst_calc_rule types, see: <link linkend="date_time.examples.calc_rules">calc_rules example</link>.
</para>
<para>
<informaltable frame="all">
<tgroup cols="2">
<thead>
<row>
<entry>Syntax</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry valign="top"><screen>partial_date_dst_rule(...)
Parameters:
start_rule
end_rule</screen></entry>
<entry>Both the start and end rules are of type gregorian::partial_date.</entry>
</row>
<row>
<entry valign="top"><screen>first_last_dst_rule(...)
Parameters:
start_rule
end_rule</screen></entry>
<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>
</row>
<row>
<entry valign="top"><screen>last_last_dst_rule(...)
Parameters:
start_rule
end_rule</screen></entry>
<entry>Both the start and end rules are of type gregorian::last_day_of_the_week_in_month.</entry>
</row>
<row>
<entry valign="top"><screen>nth_last_dst_rule(...)
Parameters:
start_rule
end_rule</screen></entry>
<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>
</row>
<row>
<entry valign="top"><screen>nth_kday_dst_rule(...)
Parameters:
start_rule
end_rule)
(see note* below)</screen>
</entry>
<entry>Both rules are of type gregorian::nth_day_of_the_week_in_month.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
* 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.
</para>
</para>
</section>
|