Boost C++ Libraries 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.

Class template time_facet



// In header: <boost/date_time/time_facet.hpp>

template<typename time_type, typename CharT, 
         typename OutItrT = std::ostreambuf_iterator<CharT, std::char_traits<CharT> > > 
class time_facet :
  public boost::date_time::date_facet< time_type::date_type, CharT, OutItrT >
  // types
  typedef time_type::date_type                                                          date_type;                    
  typedef time_type::time_duration_type                                                 time_duration_type;           
  typedef boost::date_time::period< time_type, time_duration_type >                     period_type;                  
  typedef boost::date_time::date_facet< typename time_type::date_type, CharT, OutItrT > base_type;                    
  typedef base_type::string_type                                                        string_type;                  
  typedef base_type::char_type                                                          char_type;                    
  typedef base_type::period_formatter_type                                              period_formatter_type;        
  typedef base_type::special_values_formatter_type                                      special_values_formatter_type;
  typedef base_type::date_gen_formatter_type                                            date_gen_formatter_type;      

  // construct/copy/destruct
  explicit time_facet(::size_t = 0);
  explicit time_facet(const char_type *, 
                      period_formatter_type = period_formatter_type(), 
                      const special_values_formatter_type & = special_values_formatter_type(), 
                      date_gen_formatter_type = date_gen_formatter_type(), 
                      ::size_t = 0);

  // public member functions
  std::locale::id & __get_id(void) const;
  void time_duration_format(const char_type *const);
  virtual void set_iso_format();
  virtual void set_iso_extended_format();
  OutItrT put(OutItrT, std::ios_base &, char_type, const time_type &) const;
  OutItrT put(OutItrT, std::ios_base &, char_type, const time_duration_type &) const;
  OutItrT put(OutItrT, std::ios_base &, char_type, const period_type &) const;

  // protected static functions
  static string_type 
  fractional_seconds_as_string(const time_duration_type &, bool);
  static string_type hours_as_string(const time_duration_type &, int = 2);
  template<typename IntT> static string_type integral_as_string(IntT, int = 2);

  // public data members
  static const char_type * fractional_seconds_format;
  static const char_type * fractional_seconds_or_none_format;
  static const char_type * seconds_with_fractional_seconds_format;
  static const char_type * seconds_format;
  static const char_type * hours_format;
  static const char_type * unrestricted_hours_format;
  static const char_type * standard_format;
  static const char_type * zone_abbrev_format;
  static const char_type * zone_name_format;
  static const char_type * zone_iso_format;
  static const char_type * zone_iso_extended_format;
  static const char_type * posix_zone_string_format;
  static const char_type * duration_seperator;
  static const char_type * duration_sign_always;
  static const char_type * duration_sign_negative_only;
  static const char_type * negative_sign;
  static const char_type * positive_sign;
  static const char_type * iso_time_format_specifier;
  static const char_type * iso_time_format_extended_specifier;
  static const char_type * default_time_format;
  static const char_type * default_time_duration_format;
  static std::locale::id id;


Facet used for format-based output of time types This class provides for the use of format strings to output times. In addition to the flags for formatting date elements, the following are the allowed format flags:

  • x X => default format - enables addition of more flags to default (ie. "%x %X %z")

  • f => fractional seconds ".123456"

  • F => fractional seconds or none: like frac sec but empty if frac sec == 0

  • s => seconds w/ fractional sec "02.123" (this is the same as "%S%f) - %S => seconds "02" - %z => abbreviated time zone "EDT" - %Z => full time zone name "Eastern Daylight Time"

time_facet public construct/copy/destruct

  1. explicit time_facet(::size_t ref_arg = 0);
    sets default formats for ptime, local_date_time, and time_duration
  2. explicit time_facet(const char_type * format_arg, 
                        period_formatter_type period_formatter_arg = period_formatter_type(), 
                        const special_values_formatter_type & special_value_formatter = special_values_formatter_type(), 
                        date_gen_formatter_type dg_formatter = date_gen_formatter_type(), 
                        ::size_t ref_arg = 0);
    Construct the facet with an explicitly specified format.

time_facet public member functions

  1. std::locale::id & __get_id(void) const;
  2. void time_duration_format(const char_type *const format);
    Changes format for time_duration.
  3. virtual void set_iso_format();
  4. virtual void set_iso_extended_format();
  5. OutItrT put(OutItrT next_arg, std::ios_base & ios_arg, char_type fill_arg, 
                const time_type & time_arg) const;
  6. OutItrT put(OutItrT next_arg, std::ios_base & ios_arg, char_type fill_arg, 
                const time_duration_type & time_dur_arg) const;
    put function for time_duration
  7. OutItrT put(OutItrT next, std::ios_base & ios_arg, char_type fill, 
                const period_type & p) const;

time_facet protected static functions

  1. static string_type 
    fractional_seconds_as_string(const time_duration_type & time_arg, 
                                 bool null_when_zero);
  2. static string_type 
    hours_as_string(const time_duration_type & time_arg, int width = 2);
  3. template<typename IntT> 
      static string_type integral_as_string(IntT val, int width = 2);