ex_calc_rules.xml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. <!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
  5. Subject to the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <section id="date_time.examples.calc_rules">
  9. <title>Daylight Savings Calc Rules</title>
  10. <para>
  11. Example of creating various Daylight Savings Calc Rule objects.
  12. </para>
  13. <programlisting>
  14. <![CDATA[
  15. /* A simple example for creating various dst_calc_rule instances
  16. */
  17. #include "boost/date_time/gregorian/gregorian.hpp"
  18. #include "boost/date_time/local_time/local_time.hpp"
  19. #include <iostream>
  20. int
  21. main()
  22. {
  23. using namespace boost;
  24. using namespace local_time;
  25. using namespace gregorian;
  26. /***** create the necessary date_generator objects *****/
  27. // starting generators
  28. first_day_of_the_week_in_month fd_start(Sunday, May);
  29. last_day_of_the_week_in_month ld_start(Sunday, May);
  30. nth_day_of_the_week_in_month nkd_start(nth_day_of_the_week_in_month::third,
  31. Sunday, May);
  32. partial_date pd_start(1, May);
  33. // ending generators
  34. first_day_of_the_week_in_month fd_end(Sunday, Oct);
  35. last_day_of_the_week_in_month ld_end(Sunday, Oct);
  36. nth_day_of_the_week_in_month nkd_end(nth_day_of_the_week_in_month::third,
  37. Sunday, Oct);
  38. partial_date pd_end(31, Oct);
  39. /***** create the various dst_calc_rule objects *****/
  40. dst_calc_rule_ptr pdr(new partial_date_dst_rule(pd_start, pd_end));
  41. dst_calc_rule_ptr flr(new first_last_dst_rule(fd_start, ld_end));
  42. dst_calc_rule_ptr llr(new last_last_dst_rule(ld_start, ld_end));
  43. dst_calc_rule_ptr nlr(new nth_last_dst_rule(nkd_start, ld_end));
  44. dst_calc_rule_ptr ndr(new nth_day_of_the_week_in_month_dst_rule(nkd_start,
  45. nkd_end));
  46. return 0;
  47. }
  48. ]]>
  49. </programlisting>
  50. </section>