mirror of
https://github.com/boostorg/date_time.git
synced 2026-02-23 15:42:20 +00:00
merge changes from RC_1_29_0 -- fix locale to support date order
[SVN r15560]
This commit is contained in:
@@ -33,11 +33,10 @@ namespace date_time {
|
||||
//! Formats a month as as string into an output iterator
|
||||
static void format_month(const month_type& month,
|
||||
ostream_type& os,
|
||||
const facet_type& f,
|
||||
month_format_spec fs)
|
||||
const facet_type& f)
|
||||
{
|
||||
|
||||
switch (fs)
|
||||
switch (f.month_format())
|
||||
{
|
||||
case month_as_short_string:
|
||||
{
|
||||
@@ -122,27 +121,55 @@ namespace date_time {
|
||||
// return ss.str();
|
||||
// }
|
||||
|
||||
|
||||
// Put ymd to ostream -- part of ostream refactor
|
||||
static void ymd_put(ymd_type ymd,
|
||||
ostream_type& os,
|
||||
const facet_type& f)
|
||||
{
|
||||
os << ymd.year;
|
||||
std::ostreambuf_iterator<charT> oitr(os);
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.month_sep_char(oitr);
|
||||
switch (f.date_order()) {
|
||||
case ymd_order_iso: {
|
||||
os << ymd.year;
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.month_sep_char(oitr);
|
||||
}
|
||||
month_formatter::format_month(ymd.month, os, f);
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.day_sep_char(oitr);
|
||||
}
|
||||
os << std::setw(2) << std::setfill('0')
|
||||
<< ymd.day;
|
||||
break;
|
||||
}
|
||||
case ymd_order_us: {
|
||||
month_formatter::format_month(ymd.month, os, f);
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.day_sep_char(oitr);
|
||||
}
|
||||
os << std::setw(2) << std::setfill('0')
|
||||
<< ymd.day;
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.month_sep_char(oitr);
|
||||
}
|
||||
os << ymd.year;
|
||||
break;
|
||||
}
|
||||
case ymd_order_dmy: {
|
||||
os << std::setw(2) << std::setfill('0')
|
||||
<< ymd.day;
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.day_sep_char(oitr);
|
||||
}
|
||||
month_formatter::format_month(ymd.month, os, f);
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.month_sep_char(oitr);
|
||||
}
|
||||
os << ymd.year;
|
||||
break;
|
||||
}
|
||||
}
|
||||
month_formatter::format_month(ymd.month, os,
|
||||
f, month_as_short_string);
|
||||
|
||||
|
||||
if (f.has_date_sep_chars()) {
|
||||
f.day_sep_char(oitr);
|
||||
}
|
||||
os << std::setw(2) << std::setfill('0')
|
||||
<< ymd.day;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "boost/date_time/special_defs.hpp"
|
||||
#include "boost/date_time/date_defs.hpp"
|
||||
#include "boost/date_time/parse_format_base.hpp"
|
||||
#include <locale>
|
||||
|
||||
|
||||
@@ -84,6 +85,16 @@ namespace date_time {
|
||||
{
|
||||
do_day_sep_char(oitr);
|
||||
}
|
||||
//! Determines the order to put the date elements
|
||||
ymd_order_spec date_order() const
|
||||
{
|
||||
return do_date_order();
|
||||
}
|
||||
//! Determines if month is displayed as integer, short or long string
|
||||
month_format_spec month_format() const
|
||||
{
|
||||
return do_month_format();
|
||||
}
|
||||
|
||||
protected:
|
||||
//! Default facet implementation uses month_type defaults
|
||||
@@ -145,7 +156,16 @@ namespace date_time {
|
||||
{
|
||||
put_string(oitr, "-");
|
||||
}
|
||||
|
||||
//! Default for date order
|
||||
virtual ymd_order_spec do_date_order() const
|
||||
{
|
||||
return ymd_order_iso;
|
||||
}
|
||||
//! Default month format
|
||||
virtual month_format_spec do_month_format() const
|
||||
{
|
||||
return month_as_short_string;
|
||||
}
|
||||
void put_string(iter_type& oi, const char* const s) const
|
||||
{
|
||||
string_type s1(s);
|
||||
@@ -169,12 +189,16 @@ namespace date_time {
|
||||
const char* const special_value_names[],
|
||||
const char* const weekday_short_names[],
|
||||
const char* const weekday_long_names[],
|
||||
char separator_char = '-') :
|
||||
char separator_char = '-',
|
||||
ymd_order_spec order_spec = ymd_order_iso,
|
||||
month_format_spec month_format = month_as_short_string) :
|
||||
month_short_names_(month_short_names),
|
||||
month_long_names_(month_long_names),
|
||||
special_value_names_(special_value_names),
|
||||
weekday_short_names_(weekday_short_names),
|
||||
weekday_long_names_(weekday_long_names)
|
||||
weekday_long_names_(weekday_long_names),
|
||||
order_spec_(order_spec),
|
||||
month_format_spec_(month_format)
|
||||
{
|
||||
separator_char_[0] = separator_char;
|
||||
separator_char_[1] = '\0';
|
||||
@@ -219,6 +243,16 @@ namespace date_time {
|
||||
{
|
||||
put_string(oitr, separator_char_);
|
||||
}
|
||||
//! Set the date ordering
|
||||
virtual ymd_order_spec do_date_order() const
|
||||
{
|
||||
return order_spec_;
|
||||
}
|
||||
//! Set the date ordering
|
||||
virtual month_format_spec do_month_format() const
|
||||
{
|
||||
return month_format_spec_;
|
||||
}
|
||||
|
||||
private:
|
||||
const char* const* month_short_names_;
|
||||
@@ -227,7 +261,8 @@ namespace date_time {
|
||||
const char* const* weekday_short_names_;
|
||||
const char* const* weekday_long_names_;
|
||||
char separator_char_[2];
|
||||
|
||||
ymd_order_spec order_spec_;
|
||||
month_format_spec month_format_spec_;
|
||||
};
|
||||
|
||||
} } //namespace boost::date_time
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace gregorian {
|
||||
std::locale locale = os.getloc();
|
||||
if (std::has_facet<greg_base_facet>(locale)) {
|
||||
const greg_base_facet& f = std::use_facet<greg_base_facet>(locale);
|
||||
greg_month_formatter::format_month(m, os, f, date_time::month_as_long_string);
|
||||
greg_month_formatter::format_month(m, os, f);
|
||||
|
||||
}
|
||||
else { //default to numeric
|
||||
|
||||
Reference in New Issue
Block a user