From a91ceefb4e594648540cc0a3c00611cd962989f9 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Mon, 23 Apr 2018 20:31:28 -0400 Subject: [PATCH] Allow %H %M and %S to deal with negative durations --- include/date/date.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/date/date.h b/include/date/date.h index 28541bd..dd2825c 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -4619,6 +4619,7 @@ to_stream(std::basic_ostream& os, const CharT* fmt, os.flags(std::ios::skipws | std::ios::dec); os.width(0); tm tm{}; + bool insert_negative = fds.has_tod && fds.tod.to_duration() < Duration::zero(); #if !ONLY_C_LOCALE auto& facet = use_facet>(os.getloc()); #endif @@ -4933,6 +4934,11 @@ to_stream(std::basic_ostream& os, const CharT* fmt, { if (!fds.has_tod) os.setstate(std::ios::failbit); + if (insert_negative) + { + os << '-'; + insert_negative = false; + } auto hms = fds.tod; #if !ONLY_C_LOCALE if (modified == CharT{}) @@ -5027,6 +5033,11 @@ to_stream(std::basic_ostream& os, const CharT* fmt, { if (!fds.has_tod) os.setstate(std::ios::failbit); + if (insert_negative) + { + os << '-'; + insert_negative = false; + } #if !ONLY_C_LOCALE if (modified == CharT{}) #endif @@ -5167,6 +5178,11 @@ to_stream(std::basic_ostream& os, const CharT* fmt, { if (!fds.has_tod) os.setstate(std::ios::failbit); + if (insert_negative) + { + os << '-'; + insert_negative = false; + } #if !ONLY_C_LOCALE if (modified == CharT{}) #endif