Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template format_date_parser

boost::date_time::format_date_parser — Class with generic date parsing using a format string.

Synopsis

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

template<typename date_type, typename charT> 
class format_date_parser {
public:
  // types
  typedef                 ;          
  typedef          ;    
  typedef          ;      
  typedef                ;            
  typedef                       ;            
  typedef                      ;           
  typedef                        ;             
  typedef                   ;        
  typedef                ;     
  typedef                ;     
  typedef string_parse_tree<                 ;      
  typedef parse_tree_type::parse_match_result_type  ;        
  typedef  ;

  // construct/copy/destruct
  (, , 
                     , 
                     , 
                     );
  (, );
  (format_date_parser< );

  // public member functions
   () ;
   ();
   ();
   ();
   ();
   ();
   (, , 
                       special_values_parser< ) ;
   (, 
                       , 
                       special_values_parser< ) ;
   (, 
                       , , 
                       special_values_parser< ) ;
   (, 
                         , ) ;
   (, 
                         , , 
                         match_results &) ;
   (, 
                                  ) ;
   (, 
                              ) ;
   
  (, 
                , ) ;
   
  (, 
                , , 
                match_results &) ;
   (, 
                       , ) ;
   (, 
                       , , 
                       match_results &) ;
};

Description

The following is the set of recognized format specifiers

  • a - Short weekday name

  • A - Long weekday name

  • b - Abbreviated month name

  • B - Full month name

  • d - Day of the month as decimal 01 to 31

  • j - Day of year as decimal from 001 to 366

  • m - Month name as a decimal 01 to 12

  • U - Week number 00 to 53 with first Sunday as the first day of week 1?

  • w - Weekday as decimal number 0 to 6 where Sunday == 0

  • W - Week number 00 to 53 where Monday is first day of week 1

  • x - facet default date representation

  • y - Year without the century - eg: 04 for 2004

  • Y - Year with century

The weekday specifiers (a and A) do not add to the date construction, but they provide a way to skip over the weekday names for formats that provide them.

todo – Another interesting feature that this approach could provide is an option to fill in any missing fields with the current values from the clock. So if you have m-d the parser would detect the missing year value and fill it in using the clock.

todo – What to do with the x. x in the classic facet is just bad...

format_date_parser public construct/copy/destruct

  1. ( format_str, 
                        month_short_names, 
                        month_long_names, 
                        weekday_short_names, 
                        weekday_long_names);
  2. ( format_str,  locale);
  3. (format_date_parser<  fdp);

format_date_parser public member functions

  1.  () ;
  2.  ( format_str);
  3.  ( month_names);
  4.  ( month_names);
  5.  ( weekday_names);
  6.  ( weekday_names);
  7.  ( value, 
                          format_str, 
                         special_values_parser<  sv_parser) ;
  8.  ( sitr, 
                          stream_end, 
                         special_values_parser<  sv_parser) ;
  9.  ( sitr, 
                          stream_end, 
                          format_str, 
                         special_values_parser<  sv_parser) ;

    Of all the objects that the format_date_parser can parse, only a date can be a special value. Therefore, only parse_date checks for special_values.

  10.  ( sitr, 
                            stream_end, 
                            format_str) ;
    Throws bad_month if unable to parse.
  11.  ( sitr, 
                            stream_end, 
                            format_str, match_results & mr) ;
    Throws bad_month if unable to parse.
  12.  ( sitr, 
                                     stream_end) ;
    Expects 1 or 2 digits 1-31. Throws bad_day_of_month if unable to parse.
  13.  ( sitr, 
                                 stream_end) ;
    Expects 2 digits 01-31. Throws bad_day_of_month if unable to parse.
  14.  
    ( sitr, 
                   stream_end, 
                   format_str) ;
  15.  
    ( sitr, 
                   stream_end, 
                   format_str, match_results & mr) ;
  16.  ( sitr, 
                          stream_end, 
                          format_str) ;
    throws bad_year if unable to parse
  17.  ( sitr, 
                          stream_end, 
                          format_str, match_results & mr) ;
    throws bad_year if unable to parse

PrevUpHomeNext