• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.calc_rules">
11  <title>Daylight Savings Calc Rules</title>
12
13  <para>
14    Example of creating various Daylight Savings Calc Rule objects.
15  </para>
16  <programlisting>
17    <![CDATA[
18  /* A simple example for creating various dst_calc_rule instances
19   */
20
21  #include "boost/date_time/gregorian/gregorian.hpp"
22  #include "boost/date_time/local_time/local_time.hpp"
23  #include <iostream>
24
25  int
26  main()
27  {
28    using namespace boost;
29    using namespace local_time;
30    using namespace gregorian;
31
32    /***** create the necessary date_generator objects *****/
33    // starting generators
34    first_day_of_the_week_in_month fd_start(Sunday, May);
35    last_day_of_the_week_in_month ld_start(Sunday, May);
36    nth_day_of_the_week_in_month nkd_start(nth_day_of_the_week_in_month::third,
37                                           Sunday, May);
38    partial_date pd_start(1, May);
39    // ending generators
40    first_day_of_the_week_in_month fd_end(Sunday, Oct);
41    last_day_of_the_week_in_month ld_end(Sunday, Oct);
42    nth_day_of_the_week_in_month nkd_end(nth_day_of_the_week_in_month::third,
43                                         Sunday, Oct);
44    partial_date pd_end(31, Oct);
45
46    /***** create the various dst_calc_rule objects *****/
47    dst_calc_rule_ptr pdr(new partial_date_dst_rule(pd_start, pd_end));
48    dst_calc_rule_ptr flr(new first_last_dst_rule(fd_start, ld_end));
49    dst_calc_rule_ptr llr(new last_last_dst_rule(ld_start, ld_end));
50    dst_calc_rule_ptr nlr(new nth_last_dst_rule(nkd_start, ld_end));
51    dst_calc_rule_ptr ndr(new nth_day_of_the_week_in_month_dst_rule(nkd_start,
52                                                                    nkd_end));
53
54    return 0;
55  }
56
57    ]]>
58  </programlisting>
59</section>
60