dst_transition_generators.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
  2. * Use, modification and distribution is subject to the
  3. * Boost Software License, Version 1.0. (See accompanying
  4. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  5. * Author: Jeff Garland, Bart Garst
  6. */
  7. #ifndef DATE_TIME_DATE_DST_TRANSITION_DAY_GEN_HPP__
  8. #define DATE_TIME_DATE_DST_TRANSITION_DAY_GEN_HPP__
  9. namespace boost {
  10. namespace date_time {
  11. //! Defines base interface for calculating start and end date of daylight savings
  12. template<class date_type>
  13. class dst_day_calc_rule
  14. {
  15. public:
  16. typedef typename date_type::year_type year_type;
  17. virtual ~dst_day_calc_rule() {}
  18. virtual date_type start_day(year_type y) const=0;
  19. virtual std::string start_rule_as_string() const=0;
  20. virtual date_type end_day(year_type y) const=0;
  21. virtual std::string end_rule_as_string() const=0;
  22. };
  23. //! Canonical form for a class that provides day rule calculation
  24. /*! This class is used to generate specific sets of dst rules
  25. *
  26. *@tparam spec Provides a specifiction of the function object types used
  27. * to generate start and end days of daylight savings as well
  28. * as the date type.
  29. */
  30. template<class spec>
  31. class day_calc_dst_rule : public dst_day_calc_rule<typename spec::date_type>
  32. {
  33. public:
  34. typedef typename spec::date_type date_type;
  35. typedef typename date_type::year_type year_type;
  36. typedef typename spec::start_rule start_rule;
  37. typedef typename spec::end_rule end_rule;
  38. day_calc_dst_rule(start_rule dst_start,
  39. end_rule dst_end) :
  40. dst_start_(dst_start),
  41. dst_end_(dst_end)
  42. {}
  43. virtual date_type start_day(year_type y) const
  44. {
  45. return dst_start_.get_date(y);
  46. }
  47. virtual std::string start_rule_as_string() const
  48. {
  49. return dst_start_.to_string();
  50. }
  51. virtual date_type end_day(year_type y) const
  52. {
  53. return dst_end_.get_date(y);
  54. }
  55. virtual std::string end_rule_as_string() const
  56. {
  57. return dst_end_.to_string();
  58. }
  59. private:
  60. start_rule dst_start_;
  61. end_rule dst_end_;
  62. };
  63. } }//namespace
  64. #endif