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
e9bab6d0
Commit
e9bab6d0
authored
May 08, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve handling of large durations
parent
f52c09f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
include/fmt/chrono.h
include/fmt/chrono.h
+19
-1
test/chrono-test.cc
test/chrono-test.cc
+5
-1
No files found.
include/fmt/chrono.h
View file @
e9bab6d0
...
...
@@ -401,6 +401,24 @@ inline T mod(T x, int y) {
return
std
::
fmod
(
x
,
y
);
}
template
<
typename
Rep
,
typename
Period
,
typename
std
::
enable_if
<
std
::
is_integral
<
Rep
>
::
value
,
int
>::
type
=
0
>
inline
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
get_milliseconds
(
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
{
auto
s
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
d
);
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
d
-
s
);
}
template
<
typename
Rep
,
typename
Period
,
typename
std
::
enable_if
<
std
::
is_floating_point
<
Rep
>
::
value
,
int
>::
type
=
0
>
inline
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
get_milliseconds
(
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
{
auto
ms
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>>
(
d
);
return
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
(
mod
(
ms
.
count
(),
1000
));
}
template
<
typename
Rep
,
typename
OutputIt
>
OutputIt
static
format_chrono_duration_value
(
OutputIt
out
,
Rep
val
,
int
precision
)
{
...
...
@@ -443,7 +461,7 @@ struct chrono_formatter {
*
out
++
=
'-'
;
}
s
=
std
::
chrono
::
duration_cast
<
seconds
>
(
d
);
ms
=
std
::
chrono
::
duration_cast
<
milliseconds
>
(
d
-
s
);
ms
=
get_milliseconds
(
d
);
}
Rep
hour
()
const
{
return
mod
((
s
.
count
()
/
3600
),
24
);
}
...
...
test/chrono-test.cc
View file @
e9bab6d0
...
...
@@ -307,13 +307,17 @@ TEST(ChronoTest, InvalidColons) {
}
TEST
(
ChronoTest
,
SpecialDurations
)
{
EXPECT_EQ
(
"40"
,
fmt
::
format
(
"{:%S}"
,
std
::
chrono
::
duration
<
double
>
(
1e20
)));
EXPECT_EQ
(
"40."
,
fmt
::
format
(
"{:%S}"
,
std
::
chrono
::
duration
<
double
>
(
1e20
)).
substr
(
0
,
3
));
EXPECT_EQ
(
"-00:01"
,
fmt
::
format
(
"{:%M:%S}"
,
std
::
chrono
::
duration
<
double
>
(
-
1
)));
auto
nan
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
EXPECT_EQ
(
"nan nan nan nan.nan nan:nan nan"
,
fmt
::
format
(
"{:%I %H %M %S %R %r}"
,
std
::
chrono
::
duration
<
double
>
(
nan
)));
fmt
::
format
(
"{:%S}"
,
std
::
chrono
::
duration
<
float
,
std
::
atto
>
(
1.79400457e+31
f
));
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR
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