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
f8542cd9
Commit
f8542cd9
authored
Oct 10, 2021
by
Vladislav Shchapov
Committed by
Victor Zverovich
Oct 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unified formatters for std::chrono::time_point<std::chrono::system_clock, Duration> and std::tm
parent
4707373d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
17 deletions
+18
-17
include/fmt/chrono.h
include/fmt/chrono.h
+18
-17
No files found.
include/fmt/chrono.h
View file @
f8542cd9
...
@@ -1694,17 +1694,13 @@ template <typename Char, typename Duration>
...
@@ -1694,17 +1694,13 @@ template <typename Char, typename Duration>
struct
formatter
<
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
,
Duration
>
,
struct
formatter
<
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
,
Duration
>
,
Char
>
:
formatter
<
std
::
tm
,
Char
>
{
Char
>
:
formatter
<
std
::
tm
,
Char
>
{
FMT_CONSTEXPR
formatter
()
{
FMT_CONSTEXPR
formatter
()
{
this
->
specs
=
{
default_specs
,
sizeof
(
default_specs
)
/
sizeof
(
Char
)};
this
->
do_parse
(
default_specs
,
default_specs
+
(
sizeof
(
default_specs
)
/
sizeof
(
Char
)));
}
}
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
auto
begin
=
ctx
.
begin
();
return
this
->
do_parse
(
ctx
.
begin
(),
ctx
.
end
(),
true
);
auto
end
=
ctx
.
end
();
if
(
begin
!=
end
&&
*
begin
==
':'
)
++
begin
;
end
=
detail
::
parse_chrono_format
(
begin
,
end
,
detail
::
tm_format_checker
());
if
(
end
!=
begin
)
this
->
specs
=
{
begin
,
detail
::
to_unsigned
(
end
-
begin
)};
return
end
;
}
}
template
<
typename
FormatContext
>
template
<
typename
FormatContext
>
...
@@ -1714,7 +1710,8 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
...
@@ -1714,7 +1710,8 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
return
formatter
<
std
::
tm
,
Char
>::
format
(
time
,
ctx
);
return
formatter
<
std
::
tm
,
Char
>::
format
(
time
,
ctx
);
}
}
static
constexpr
Char
default_specs
[]
=
{
'%'
,
'F'
,
' '
,
'%'
,
'T'
};
// '}' - for detail::parse_chrono_format.
static
constexpr
Char
default_specs
[]
=
{
'%'
,
'F'
,
' '
,
'%'
,
'T'
,
'}'
};
};
};
template
<
typename
Char
,
typename
Duration
>
template
<
typename
Char
,
typename
Duration
>
...
@@ -1730,17 +1727,17 @@ template <typename Char> struct formatter<std::tm, Char> {
...
@@ -1730,17 +1727,17 @@ template <typename Char> struct formatter<std::tm, Char> {
hh_mm_ss
,
hh_mm_ss
,
};
};
spec
spec_
=
spec
::
unknown
;
spec
spec_
=
spec
::
unknown
;
public:
basic_string_view
<
Char
>
specs
;
basic_string_view
<
Char
>
specs
;
template
<
typename
ParseContext
>
protected:
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
template
<
typename
It
>
auto
begin
=
ctx
.
begin
();
FMT_CONSTEXPR
auto
do_parse
(
It
begin
,
It
end
,
bool
with_default
=
false
)
auto
end
=
ctx
.
end
();
->
It
{
if
(
begin
!=
end
&&
*
begin
==
':'
)
++
begin
;
if
(
begin
!=
end
&&
*
begin
==
':'
)
++
begin
;
end
=
detail
::
parse_chrono_format
(
begin
,
end
,
detail
::
tm_format_checker
());
end
=
detail
::
parse_chrono_format
(
begin
,
end
,
detail
::
tm_format_checker
());
specs
=
{
begin
,
detail
::
to_unsigned
(
end
-
begin
)};
if
(
!
with_default
||
end
!=
begin
)
{
specs
=
{
begin
,
detail
::
to_unsigned
(
end
-
begin
)};
}
// basic_string_view<>::compare isn't constexpr before C++17
// basic_string_view<>::compare isn't constexpr before C++17
if
(
specs
.
size
()
==
2
&&
specs
[
0
]
==
Char
(
'%'
))
{
if
(
specs
.
size
()
==
2
&&
specs
[
0
]
==
Char
(
'%'
))
{
if
(
specs
[
1
]
==
Char
(
'F'
))
if
(
specs
[
1
]
==
Char
(
'F'
))
...
@@ -1751,12 +1748,17 @@ template <typename Char> struct formatter<std::tm, Char> {
...
@@ -1751,12 +1748,17 @@ template <typename Char> struct formatter<std::tm, Char> {
return
end
;
return
end
;
}
}
public:
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
this
->
do_parse
(
ctx
.
begin
(),
ctx
.
end
());
}
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_formatter
<
FormatContext
,
decltype
(
ctx
.
out
())
>
f
(
ctx
,
ctx
.
out
(),
detail
::
tm_formatter
<
FormatContext
,
decltype
(
ctx
.
out
())
>
f
(
ctx
,
ctx
.
out
(),
tm
);
tm
);
if
(
spec_
==
spec
::
year_month_day
)
{
if
(
spec_
==
spec
::
year_month_day
)
{
f
.
on_iso_date
();
f
.
on_iso_date
();
return
f
.
out
;
return
f
.
out
;
...
@@ -1764,7 +1766,6 @@ template <typename Char> struct formatter<std::tm, Char> {
...
@@ -1764,7 +1766,6 @@ template <typename Char> struct formatter<std::tm, Char> {
f
.
on_iso_time
();
f
.
on_iso_time
();
return
f
.
out
;
return
f
.
out
;
}
}
detail
::
parse_chrono_format
(
specs
.
begin
(),
specs
.
end
(),
f
);
detail
::
parse_chrono_format
(
specs
.
begin
(),
specs
.
end
(),
f
);
return
f
.
out
;
return
f
.
out
;
}
}
...
...
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