Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template posix_time_zone_base

boost::local_time::posix_time_zone_base — A time zone class constructed from a POSIX time zone string.

Synopsis

// In header: <boost/date_time/local_time/posix_time_zone.hpp>

template<typename CharT> 
class posix_time_zone_base {
public:
  // types
  typedef boost::posix_time::time_duration                                                           time_duration_type;     
  typedef date_time::time_zone_names_base< CharT >                                                   time_zone_names;        
  typedef date_time::time_zone_base< posix_time::ptime, CharT >                                      base_type;              
  typedef base_type::string_type                                                                     string_type;            
  typedef CharT                                                                                      char_type;              
  typedef base_type::stringstream_type                                                               stringstream_type;      
  typedef boost::char_separator< char_type, std::char_traits< char_type > >                          char_separator_type;    
  typedef boost::tokenizer< char_separator_type, typename string_type::const_iterator, string_type > tokenizer_type;         
  typedef tokenizer_type::iterator                                                                   tokenizer_iterator_type;

  // construct/copy/destruct
  posix_time_zone_base(const string_type &);
  ~posix_time_zone_base();

  // public member functions
  string_type std_zone_abbrev() const;
  string_type dst_zone_abbrev() const;
  string_type std_zone_name() const;
  string_type dst_zone_name() const;
  bool has_dst() const;
  posix_time::ptime dst_local_start_time(gregorian::greg_year) const;
  posix_time::ptime dst_local_end_time(gregorian::greg_year) const;
  time_duration_type base_utc_offset() const;
  time_duration_type dst_offset() const;
  string_type to_posix_string() const;

  // private member functions
  void calc_zone(const string_type &);
  void calc_rules(const string_type &, const string_type &);
  void M_func(const string_type &, const string_type &);
  void julian_no_leap(const string_type &, const string_type &);
  void julian_day(const string_type &, const string_type &);

  // private static functions
  static std::string td_as_string(const time_duration_type &);
};

Description

A POSIX time zone string takes the form of:
"std offset dst [offset],start[/time],end[/time]" (w/no spaces) 'std' specifies the abbrev of the time zone.
'offset' is the offset from UTC.
'dst' specifies the abbrev of the time zone during daylight savings time.
The second offset is how many hours changed during DST. Default=1
'start' and'end' are the dates when DST goes into (and out of) effect.
'offset' takes the form of: [+|-]hh[:mm[:ss]] {h=0-23, m/s=0-59}
'time' and 'offset' take the same form. Time defaults=02:00:00
'start' and 'end' can be one of three forms:
Mm.w.d {month=1-12, week=1-5 (5 is always last), day=0-6}
Jn {n=1-365 Feb29 is never counted}
n {n=0-365 Feb29 is counted in leap years}
Example "PST-5PDT01:00:00,M4.1.0/02:00:00,M10.1.0/02:00:00"
Exceptions will be thrown under these conditions:
An invalid date spec (see date class)
A boost::local_time::bad_offset exception will be thrown for:
A DST start or end offset that is negative or more than 24 hours
A UTC zone that is greater than +14 or less than -12 hours
A boost::local_time::bad_adjustment exception will be thrown for:
A DST adjustment that is 24 hours or more (positive or negative)

Note that UTC zone offsets can be greater than +12: http://www.worldtimezone.com/utc/utc+1200.html

posix_time_zone_base public construct/copy/destruct

  1. posix_time_zone_base(const string_type & s);
    Construct from a POSIX time zone string.
  2. ~posix_time_zone_base();

posix_time_zone_base public member functions

  1. string_type std_zone_abbrev() const;
    String for the zone when not in daylight savings (eg: EST).
  2. string_type dst_zone_abbrev() const;
    String for the timezone when in daylight savings (eg: EDT).

    For those time zones that have no DST, an empty string is used

  3. string_type std_zone_name() const;
    String for the zone when not in daylight savings (eg: Eastern Standard Time).

    The full STD name is not extracted from the posix time zone string. Therefore, the STD abbreviation is used in it's place

  4. string_type dst_zone_name() const;
    String for the timezone when in daylight savings (eg: Eastern Daylight Time).

    The full DST name is not extracted from the posix time zone string. Therefore, the STD abbreviation is used in it's place. For time zones that have no DST, an empty string is used

  5. bool has_dst() const;
    True if zone uses daylight savings adjustments otherwise false.
  6. posix_time::ptime dst_local_start_time(gregorian::greg_year y) const;
    Local time that DST starts -- NADT if has_dst is false.
  7. posix_time::ptime dst_local_end_time(gregorian::greg_year y) const;
    Local time that DST ends -- NADT if has_dst is false.
  8. time_duration_type base_utc_offset() const;
    Base offset from UTC for zone (eg: -07:30:00).
  9. time_duration_type dst_offset() const;
    Adjustment forward or back made while DST is in effect.
  10. string_type to_posix_string() const;
    Returns a POSIX time_zone string for this object.

posix_time_zone_base private member functions

  1. void calc_zone(const string_type & obj);

    Extract time zone abbreviations for STD & DST as well as the offsets for the time shift that occurs and how much of a shift. At this time full time zone names are NOT extracted so the abbreviations are used in their place

  2. void calc_rules(const string_type & start, const string_type & end);
  3. void M_func(const string_type & s, const string_type & e);
  4. void julian_no_leap(const string_type & s, const string_type & e);
    Julian day. Feb29 is never counted, even in leap years.
  5. void julian_day(const string_type & s, const string_type & e);
    Julian day. Feb29 is always counted, but exception thrown in non-leap years.

posix_time_zone_base private static functions

  1. static std::string td_as_string(const time_duration_type & td);
    helper function used when throwing exceptions

PrevUpHomeNext