Use predefined formats for C-locale

This commit is contained in:
Vladislav Shchapov 2021-11-11 21:33:33 +05:00 committed by Victor Zverovich
parent a3ab36c803
commit be3a3a5aed

View File

@ -1018,13 +1018,16 @@ template <typename OutputIt, typename Char> class tm_writer {
format_localized('A'); format_localized('A');
} }
void on_dec0_weekday(numeric_system ns) { void on_dec0_weekday(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('w', 'O'); if (is_classic_ || ns == numeric_system::standard) return write1(tm_wday());
write1(tm_wday()); format_localized('w', 'O');
} }
void on_dec1_weekday(numeric_system ns) { void on_dec1_weekday(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('u', 'O'); if (is_classic_ || ns == numeric_system::standard) {
auto wday = tm_wday(); auto wday = tm_wday();
write1(wday == 0 ? days_per_week : wday); write1(wday == 0 ? days_per_week : wday);
} else {
format_localized('u', 'O');
}
} }
void on_abbr_month() { void on_abbr_month() {
@ -1095,49 +1098,63 @@ template <typename OutputIt, typename Char> class tm_writer {
void on_tz_name() { format_localized('Z'); } void on_tz_name() { format_localized('Z'); }
void on_year(numeric_system ns) { void on_year(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('Y', 'E'); if (is_classic_ || ns == numeric_system::standard)
write_year(tm_year()); return write_year(tm_year());
format_localized('Y', 'E');
} }
void on_short_year(numeric_system ns) { void on_short_year(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('y', 'O'); if (is_classic_ || ns == numeric_system::standard)
write2(split_year_lower(tm_year())); return write2(split_year_lower(tm_year()));
format_localized('y', 'O');
}
void on_offset_year() {
if (is_classic_) return write2(split_year_lower(tm_year()));
format_localized('y', 'E');
} }
void on_offset_year() { format_localized('y', 'E'); }
void on_century(numeric_system ns) { void on_century(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('C', 'E'); if (is_classic_ || ns == numeric_system::standard) {
auto year = tm_year(); auto year = tm_year();
auto upper = year / 100; auto upper = year / 100;
if (year >= -99 && year < 0) { if (year >= -99 && year < 0) {
// Zero upper on negative year. // Zero upper on negative year.
*out_++ = '-'; *out_++ = '-';
*out_++ = '0'; *out_++ = '0';
} else if (upper >= 0 && upper < 100) { } else if (upper >= 0 && upper < 100) {
write2(static_cast<int>(upper)); write2(static_cast<int>(upper));
} else {
out_ = write<Char>(out_, upper);
}
} else { } else {
out_ = write<Char>(out_, upper); format_localized('C', 'E');
} }
} }
void on_dec_month(numeric_system ns) { void on_dec_month(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('m', 'O'); if (is_classic_ || ns == numeric_system::standard)
write2(tm_mon() + 1); return write2(tm_mon() + 1);
format_localized('m', 'O');
} }
void on_dec0_week_of_year(numeric_system ns) { void on_dec0_week_of_year(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('U', 'O'); if (is_classic_ || ns == numeric_system::standard)
write2((tm_yday() + days_per_week - tm_wday()) / days_per_week); return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week);
format_localized('U', 'O');
} }
void on_dec1_week_of_year(numeric_system ns) { void on_dec1_week_of_year(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('W', 'O'); if (is_classic_ || ns == numeric_system::standard) {
auto wday = tm_wday(); auto wday = tm_wday();
write2((tm_yday() + days_per_week - write2((tm_yday() + days_per_week -
(wday == 0 ? (days_per_week - 1) : (wday - 1))) / (wday == 0 ? (days_per_week - 1) : (wday - 1))) /
days_per_week); days_per_week);
} else {
format_localized('W', 'O');
}
} }
void on_iso_week_of_year(numeric_system ns) { void on_iso_week_of_year(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('V', 'O'); if (is_classic_ || ns == numeric_system::standard)
write2(tm_iso_week_of_year()); return write2(tm_iso_week_of_year());
format_localized('V', 'O');
} }
void on_iso_week_based_year() { write_year(tm_iso_week_year()); } void on_iso_week_based_year() { write_year(tm_iso_week_year()); }
@ -1151,32 +1168,36 @@ template <typename OutputIt, typename Char> class tm_writer {
write2(yday % 100); write2(yday % 100);
} }
void on_day_of_month(numeric_system ns) { void on_day_of_month(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('d', 'O'); if (is_classic_ || ns == numeric_system::standard) return write2(tm_mday());
write2(tm_mday()); format_localized('d', 'O');
} }
void on_day_of_month_space(numeric_system ns) { void on_day_of_month_space(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('e', 'O'); if (is_classic_ || ns == numeric_system::standard) {
auto mday = to_unsigned(tm_mday()) % 100; auto mday = to_unsigned(tm_mday()) % 100;
const char* d2 = digits2(mday); const char* d2 = digits2(mday);
*out_++ = mday < 10 ? ' ' : d2[0]; *out_++ = mday < 10 ? ' ' : d2[0];
*out_++ = d2[1]; *out_++ = d2[1];
} else {
format_localized('e', 'O');
}
} }
void on_24_hour(numeric_system ns) { void on_24_hour(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('H', 'O'); if (is_classic_ || ns == numeric_system::standard) return write2(tm_hour());
write2(tm_hour()); format_localized('H', 'O');
} }
void on_12_hour(numeric_system ns) { void on_12_hour(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('I', 'O'); if (is_classic_ || ns == numeric_system::standard)
write2(tm_hour12()); return write2(tm_hour12());
format_localized('I', 'O');
} }
void on_minute(numeric_system ns) { void on_minute(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('M', 'O'); if (is_classic_ || ns == numeric_system::standard) return write2(tm_min());
write2(tm_min()); format_localized('M', 'O');
} }
void on_second(numeric_system ns) { void on_second(numeric_system ns) {
if (ns != numeric_system::standard) return format_localized('S', 'O'); if (is_classic_ || ns == numeric_system::standard) return write2(tm_sec());
write2(tm_sec()); format_localized('S', 'O');
} }
void on_12_hour_time() { void on_12_hour_time() {