Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
7a604cdd
Commit
7a604cdd
authored
Oct 17, 2021
by
Vladislav Shchapov
Committed by
Victor Zverovich
Oct 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
aeb54b0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
16 deletions
+13
-16
include/fmt/chrono.h
include/fmt/chrono.h
+13
-16
No files found.
include/fmt/chrono.h
View file @
7a604cdd
...
@@ -1399,11 +1399,9 @@ struct tm_format_checker : null_chrono_spec_handler<tm_format_checker> {
...
@@ -1399,11 +1399,9 @@ struct tm_format_checker : null_chrono_spec_handler<tm_format_checker> {
FMT_CONSTEXPR
void
on_tz_name
()
{}
FMT_CONSTEXPR
void
on_tz_name
()
{}
};
};
template
<
typename
FormatContext
,
typename
OutputIt
>
class
tm_writer
{
template
<
typename
OutputIt
,
typename
Char
>
class
tm_writer
{
using
char_type
=
typename
FormatContext
::
char_type
;
static
constexpr
int
days_per_week
=
7
;
static
constexpr
int
days_per_week
=
7
;
FormatContext
&
ctx_
;
OutputIt
out_
;
OutputIt
out_
;
const
std
::
tm
&
tm_
;
const
std
::
tm
&
tm_
;
...
@@ -1480,7 +1478,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1480,7 +1478,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
to_unsigned
(
to_nonnegative_int
(
year
,
max_value
<
int
>
()));
to_unsigned
(
to_nonnegative_int
(
year
,
max_value
<
int
>
()));
const
int
num_digits
=
count_digits
(
n
);
const
int
num_digits
=
count_digits
(
n
);
if
(
width
>
num_digits
)
out_
=
std
::
fill_n
(
out_
,
width
-
num_digits
,
'0'
);
if
(
width
>
num_digits
)
out_
=
std
::
fill_n
(
out_
,
width
-
num_digits
,
'0'
);
out_
=
format_decimal
<
char_type
>
(
out_
,
n
,
num_digits
).
end
;
out_
=
format_decimal
<
Char
>
(
out_
,
n
,
num_digits
).
end
;
}
}
}
}
...
@@ -1488,7 +1486,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1488,7 +1486,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
// By prepending an extra space we can distinguish an empty result that
// By prepending an extra space we can distinguish an empty result that
// indicates insufficient buffer size from a guaranteed non-empty result
// indicates insufficient buffer size from a guaranteed non-empty result
// https://github.com/fmtlib/fmt/issues/2238
// https://github.com/fmtlib/fmt/issues/2238
char_type
tm_format
[
5
]
=
{
' '
,
'%'
,
'x'
,
'\0'
,
'\0'
};
Char
tm_format
[
5
]
=
{
' '
,
'%'
,
'x'
,
'\0'
,
'\0'
};
if
(
modifier
)
{
if
(
modifier
)
{
tm_format
[
2
]
=
modifier
;
tm_format
[
2
]
=
modifier
;
tm_format
[
3
]
=
format
;
tm_format
[
3
]
=
format
;
...
@@ -1496,7 +1494,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1496,7 +1494,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
tm_format
[
2
]
=
format
;
tm_format
[
2
]
=
format
;
}
}
basic_memory_buffer
<
char_type
>
buf
;
basic_memory_buffer
<
Char
>
buf
;
for
(;;)
{
for
(;;)
{
size_t
size
=
buf
.
capacity
();
size_t
size
=
buf
.
capacity
();
size_t
count
=
detail
::
strftime
(
buf
.
data
(),
size
,
tm_format
,
&
tm_
);
size_t
count
=
detail
::
strftime
(
buf
.
data
(),
size
,
tm_format
,
&
tm_
);
...
@@ -1508,17 +1506,16 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1508,17 +1506,16 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
buf
.
reserve
(
buf
.
capacity
()
+
(
size
>
MIN_GROWTH
?
size
:
MIN_GROWTH
));
buf
.
reserve
(
buf
.
capacity
()
+
(
size
>
MIN_GROWTH
?
size
:
MIN_GROWTH
));
}
}
// Remove the extra space.
// Remove the extra space.
out_
=
copy_str
<
char_type
>
(
buf
.
begin
()
+
1
,
buf
.
end
(),
out_
);
out_
=
copy_str
<
Char
>
(
buf
.
begin
()
+
1
,
buf
.
end
(),
out_
);
}
}
public:
public:
explicit
tm_writer
(
FormatContext
&
ctx
,
OutputIt
out
,
const
std
::
tm
&
tm
)
explicit
tm_writer
(
OutputIt
out
,
const
std
::
tm
&
tm
)
:
out_
(
out
),
tm_
(
tm
)
{}
:
ctx_
(
ctx
),
out_
(
out
),
tm_
(
tm
)
{}
OutputIt
out
()
const
{
return
out_
;
}
OutputIt
out
()
const
{
return
out_
;
}
FMT_CONSTEXPR
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
FMT_CONSTEXPR
void
on_text
(
const
Char
*
begin
,
const
Char
*
end
)
{
out_
=
copy_str
<
char_type
>
(
begin
,
end
,
out_
);
out_
=
copy_str
<
Char
>
(
begin
,
end
,
out_
);
}
}
void
on_abbr_weekday
()
{
format_localized
(
'a'
);
}
void
on_abbr_weekday
()
{
format_localized
(
'a'
);
}
void
on_full_weekday
()
{
format_localized
(
'A'
);
}
void
on_full_weekday
()
{
format_localized
(
'A'
);
}
...
@@ -1551,7 +1548,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1551,7 +1548,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
write_digit2_separated
(
buf
,
to_unsigned
(
tm_
.
tm_mon
+
1
),
write_digit2_separated
(
buf
,
to_unsigned
(
tm_
.
tm_mon
+
1
),
to_unsigned
(
tm_
.
tm_mday
),
to_unsigned
(
tm_
.
tm_mday
),
to_unsigned
(
split_year_lower
(
tm_year
())),
'/'
);
to_unsigned
(
split_year_lower
(
tm_year
())),
'/'
);
out_
=
copy_str
<
char_type
>
(
std
::
begin
(
buf
),
std
::
end
(
buf
),
out_
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
),
std
::
end
(
buf
),
out_
);
}
}
void
on_iso_date
()
{
void
on_iso_date
()
{
auto
year
=
tm_year
();
auto
year
=
tm_year
();
...
@@ -1566,7 +1563,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1566,7 +1563,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
}
}
write_digit2_separated
(
buf
+
2
,
year
%
100
,
to_unsigned
(
tm_
.
tm_mon
+
1
),
write_digit2_separated
(
buf
+
2
,
year
%
100
,
to_unsigned
(
tm_
.
tm_mon
+
1
),
to_unsigned
(
tm_
.
tm_mday
),
'-'
);
to_unsigned
(
tm_
.
tm_mday
),
'-'
);
out_
=
copy_str
<
char_type
>
(
std
::
begin
(
buf
)
+
offset
,
std
::
end
(
buf
),
out_
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
)
+
offset
,
std
::
end
(
buf
),
out_
);
}
}
void
on_utc_offset
()
{
format_localized
(
'z'
);
}
void
on_utc_offset
()
{
format_localized
(
'z'
);
}
void
on_tz_name
()
{
format_localized
(
'Z'
);
}
void
on_tz_name
()
{
format_localized
(
'Z'
);
}
...
@@ -1594,7 +1591,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1594,7 +1591,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
}
else
if
(
upper
>=
0
&&
upper
<
100
)
}
else
if
(
upper
>=
0
&&
upper
<
100
)
write2
(
to_unsigned
(
upper
));
write2
(
to_unsigned
(
upper
));
else
else
out_
=
write
<
char_type
>
(
out_
,
upper
);
out_
=
write
<
Char
>
(
out_
,
upper
);
}
else
}
else
format_localized
(
'C'
,
'E'
);
format_localized
(
'C'
,
'E'
);
}
}
...
@@ -1684,7 +1681,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
...
@@ -1684,7 +1681,7 @@ template <typename FormatContext, typename OutputIt> class tm_writer {
write_digit2_separated
(
buf
,
to_unsigned
(
tm_
.
tm_hour
),
write_digit2_separated
(
buf
,
to_unsigned
(
tm_
.
tm_hour
),
to_unsigned
(
tm_
.
tm_min
),
to_unsigned
(
tm_
.
tm_sec
),
to_unsigned
(
tm_
.
tm_min
),
to_unsigned
(
tm_
.
tm_sec
),
':'
);
':'
);
out_
=
copy_str
<
char_type
>
(
std
::
begin
(
buf
),
std
::
end
(
buf
),
out_
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
),
std
::
end
(
buf
),
out_
);
}
}
void
on_am_pm
()
{
format_localized
(
'p'
);
}
void
on_am_pm
()
{
format_localized
(
'p'
);
}
...
@@ -1762,7 +1759,7 @@ template <typename Char> struct formatter<std::tm, Char> {
...
@@ -1762,7 +1759,7 @@ template <typename Char> struct formatter<std::tm, Char> {
template
<
typename
FormatContext
>
template
<
typename
FormatContext
>
auto
format
(
const
std
::
tm
&
tm
,
FormatContext
&
ctx
)
const
auto
format
(
const
std
::
tm
&
tm
,
FormatContext
&
ctx
)
const
->
decltype
(
ctx
.
out
())
{
->
decltype
(
ctx
.
out
())
{
detail
::
tm_writer
<
FormatContext
,
decltype
(
ctx
.
out
())
>
f
(
ctx
,
ctx
.
out
(),
tm
);
detail
::
tm_writer
<
decltype
(
ctx
.
out
()),
Char
>
f
(
ctx
.
out
(),
tm
);
if
(
spec_
==
spec
::
year_month_day
)
if
(
spec_
==
spec
::
year_month_day
)
f
.
on_iso_date
();
f
.
on_iso_date
();
else
if
(
spec_
==
spec
::
hh_mm_ss
)
else
if
(
spec_
==
spec
::
hh_mm_ss
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment