Skip to content

Commit

Permalink
seems to pass the unit test now (except for the nan stuff from victor)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldreik committed May 5, 2019
1 parent 786b4b7 commit bb375e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,18 @@ struct chrono_formatter {
*out++ = '-';
}

s = std::chrono::duration_cast<seconds>(d);
ms = std::chrono::duration_cast<milliseconds>(d - s);
if (is_floating_point) {

if constexpr (is_floating_point) {
auto tmpseconds = std::chrono::duration_cast<seconds>(d);
s=seconds{std::floor(tmpseconds.count())};
ms = std::chrono::duration_cast<milliseconds>(tmpseconds - s);
if (!std::isfinite(s.count()) || !std::isfinite(ms.count())) {
FMT_THROW(format_error("internal overflow of floating point duration"));
}
} else {
s = std::chrono::duration_cast<seconds>(d);
ms = std::chrono::duration_cast<milliseconds>(d - s);

}
}

Expand Down
2 changes: 1 addition & 1 deletion test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,6 @@ TEST(ChronoTest, OverflowingFloat) {

TEST(ChronoTest, OverflowingFloat2) {
const std::chrono::duration<float, std::atto> d{1.79400457e+31f};
EXPECT_THROW(fmt::format("{:%S}", d), fmt::format_error);
fmt::format("{:%S}", d);
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR

0 comments on commit bb375e1

Please sign in to comment.