# Date Input Facet

Introduction - Construction - Accessors

Introduction

The `boost::date_time::date_input_facet` enables users to have significant control how dates (and other gregorian objects) are streamed in. The date_input_facet is typedef'd in the `gregorian` namespace as `date_input_facet` and `wdate_input_facet`.

Construction

Syntax | Description
--- | ---

    date_input_facet()

Default constructor

    date_input_facet(string_type format)

Format given will be used for date input. All other formats will use their defaults.

    date_input_facet(...)
      Parameters:
        string_type format
        format_date_parser_type
        special_values_parser_type
        period_parser_type
        date_gen_parser_type

Format given will be used for date input. The remaining parameters are parser objects. Further details on these objects can be found here.

Accessors

Syntax | Description
--- | ---
Example

    void format(char_type*)

Set the format for dates.

    date_input_facet* f =
        new date_input_facet();
    f->format("%m %d %Y");

    void set_iso_format()

Sets the date format to ISO

    f->set_iso_format();
    // "%Y%m%d"

    void set_iso_extended_format()

Sets the date format to ISO Extended

    f->set_iso_extended_format();
    // "%Y-%m-%d"

    void month_format(char_type*)

Set the format when 'get'ing months individually.

    f->month_format("%B");
    ss.str("March");
    ss >> m; // March

    void weekday_format(char_type*)

Set the format when 'get'ing weekdays individually.

    f->weekday_format("%a");
    ss.str("Sun");
    ss >> wd; // Sunday

    void year_format(char_type*)

Set the format when 'get'ing years individually.

    f->weekday_format("%y");
    ss.str("04");
    ss >> year; // 2004

    void period_parser(...)
      Parameter:
        period_parser_type

Replaces the period parser object with a user created one.

see the tutorial for a complete example.

    void special_values_parser(...)
      Parameter:
        special_values_parser_type

Replaces the special_values parser object with a user created one.

see the tutorial for a complete example.

    void date_gen_phrase_strings(...)
      Parameters:
        input_collection_type

Sets new date generator phrase strings in date_gen_parser. The input collection is a vector of strings (for details on these strings see date generator formatter/parser documentation).

    void short_weekday_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'getting' short weekdays.

see the tutorial for a complete example.

    void long_weekday_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'getting' long weekdays.

see the tutorial for a complete example.

    void short_month_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'getting' short months.

see the tutorial for a complete example.

    void long_month_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'getting' long months.

see the tutorial for a complete example.

    InItrT get(...)
      Common parameters for all
      'get' functions:
        InItrT from
        InItrT to
        ios_base
      Unique parameter for 'get' funcs:
        gregorian object

There are 13 get functions in the date_input_facet. The common parameters are: an iterator pointing to the begining of the stream, an iterator pointing to the end of the stream, and an ios_base object. Each unique gregorian object has it's own get function. Each unique get function is described below.

    InItrT get(..., date)

Gets a date object from the stream using the format set by `format(...)` or the default.

    ss.str("2005-Jan-01");
    ss >> d; // default format

    InItrT get(..., month)

Gets a month object from the stream using the format set by `month_format(...)` or the default.

    ss.str("Feb");
    ss >> m; // default format

    InItrT get(..., day_of_week)

Gets a day of week object from the stream using the format set by `weekday_format(...)` or the default.

    ss.str("Sun");
    ss >> dow; // default format

    InItrT get(..., day)

Gets a day of month object from the stream as a two digit number.

    "01" // January 1st

    InItrT get(..., year)

Gets a year object from the stream as a number. The number of expected digits depends on the year format.

    ss/str("2005");
    ss >> y; // default format

    InItrT get(..., days)

Gets a days object from the stream as a number.

    ss.str("356");
    ss >> dys; // a full year

    InItrT get(..., date_period)

Gets a date_period from the stream. The format of the dates will use the format set by `format(..)` or the default date format. The type of period (open or closed range) and the delimiters used are those used by the period_parser.

see the tutorial for a complete example.

    InItrT get(..., partial_date)

Gets a partial_date date_generator object from the stream. The month format used is set by `month_format(..)` or the default. The day of month is represented as a two digit number.

    "01 Jan" // default formats
    "01 January" // long month format

    InItrT get(..., date_generator)
      Date Generator Type:
        nth_day_of_the_week_in_month

Gets a nth_day_of_the_week_in_month object from the stream. The month format is set by `month_format(...)` or the default. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_parser.

    "third Fri in May" // defaults

    InItrT get(..., date_generator)
      Date Generator Type:
        first_day_of_the_week_in_month

Gets a first_day_of_the_week_in_month object from the stream. The month format is set by `month_format(...)` or the default. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_parser.

    "first Wed of Jun" // defaults

    InItrT get(..., date_generator)
      Date Generator Type:
        last_day_of_the_week_in_month

Gets a last_day_of_the_week_in_month object from the stream. The month format is set by `month_format(...)` or the default. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_parser.

    "last Tue of Mar" // defaults

    InItrT get(..., date_generator)
      Date Generator Type:
        first_day_of_the_week_after

Gets a first_day_of_the_week_after object from the stream. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_parser.

    "first Sat after" // defaults

    InItrT get(..., date_generator)
      Date Generator Type:
        first_day_of_the_week_before

Gets a first_day_of_the_week_before object from the stream. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_parser.

    "first Mon before" // defaults