time_zone_base.hpp 3.6 KB

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