time_zone_base.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef _DATE_TIME_TIME_ZONE_BASE__
  2. #define _DATE_TIME_TIME_ZONE_BASE__
  3. /* Copyright (c) 2003-2005 CrystalClear Software, Inc.
  4. * Subject to the Boost Software License, Version 1.0.
  5. * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  6. * Author: Jeff Garland, Bart Garst
  7. * $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $
  8. */
  9. #include <string>
  10. #include <sstream>
  11. namespace boost {
  12. namespace date_time {
  13. //! Interface class for dynamic time zones.
  14. /*! This class represents the base interface for all timezone
  15. * representations. Subclasses may provide different systems
  16. * for identifying a particular zone. For example some may
  17. * provide a geographical based zone construction while others
  18. * may specify the offset from GMT. Another possible implementation
  19. * would be to convert from POSIX timezone strings. Regardless of
  20. * the construction technique, this is the interface that these
  21. * time zone types must provide.
  22. *
  23. * Note that this class is intended to be used as a shared
  24. * resource (hence the derivation from boost::counted_base.
  25. */
  26. template<typename time_type, typename CharT>
  27. class time_zone_base {
  28. public:
  29. typedef CharT char_type;
  30. typedef std::basic_string<CharT> string_type;
  31. typedef std::basic_ostringstream<CharT> stringstream_type;
  32. typedef typename time_type::date_type::year_type year_type;
  33. typedef typename time_type::time_duration_type time_duration_type;
  34. time_zone_base() {};
  35. virtual ~time_zone_base() {};
  36. //!String for the timezone when in daylight savings (eg: EDT)
  37. virtual string_type dst_zone_abbrev() const=0;
  38. //!String for the zone when not in daylight savings (eg: EST)
  39. virtual string_type std_zone_abbrev() const=0;
  40. //!String for the timezone when in daylight savings (eg: Eastern Daylight Time)
  41. virtual string_type dst_zone_name() const=0;
  42. //!String for the zone when not in daylight savings (eg: Eastern Standard Time)
  43. virtual string_type std_zone_name() const=0;
  44. //! True if zone uses daylight savings adjustments otherwise false
  45. virtual bool has_dst() const=0;
  46. //! Local time that DST starts -- undefined if has_dst is false
  47. virtual time_type dst_local_start_time(year_type y) const=0;
  48. //! Local time that DST ends -- undefined if has_dst is false
  49. virtual time_type dst_local_end_time(year_type y) const=0;
  50. //! Base offset from UTC for zone (eg: -07:30:00)
  51. virtual time_duration_type base_utc_offset() const=0;
  52. //! Adjustment forward or back made while DST is in effect
  53. virtual time_duration_type dst_offset() const=0;
  54. //! Returns a POSIX time_zone string for this object
  55. virtual string_type to_posix_string() const =0;
  56. private:
  57. };
  58. //! Structure which holds the time offsets associated with daylight savings time
  59. /*!
  60. *@param time_duration_type A type used to represent the offset
  61. */
  62. template<class time_duration_type>
  63. class dst_adjustment_offsets
  64. {
  65. public:
  66. dst_adjustment_offsets(const time_duration_type& dst_adjust,
  67. const time_duration_type& dst_start_offset,
  68. const time_duration_type& dst_end_offset) :
  69. dst_adjust_(dst_adjust),
  70. dst_start_offset_(dst_start_offset),
  71. dst_end_offset_(dst_end_offset)
  72. {}
  73. //! Amount DST adjusts the clock eg: plus one hour
  74. time_duration_type dst_adjust_;
  75. //! Time past midnight on start transition day that dst starts
  76. time_duration_type dst_start_offset_;
  77. //! Time past midnight on end transition day that dst ends
  78. time_duration_type dst_end_offset_;
  79. };
  80. } } //namespace date_time
  81. #endif