Skip to content

Commit 1203f29

Browse files
authored
Merge 2021-10 LWG Motion 2
P2372R3 Fixing locale handling in chrono formatters
2 parents d027b53 + 582ec50 commit 1203f29

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609
#define @\defnlibxname{cpp_lib_exchange_function}@ 201304L // also in \libheader{utility}
610610
#define @\defnlibxname{cpp_lib_execution}@ 201902L // also in \libheader{execution}
611611
#define @\defnlibxname{cpp_lib_filesystem}@ 201703L // also in \libheader{filesystem}
612-
#define @\defnlibxname{cpp_lib_format}@ 202106L // also in \libheader{format}
612+
#define @\defnlibxname{cpp_lib_format}@ 202110L // also in \libheader{format}
613613
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}
614614
#define @\defnlibxname{cpp_lib_generic_associative_lookup}@ 201304L // also in \libheader{map}, \libheader{set}
615615
#define @\defnlibxname{cpp_lib_generic_unordered_lookup}@ 201811L

source/time.tex

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,9 +2717,7 @@
27172717
\effects
27182718
Equivalent to:
27192719
\begin{codeblock}
2720-
auto const dp = floor<days>(tp);
2721-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{} {}"),
2722-
year_month_day{dp}, hh_mm_ss{tp-dp});
2720+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@("{:L%F %T}"), tp);
27232721
\end{codeblock}
27242722

27252723
\pnum
@@ -2915,7 +2913,7 @@
29152913
\effects
29162914
Equivalent to:
29172915
\begin{codeblock}
2918-
return os << format(@\placeholder{STATICALLY-WIDEN}@<charT>("{:%F %T}"), t);
2916+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%F %T}"), t);
29192917
\end{codeblock}
29202918

29212919
\pnum
@@ -3121,7 +3119,7 @@
31213119
\effects
31223120
Equivalent to:
31233121
\begin{codeblock}
3124-
return os << format(@\placeholder{STATICALLY-WIDEN}@<charT>("{:%F %T}"), t);
3122+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%F %T}"), t);
31253123
\end{codeblock}
31263124

31273125
\pnum
@@ -3284,7 +3282,7 @@
32843282
\effects
32853283
Equivalent to:
32863284
\begin{codeblock}
3287-
return os << format(@\placeholder{STATICALLY-WIDEN}@<charT>("{:%F %T}"), t);
3285+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%F %T}"), t);
32883286
\end{codeblock}
32893287

32903288
\pnum
@@ -3407,7 +3405,7 @@
34073405
\effects
34083406
Equivalent to:
34093407
\begin{codeblock}
3410-
return os << format(@\placeholder{STATICALLY-WIDEN}@<charT>("{:%F %T}"), t);
3408+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%F %T}"), t);
34113409
\end{codeblock}
34123410
\end{itemdescr}
34133411

@@ -4483,7 +4481,7 @@
44834481
Equivalent to:
44844482
\begin{codeblock}
44854483
return os << (m.ok() ?
4486-
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:%b}"), m) :
4484+
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%b}"), m) :
44874485
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{} is not a valid month"),
44884486
static_cast<unsigned>(m)));
44894487
\end{codeblock}
@@ -5210,7 +5208,7 @@
52105208
Equivalent to:
52115209
\begin{codeblock}
52125210
return os << (wd.ok() ?
5213-
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:%a}"), wd) :
5211+
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%a}"), wd) :
52145212
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{} is not a valid weekday"),
52155213
static_cast<unsigned>(wd.wd_)));
52165214
\end{codeblock}
@@ -5364,8 +5362,8 @@
53645362
\begin{codeblock}
53655363
auto i = wdi.index();
53665364
return os << (i >= 1 && i <= 5 ?
5367-
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}[{}]"), wdi.weekday(), i) :
5368-
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}[{} is not a valid index]"),
5365+
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}[{}]"), wdi.weekday(), i) :
5366+
format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}[{} is not a valid index]"),
53695367
wdi.weekday(), i));
53705368
\end{codeblock}
53715369
\end{itemdescr}
@@ -5467,7 +5465,7 @@
54675465
\effects
54685466
Equivalent to:
54695467
\begin{codeblock}
5470-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}[last]"), wdl.weekday());
5468+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}[last]"), wdl.weekday());
54715469
\end{codeblock}
54725470
\end{itemdescr}
54735471

@@ -5594,7 +5592,7 @@
55945592
\effects
55955593
Equivalent to:
55965594
\begin{codeblock}
5597-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}"),
5595+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}/{}"),
55985596
md.month(), md.day());
55995597
\end{codeblock}
56005598
\end{itemdescr}
@@ -5731,7 +5729,7 @@
57315729
\effects
57325730
Equivalent to:
57335731
\begin{codeblock}
5734-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/last"), mdl.month());
5732+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}/last"), mdl.month());
57355733
\end{codeblock}
57365734
\end{itemdescr}
57375735

