Skip to content

Commit

Permalink
handling fails when use minimum time_point
Browse files Browse the repository at this point in the history
  • Loading branch information
0xArdi-N committed Nov 11, 2023
1 parent 6b0082e commit 06b9571
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
if (subsecs.count() < 0) {
auto second =
std::chrono::duration_cast<Duration>(std::chrono::seconds(1));
if (epoch.count() < ((Duration::min)() + second).count())
if ((epoch + second).count() < ((Duration::min)() + second).count())
FMT_THROW(format_error("duration is too small"));
subsecs += second;
val -= second;
Expand Down
6 changes: 6 additions & 0 deletions test/chrono-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,3 +1003,9 @@ TEST(chrono_test, glibc_extensions) {
EXPECT_EQ(fmt::format("{:%-S}", d), "3.140000");
}
}
TEST(chrono_test, time_min) {
{
const auto t = std::chrono::system_clock::time_point::min();
EXPECT_EQ(fmt::format("{:%S}", t), "53.224192");
}
}

0 comments on commit 06b9571

Please sign in to comment.