From 7a33f5e78316f6740879767207cbb6a982b48ffc Mon Sep 17 00:00:00 2001 From: Filip Brcic Date: Tue, 18 May 2021 21:59:52 +0200 Subject: [PATCH] Handle subsecond time before epoch start correctly --- include/fmt/chrono.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index a8a619f7..85d152f0 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -414,10 +414,12 @@ struct formatter(epoch); - // auto subseconds = abs(std::chrono::duration_cast>(epoch - seconds)); auto subseconds = std::chrono::duration_cast>(epoch - seconds); - if (subseconds < subseconds.zero()) subseconds = -subseconds; + if (subseconds < subseconds.zero()) { + time = localtime(val - std::chrono::seconds{1}); + subseconds = std::chrono::seconds{1} + subseconds; + } if (subseconds.count() > 0) { auto width = std::to_string(Period::den).size() - 1;