# Date Facet

Introduction - Construction - Accessors

Introduction

The `boost::date_time::date_facet` enables users to have significant control over the output streaming of dates (and other gregorian objects). The date_facet is typedef'd in the `gregorian` namespace as `date_facet` and `wdate_facet`.

Construction

Syntax | Description
--- | ---

    date_facet()

Default constructor

    date_facet(...)
      Parameters:
        char_type* format
        input_collection_type

Format given will be used for date output. All other formats will use their defaults. Collection is the set of short names to be used for months. All other name collections will use their defaults.

    date_facet(...)
      Parameters:
        char_type* format
        period_formatter_type
        special_values_formatter_type
        date_gen_formatter_type

Format given will be used for date output. The remaining parameters are formatter objects. Further details on these objects can be found here. This constructor also provides default arguments for all parameters except the format. Therefore, `date_facet("%m %d %Y")` will work.

Accessors

Syntax | Description
--- | ---
Example

    void format(char_type*)

Set the format for dates.

    date_facet* f = new date_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 for months when they are 'put' individually.

    f->month_format("%B");
    ss << greg_month(12); // "December"

    void weekday_format(char_type*)

Set the format for weekdays when they are 'put' individually.

    f->weekday_format("%a");
    ss << greg_weekday(2); // "Tue"

    void period_formatter(...)
      Parameter:
        period_formatter_type

Replaces the period formatter object with a user created one.

see the tutorial for a complete example.

    void special_values_formatter(...)
      Parameter:
        special_values_formatter_type

Replaces the special_values formatter object with a user created one.

see the tutorial for a complete example.

    void date_gen_phrase_strings(...)
      Parameters:
        input_collection_type
        date_gen_formatter_type::
          phrase_elements

Sets new date generator phrase strings in date_gen_formatter. The input collection is a vector of strings (for details on these strings see date generator formatter/parser documentation). The phrase_elements parameter is an enum, defined in the date_generator_formatter object, that has a default value of 'first'. It is used to indicate what the position of the first string in the collection will be.

    void short_weekday_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'putting' short weekdays.

see the tutorial for a complete example.

    void long_weekday_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'putting' long weekdays.

see the tutorial for a complete example.

    void short_month_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'putting' short months.

see the tutorial for a complete example.

    void long_month_names(...)
      Parameter:
        input_collection_type

Replace strings used when 'putting' long months.

see the tutorial for a complete example.

    OutItrT put(...)
      Common parameters for all
      'put' functions:
        OutItrT
        ios_base
        char_type
      Unique parameter for 'put' funcs:
        gregorian object

There are 12 put functions in the date_facet. The common paraeters are: an iterator pointing to the next item in the stream, an ios_base object, and the fill character. Each unique gregorian object has it's own put function. Each unique put function is described below.

    OutItrT put(..., date)

Puts a date object into the stream using the format set by `format(...)` or the default.

    OutItrT put(..., days)

Puts a days object into the stream as a number.

    OutItrT put(..., month)

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

    OutItrT put(..., day)

Puts a day of month object into the stream as a two digit number.

    "01" // January 1st

    OutItrT put(..., day_of_week)

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

    OutItrT put(..., date_period)

Puts a date_period into 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_formatter.

    OutItrT put(..., partial_date)

Puts a partial_date date_generator object into 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

    OutItrT put(..., date_generator)
      Date Generator Type:
        nth_day_of_the_week_in_month

Puts a nth_day_of_the_week_in_month object into 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_formatter.

    "third Fri in May" // defaults

    OutItrT put(..., date_generator)
      Date Generator Type:
        first_day_of_the_week_in_month

Puts a first_day_of_the_week_in_month object into 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_formatter.

    "first Wed of Jun" // defaults

    OutItrT put(..., date_generator)
      Date Generator Type:
        last_day_of_the_week_in_month

Puts a last_day_of_the_week_in_month object into 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_formatter.

    "last Tue of Mar" // defaults

    OutItrT put(..., date_generator)
      Date Generator Type:
        first_day_of_the_week_after

Puts a first_day_of_the_week_after object into the stream. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_formatter.

    "first Sat after" // defaults

    OutItrT put(..., date_generator)
      Date Generator Type:
        first_day_of_the_week_before

Puts a first_day_of_the_week_before object into the stream. The weekday format is set by `weekday_format(...)` or the default. The remaining phrase elements are set in the date_generator_formatter.

    "first Mon before" // defaults