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. #include <string>
  10. namespace boost {
  11. namespace date_time {
  12. //! Defines base interface for calculating start and end date of daylight savings
  13. template<class date_type>
  14. class dst_day_calc_rule
  15. {
  16. public:
  17. typedef typename date_type::year_type year_type;
  18. virtual ~dst_day_calc_rule() {}
  19. virtual date_type start_day(year_type y) const=0;
  20. virtual std::string start_rule_as_string() const=0;
  21. virtual date_type end_day(year_type y) const=0;
  22. virtual std::string end_rule_as_string() const=0;
  23. };
  24. //! Canonical form for a class that provides day rule calculation
  25. /*! This class is used to generate specific sets of dst rules
  26. *
  27. *@tparam spec Provides a specifiction of the function object types used
  28. * to generate start and end days of daylight savings as well
  29. * as the date type.
  30. */
  31. template<class spec>
  32. class day_calc_dst_rule : public dst_day_calc_rule<typename spec::date_type>
  33. {
  34. public:
  35. typedef typename spec::date_type date_type;
  36. typedef typename date_type::year_type year_type;
  37. typedef typename spec::start_rule start_rule;
  38. typedef typename spec::end_rule end_rule;
  39. day_calc_dst_rule(start_rule dst_start,
  40. end_rule dst_end) :
  41. dst_start_(dst_start),
  42. dst_end_(dst_end)
  43. {}
  44. virtual date_type start_day(year_type y) const
  45. {
  46. return dst_start_.get_date(y);
  47. }
  48. virtual std::string start_rule_as_string() const
  49. {
  50. return dst_start_.to_string();
  51. }
  52. virtual date_type end_day(year_type y) const
  53. {
  54. return dst_end_.get_date(y);
  55. }
  56. virtual std::string end_rule_as_string() const
  57. {
  58. return dst_end_.to_string();
  59. }
  60. private:
  61. start_rule dst_start_;
  62. end_rule dst_end_;
  63. };
  64. } }//namespace
  65. #endif