@@ -5844,7 +5842,7 @@
58445842
\effects
58455843
Equivalent to:
58465844
\begin{codeblock}
5847-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}"),
5845+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}/{:L}"),
58485846
mwd.month(), mwd.weekday_indexed());
58495847
\end{codeblock}
58505848
\end{itemdescr}
@@ -5960,7 +5958,7 @@
59605958
\effects
59615959
Equivalent to:
59625960
\begin{codeblock}
5963-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}"),
5961+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L}/{:L}"),
59645962
mwdl.month(), mwdl.weekday_last());
59655963
\end{codeblock}
59665964
\end{itemdescr}
@@ -6274,7 +6272,7 @@
62746272
\effects
62756273
Equivalent to:
62766274
\begin{codeblock}
6277-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}"),
6275+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{:L}"),
62786276
ym.year(), ym.month());
62796277
\end{codeblock}
62806278
\end{itemdescr}
@@ -7133,7 +7131,7 @@
71337131
\effects
71347132
Equivalent to:
71357133
\begin{codeblock}
7136-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}"),
7134+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{:L}"),
71377135
ymdl.year(), ymdl.month_day_last());
71387136
\end{codeblock}
71397137
\end{itemdescr}
@@ -7529,7 +7527,7 @@
75297527
\effects
75307528
Equivalent to:
75317529
\begin{codeblock}
7532-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}/{}"),
7530+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{:L}/{:L}"),
75337531
ymwd.year(), ymwd.month(), ymwd.weekday_indexed());
75347532
\end{codeblock}
75357533
\end{itemdescr}
@@ -7877,7 +7875,7 @@
78777875
\effects
78787876
Equivalent to:
78797877
\begin{codeblock}
7880-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{}/{}"),
7878+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{}/{:L}/{:L}"),
78817879
ymwdl.year(), ymwdl.month(), ymwdl.weekday_last());
78827880
\end{codeblock}
78837881
\end{itemdescr}
@@ -8623,7 +8621,7 @@
86238621
\effects
86248622
Equivalent to:
86258623
\begin{codeblock}
8626-
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:%T}"), hms);
8624+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@<charT>("{:L%T}"), hms);
86278625
\end{codeblock}
86288626

86298627
\pnum
@@ -10100,14 +10098,10 @@
1010010098
\begin{itemdescr}
1010110099
\pnum
1010210100
\effects
10103-
Streams
10104-
the value returned from \tcode{t.get_local_time()}
10105-
to \tcode{os}
10106-
using the format \tcode{"\%F \%T \%Z"}.
10107-
10108-
\pnum
10109-
\returns
10110-
\tcode{os}.
10101+
Equivalent to:
10102+
\begin{codeblock}
10103+
return os << format(os.getloc(), @\placeholder{STATICALLY-WIDEN}@("{:L%F %T %Z}"), t);
10104+
\end{codeblock}
1011110105
\end{itemdescr}
1011210106

1011310107
\rSec2[time.zone.leap]{Class \tcode{leap_second}}
@@ -10446,7 +10440,7 @@
1044610440

1044710441
\begin{ncbnf}
1044810442
\fmtnontermdef{chrono-format-spec}\br
10449-
\opt{fill-and-align} \opt{width} \opt{precision} \opt{chrono-specs}
10443+
\opt{fill-and-align} \opt{width} \opt{precision} \opt{\terminal{L}} \opt{chrono-specs}
1045010444
\end{ncbnf}
1045110445

1045210446
\begin{ncbnf}
@@ -10495,15 +10489,26 @@
1049510489
represented by \fmtgrammarterm{literal-char}
1049610490
are copied unchanged to the output.
1049710491

10492+
\pnum
10493+
A \defnadj{formatting}{locale} is an instance of \tcode{locale}
10494+
used by a formatting function, that is determined as follows:
10495+
\begin{itemize}
10496+
\item
10497+
the \tcode{"C"} locale if the \tcode{L} option
10498+
is not present in \fmtgrammarterm{chrono-format-spec}, otherwise
10499+
\item
10500+
the locale passed to the formatting function if any, otherwise
10501+
\item
10502+
the global locale.
10503+
\end{itemize}
10504+
1049810505
\pnum
1049910506
Each conversion specifier \fmtgrammarterm{conversion-spec}
1050010507
is replaced by appropriate characters
1050110508
as described in \tref{time.format.spec};
1050210509
the formats specified in ISO 8601:2004 shall be used where so described.
1050310510
Some of the conversion specifiers
10504-
depend on the locale that is passed to the formatting function
10505-
if the latter takes one,
10506-
or the global locale otherwise.
10511+
depend on the formatting locale.
1050710512
If the formatted object does not contain the information
1050810513
the conversion specifier refers to,
1050910514
an exception of type \tcode{format_error} is thrown.
@@ -10778,6 +10783,7 @@
1077810783
If the \fmtgrammarterm{chrono-specs} is omitted,
1077910784
the chrono object is formatted
1078010785
as if by streaming it to \tcode{std::ostringstream os}
10786+
with the formatting locale imbued
1078110787
and copying \tcode{os.str()} through the output iterator of the context
1078210788
with additional padding and adjustments as specified by the format specifiers.
1078310789
\begin{example}

0 commit comments

Comments
 (0)