The behavior of the time facets can still be customized if you are on a platform that does not support a file system, or if you do not wish to use data files for other reasons. Naturally, you can derive from time_get and time_put and override each of the virtual methods in a portable manner as specified by the C++ standard. Additionally you can take advantage of the EWL C++ implementation if you wish (to make your job easier if portability is not a concern).
The central theme of the EWL time facets design is a non-standard facet class called std::timepunct:
template <class charT> class timepunct : public locale::facet { public: typedef charT char_type; typedef basic_string<charT> string_type; explicit timepunct(size_t refs = 0); const string_type& abrev_weekday(int wday) const {return __weekday_names_[7+wday];} const string_type& weekday(int wday) const {return __weekday_names_[wday];} const string_type& abrev_monthname(int mon) const {return __month_names_[12+mon];} const string_type& monthname(int mon) const { return __month_names_[mon];} const string_type& date_time() const {return __date_time_;} const string_type& am_pm(int hour) const {return __am_pm_[hour/12];} const string_type& time_12hour() const { return __12hr_time_;} const string_type& date() const {return __date_;} const string_type& time() const {return __time_;} const string_type& time_zone(int isdst) const {return __time_zone_[isdst];} const string_type& utc_offset(int isdst) const {return __utc_offset_[bool(isdst)];} int default_century() const {return __default_century_;} static locale::id id; protected: virtual ~timepunct() {} string_type __weekday_names_[14]; string_type __month_names_[24]; string_type __am_pm_[2]; string_type __date_time_; string_type __date_; string_type __time_; string_type __12hr_time_; string_type __time_zone_[2]; string_type __utc_offset_[2]; int __default_century_; };
This class is analogous to numpunct and moneypunct. It holds all of the configurable data. The facets time_get and time_put refer to timepunct for the data and then behave accordingly. All of the data in timepunct is protected so that the constructor of a derived facet can set this data however it sees fit. The timepunct facet will set this data according to the "C" locale.
Both the full weekday names and the abbreviated weekday names are stored in __weekday_names_. The full names occupy the first seven elements of the array, and the abbreviated names get the last seven slots. Similarly for __month_names_.
The __am_pm_ member holds the strings that represent AM and PM, in that order.
The __date_time_ member holds the formatting/parsing string for the date-and-time. This is the member that gets queried when %c comes up. Do not put %c in this string or an infinite recursion will occur. The default for this string is "%A %B %d %T %Y".
The __date_ member holds the formatting/parsing string for the date. This is the member that gets queried when %x comes up. Do not put %x in this string or an infinite recursion will occur. The default for this string is " %A %B %d %Y".
The __time_ member holds the formatting/parsing string for the time. This is the member that gets queried when %X comes up. Do not put %X in this string or an infinite recursion will occur. The default for this string is " %H:%M:%S".
The __12hr_time_ member holds the formatting/parsing string for the 12-hour-time. This is the member that gets queried when %r comes up. Do not put %r in this string or an infinite recursion will occur. The default for this string is "%I:%M:%S %p".
The __time_zone_ member contains two strings. The first is the name of the time zone when Daylight Savings Time is not in effect. The second string is the name of the time zone when Daylight Savings Time is in effect. These can be used to parse or format the tm_isdst member of a tm. These strings may be empty (as they are in the "C" locale) which means that time zone information is not available.
The __utc_offset_ member contains two strings. The first represents the UTC offset when Daylight Savings Time is not in effect. The second string is the offset when Daylight Savings Time is in effect. These can be used to parse or format the tm_isdst member of a tm. These strings may be empty (as they are in the "C" locale) which means that UTC offset information is not available.
The final member, __default_century_ is an int representing the default century to assume when parsing a two digit year with %y. The value 19 represents the 1900's, 20 represent's the 2000's, etc. The default is 20.
It is a simple matter to derive from timepunct and set these data members to whatever you see fit.