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
aa5517f6
Commit
aa5517f6
authored
Nov 13, 2021
by
Vladislav Shchapov
Committed by
Victor Zverovich
Nov 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse tm_writer in chrono_formatter
parent
50140be7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
include/fmt/chrono.h
include/fmt/chrono.h
+13
-9
No files found.
include/fmt/chrono.h
View file @
aa5517f6
...
@@ -1412,6 +1412,7 @@ struct chrono_formatter {
...
@@ -1412,6 +1412,7 @@ struct chrono_formatter {
bool
negative
;
bool
negative
;
using
char_type
=
typename
FormatContext
::
char_type
;
using
char_type
=
typename
FormatContext
::
char_type
;
using
tm_writer_type
=
tm_writer
<
OutputIt
,
char_type
>
;
chrono_formatter
(
FormatContext
&
ctx
,
OutputIt
o
,
chrono_formatter
(
FormatContext
&
ctx
,
OutputIt
o
,
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
...
@@ -1493,10 +1494,13 @@ struct chrono_formatter {
...
@@ -1493,10 +1494,13 @@ struct chrono_formatter {
void
write_pinf
()
{
std
::
copy_n
(
"inf"
,
3
,
out
);
}
void
write_pinf
()
{
std
::
copy_n
(
"inf"
,
3
,
out
);
}
void
write_ninf
()
{
std
::
copy_n
(
"-inf"
,
4
,
out
);
}
void
write_ninf
()
{
std
::
copy_n
(
"-inf"
,
4
,
out
);
}
void
format_localized
(
const
tm
&
time
,
char
format
,
char
modifier
=
0
)
{
template
<
typename
Callback
,
typename
...
Args
>
void
format_tm
(
const
tm
&
time
,
Callback
cb
,
Args
...
args
)
{
if
(
isnan
(
val
))
return
write_nan
();
if
(
isnan
(
val
))
return
write_nan
();
out
=
detail
::
write
<
char_type
>
(
get_locale
loc
(
localized
,
context
.
locale
());
out
,
time
,
get_locale
(
localized
,
context
.
locale
()),
format
,
modifier
);
auto
w
=
tm_writer_type
(
loc
,
out
,
time
);
(
w
.
*
cb
)(
args
...);
out
=
w
.
out
();
}
}
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
...
@@ -1537,7 +1541,7 @@ struct chrono_formatter {
...
@@ -1537,7 +1541,7 @@ struct chrono_formatter {
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour
(),
2
);
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour
(),
2
);
auto
time
=
tm
();
auto
time
=
tm
();
time
.
tm_hour
=
to_nonnegative_int
(
hour
(),
24
);
time
.
tm_hour
=
to_nonnegative_int
(
hour
(),
24
);
format_
localized
(
time
,
'H'
,
'O'
);
format_
tm
(
time
,
&
tm_writer_type
::
on_24_hour
,
ns
);
}
}
void
on_12_hour
(
numeric_system
ns
)
{
void
on_12_hour
(
numeric_system
ns
)
{
...
@@ -1546,7 +1550,7 @@ struct chrono_formatter {
...
@@ -1546,7 +1550,7 @@ struct chrono_formatter {
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour12
(),
2
);
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour12
(),
2
);
auto
time
=
tm
();
auto
time
=
tm
();
time
.
tm_hour
=
to_nonnegative_int
(
hour12
(),
12
);
time
.
tm_hour
=
to_nonnegative_int
(
hour12
(),
12
);
format_
localized
(
time
,
'I'
,
'O'
);
format_
tm
(
time
,
&
tm_writer_type
::
on_12_hour
,
ns
);
}
}
void
on_minute
(
numeric_system
ns
)
{
void
on_minute
(
numeric_system
ns
)
{
...
@@ -1555,7 +1559,7 @@ struct chrono_formatter {
...
@@ -1555,7 +1559,7 @@ struct chrono_formatter {
if
(
ns
==
numeric_system
::
standard
)
return
write
(
minute
(),
2
);
if
(
ns
==
numeric_system
::
standard
)
return
write
(
minute
(),
2
);
auto
time
=
tm
();
auto
time
=
tm
();
time
.
tm_min
=
to_nonnegative_int
(
minute
(),
60
);
time
.
tm_min
=
to_nonnegative_int
(
minute
(),
60
);
format_
localized
(
time
,
'M'
,
'O'
);
format_
tm
(
time
,
&
tm_writer_type
::
on_minute
,
ns
);
}
}
void
on_second
(
numeric_system
ns
)
{
void
on_second
(
numeric_system
ns
)
{
...
@@ -1580,12 +1584,12 @@ struct chrono_formatter {
...
@@ -1580,12 +1584,12 @@ struct chrono_formatter {
}
}
auto
time
=
tm
();
auto
time
=
tm
();
time
.
tm_sec
=
to_nonnegative_int
(
second
(),
60
);
time
.
tm_sec
=
to_nonnegative_int
(
second
(),
60
);
format_
localized
(
time
,
'S'
,
'O'
);
format_
tm
(
time
,
&
tm_writer_type
::
on_second
,
ns
);
}
}
void
on_12_hour_time
()
{
void
on_12_hour_time
()
{
if
(
handle_nan_inf
())
return
;
if
(
handle_nan_inf
())
return
;
format_
localized
(
time
(),
'r'
);
format_
tm
(
time
(),
&
tm_writer_type
::
on_12_hour_time
);
}
}
void
on_24_hour_time
()
{
void
on_24_hour_time
()
{
...
@@ -1609,7 +1613,7 @@ struct chrono_formatter {
...
@@ -1609,7 +1613,7 @@ struct chrono_formatter {
void
on_am_pm
()
{
void
on_am_pm
()
{
if
(
handle_nan_inf
())
return
;
if
(
handle_nan_inf
())
return
;
format_
localized
(
time
(),
'p'
);
format_
tm
(
time
(),
&
tm_writer_type
::
on_am_pm
);
}
}
void
on_duration_value
()
{
void
on_duration_value
()
{
...
...
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