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
de5da509
Commit
de5da509
authored
May 11, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix formatting of extreme durations (#1154)
parent
ea2976e6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
21 deletions
+16
-21
include/fmt/chrono.h
include/fmt/chrono.h
+6
-11
include/fmt/format.h
include/fmt/format.h
+4
-8
include/fmt/time.h
include/fmt/time.h
+2
-2
test/chrono-test.cc
test/chrono-test.cc
+4
-0
No files found.
include/fmt/chrono.h
View file @
de5da509
...
...
@@ -414,9 +414,8 @@ template <
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
));
return
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
(
mod
(
d
.
count
()
*
Period
::
num
/
Period
::
den
*
1000
,
1000
));
}
template
<
typename
Rep
,
typename
OutputIt
>
...
...
@@ -431,12 +430,9 @@ OutputIt static format_chrono_duration_value(OutputIt out, Rep val,
template
<
typename
Period
,
typename
OutputIt
>
static
OutputIt
format_chrono_duration_unit
(
OutputIt
out
)
{
if
(
const
char
*
unit
=
get_units
<
Period
>
())
return
format_to
(
out
,
"{}"
,
unit
);
else
if
(
Period
::
den
==
1
)
return
format_to
(
out
,
"[{}]s"
,
Period
::
num
);
else
return
format_to
(
out
,
"[{}/{}]s"
,
Period
::
num
,
Period
::
den
);
if
(
const
char
*
unit
=
get_units
<
Period
>
())
return
format_to
(
out
,
"{}"
,
unit
);
if
(
Period
::
den
==
1
)
return
format_to
(
out
,
"[{}]s"
,
Period
::
num
);
return
format_to
(
out
,
"[{}/{}]s"
,
Period
::
num
,
Period
::
den
);
}
template
<
typename
FormatContext
,
typename
OutputIt
,
typename
Rep
,
...
...
@@ -449,7 +445,6 @@ struct chrono_formatter {
typedef
std
::
chrono
::
duration
<
Rep
>
seconds
;
seconds
s
;
typedef
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
milliseconds
;
milliseconds
ms
;
typedef
typename
FormatContext
::
char_type
char_type
;
...
...
@@ -461,7 +456,6 @@ struct chrono_formatter {
*
out
++
=
'-'
;
}
s
=
std
::
chrono
::
duration_cast
<
seconds
>
(
d
);
ms
=
get_milliseconds
(
d
);
}
Rep
hour
()
const
{
return
mod
((
s
.
count
()
/
3600
),
24
);
}
...
...
@@ -547,6 +541,7 @@ struct chrono_formatter {
void
on_second
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
{
write
(
second
(),
2
);
auto
ms
=
get_milliseconds
(
std
::
chrono
::
duration
<
Rep
,
Period
>
(
val
));
if
(
ms
!=
std
::
chrono
::
milliseconds
(
0
))
{
*
out
++
=
'.'
;
write
(
ms
.
count
(),
3
);
...
...
include/fmt/format.h
View file @
de5da509
...
...
@@ -251,7 +251,7 @@ namespace uintptr {
struct
uintptr_t
{
unsigned
char
value
[
sizeof
(
void
*
)];
};
}
}
// namespace uintptr
using
uintptr
::
uintptr_t
;
typedef
std
::
numeric_limits
<
uintptr_t
>
numutil
;
...
...
@@ -1113,10 +1113,7 @@ FMT_CONSTEXPR unsigned basic_parse_context<Char, ErrorHandler>::next_arg_id() {
namespace
internal
{
namespace
grisu_options
{
enum
{
fixed
=
1
,
grisu3
=
2
};
enum
{
fixed
=
1
,
grisu3
=
2
};
}
// Formats value using the Grisu algorithm:
...
...
@@ -1190,8 +1187,7 @@ It grisu_prettify(const char* digits, int size, int exp, It it,
if
(
!
params
.
trailing_zeros
)
{
// Remove trailing zeros.
while
(
size
>
full_exp
&&
digits
[
size
-
1
]
==
'0'
)
--
size
;
if
(
size
!=
full_exp
)
*
it
++
=
static_cast
<
Char
>
(
'.'
);
if
(
size
!=
full_exp
)
*
it
++
=
static_cast
<
Char
>
(
'.'
);
return
copy_str
<
Char
>
(
digits
+
full_exp
,
digits
+
size
,
it
);
}
*
it
++
=
static_cast
<
Char
>
(
'.'
);
...
...
@@ -2877,7 +2873,7 @@ void basic_writer<Range>::write_double(T value, const format_specs& spec) {
(
spec
.
type
!=
'a'
&&
spec
.
type
!=
'A'
&&
spec
.
type
!=
'e'
&&
spec
.
type
!=
'E'
)
&&
internal
::
grisu_format
(
static_cast
<
double
>
(
value
),
buffer
,
precision
,
options
,
exp
);
precision
,
options
,
exp
);
if
(
!
use_grisu
)
internal
::
sprintf_format
(
value
,
buffer
,
spec
);
if
(
handler
.
as_percentage
)
{
...
...
include/fmt/time.h
View file @
de5da509
...
...
@@ -11,9 +11,9 @@
#include "chrono.h"
#ifdef _MSC_VER
#pragma message("fmt/time.h is deprecated, use fmt/chrono.h instead")
#
pragma message("fmt/time.h is deprecated, use fmt/chrono.h instead")
#else
#warning fmt/time.h is deprecated, use fmt/chrono.h instead
#
warning fmt/time.h is deprecated, use fmt/chrono.h instead
#endif
#endif // FMT_TIME_H_
test/chrono-test.cc
View file @
de5da509
...
...
@@ -318,6 +318,10 @@ TEST(ChronoTest, SpecialDurations) {
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
));
EXPECT_EQ
(
fmt
::
format
(
"{}"
,
std
::
chrono
::
duration
<
float
,
std
::
exa
>
(
1
)),
"1Es"
);
EXPECT_EQ
(
fmt
::
format
(
"{}"
,
std
::
chrono
::
duration
<
float
,
std
::
atto
>
(
1
)),
"1as"
);
}
#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