Chris@16: #ifndef DATE_TIME_TIME_FORMATTING_STREAMS_HPP___ Chris@16: #define DATE_TIME_TIME_FORMATTING_STREAMS_HPP___ Chris@16: Chris@16: /* Copyright (c) 2002,2003 CrystalClear Software, Inc. Chris@16: * Use, modification and distribution is subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying Chris@16: * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Author: Jeff Garland, Bart Garst Chris@101: * $Date$ Chris@16: */ Chris@16: Chris@16: #include Chris@16: Chris@16: #ifndef BOOST_DATE_TIME_NO_LOCALE Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace date_time { Chris@16: Chris@16: Chris@16: //! Put a time type into a stream using appropriate facets Chris@16: template Chris@16: class ostream_time_duration_formatter Chris@16: { Chris@16: public: Chris@16: typedef std::basic_ostream ostream_type; Chris@16: typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type; Chris@16: Chris@16: //! Put time into an ostream Chris@16: static void duration_put(const time_duration_type& td, Chris@16: ostream_type& os) Chris@16: { Chris@16: if(td.is_special()) { Chris@16: os << td.get_rep(); Chris@16: } Chris@16: else { Chris@16: charT fill_char = '0'; Chris@16: if(td.is_negative()) { Chris@16: os << '-'; Chris@16: } Chris@16: os << std::setw(2) << std::setfill(fill_char) Chris@16: << absolute_value(td.hours()) << ":"; Chris@16: os << std::setw(2) << std::setfill(fill_char) Chris@16: << absolute_value(td.minutes()) << ":"; Chris@16: os << std::setw(2) << std::setfill(fill_char) Chris@16: << absolute_value(td.seconds()); Chris@16: fractional_seconds_type frac_sec = Chris@16: absolute_value(td.fractional_seconds()); Chris@16: if (frac_sec != 0) { Chris@16: os << "." Chris@16: << std::setw(time_duration_type::num_fractional_digits()) Chris@16: << std::setfill(fill_char) Chris@16: << frac_sec; Chris@16: } Chris@16: } // else Chris@16: } // duration_put Chris@16: }; //class ostream_time_duration_formatter Chris@16: Chris@16: //! Put a time type into a stream using appropriate facets Chris@16: template Chris@16: class ostream_time_formatter Chris@16: { Chris@16: public: Chris@16: typedef std::basic_ostream ostream_type; Chris@16: typedef typename time_type::date_type date_type; Chris@16: typedef typename time_type::time_duration_type time_duration_type; Chris@16: typedef ostream_time_duration_formatter duration_formatter; Chris@16: Chris@16: //! Put time into an ostream Chris@16: static void time_put(const time_type& t, Chris@16: ostream_type& os) Chris@16: { Chris@16: date_type d = t.date(); Chris@16: os << d; Chris@16: if(!d.is_infinity() && !d.is_not_a_date()) Chris@16: { Chris@16: os << " "; //TODO: fix the separator here. Chris@16: duration_formatter::duration_put(t.time_of_day(), os); Chris@16: } Chris@16: Chris@16: } // time_to_ostream Chris@16: }; //class ostream_time_formatter Chris@16: Chris@16: Chris@16: //! Put a time period into a stream using appropriate facets Chris@16: template Chris@16: class ostream_time_period_formatter Chris@16: { Chris@16: public: Chris@16: typedef std::basic_ostream ostream_type; Chris@16: typedef typename time_period_type::point_type time_type; Chris@16: typedef ostream_time_formatter time_formatter; Chris@16: Chris@16: //! Put time into an ostream Chris@16: static void period_put(const time_period_type& tp, Chris@16: ostream_type& os) Chris@16: { Chris@16: os << '['; //TODO: facet or manipulator for periods? Chris@16: time_formatter::time_put(tp.begin(), os); Chris@16: os << '/'; //TODO: facet or manipulator for periods? Chris@16: time_formatter::time_put(tp.last(), os); Chris@16: os << ']'; Chris@16: Chris@16: } // period_put Chris@16: Chris@16: }; //class ostream_time_period_formatter Chris@16: Chris@16: Chris@16: Chris@16: } } //namespace date_time Chris@16: Chris@16: #endif //BOOST_DATE_TIME_NO_LOCALE Chris@16: Chris@16: #endif