# Time Facet

Introduction - Construction - Accessors

Introduction

The `boost::date_time::time_facet` is an extension of the `boost::date_time::date_facet`. The time_facet is typedef'ed in the `posix_time` namespace as `time_facet` and `wtime_facet`. It is typedef'd in the `local_time` namespace as `local_time_facet` and `wlocal_time_facet`.

Construction

Syntax | Description
--- | ---

    time_facet()

Default constructor

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

Format given will be used for time 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, `time_facet("%H:%M:S %m %d %Y")` will work.

Accessors

The time_facet inherits all the public date_facet methods. Therefore, the date_facet methods are not listed here. Instead, they can be found by following this link.

Syntax | Description
--- | ---
Example

    void time_duration_format(...)
      Parameter:
        char_type*

Sets the time_duration format. The time_duration format has the ability to display the sign of the duration. The `'%+'` flag will always display the sign. The `'%-'` will only display if the sign is negative. Currently the '-' and '+' characters are used to denote the sign.

    f->time_duration_format("%+%H:%M");
    // hours and minutes only w/ sign always displayed
    time_duration td1(3, 15, 56);
    time_duration td2(-12, 25, 32);
    ss << td1; // "+03:15:56"
    ss << td2; // "-12:25:56"

    void set_iso_format()

Sets the date and time format to ISO.

    f->set_iso_format();
    // "%Y%m%dT%H%M%S%F%q"

    void set_iso_extended_format()

Sets the date and time format to ISO Extended

    f->set_iso_extended_format();
    // "%Y-%m-%d %H:%M:%S%F%Q"

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

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

    OutItrT put(..., ptime)

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

    OutItrT put(..., time_duration)

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

    OutItrT put(..., time_period)

Puts a time_period into the stream. The format of the dates and times will use the format set by `format(..)` or the default date/time format. The type of period (open or closed range) and the delimiters used are those used by the period_formatter.