From 0bde4ba8c8eea1ade240f0249972594e486af3fe Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 3 Mar 2018 11:54:48 -0500 Subject: [PATCH] Make the parsing of minutes optional under the flag %z --- include/date/date.h | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/include/date/date.h b/include/date/date.h index c53bf34..28328df 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -6771,11 +6771,46 @@ from_stream(std::basic_istream& is, const CharT* fmt, { int H, M; if (modified == CharT{}) - read(is, rs{H, 2, 2}, ru{M, 2, 2}); + { + read(is, rs{H, 2, 2}); + if (!is.fail()) + temp_offset = hours{H}; + if (is.good()) + { + auto ic = is.peek(); + if (!Traits::eq_int_type(ic, Traits::eof())) + { + auto c = static_cast(Traits::to_char_type(ic)); + if ('0' <= c && c <= '9') + { + read(is, ru{M, 2, 2}); + if (!is.fail()) + temp_offset += minutes{ H < 0 ? -M : M }; + } + } + } + } else - read(is, rs{H, 1, 2}, CharT{':'}, ru{M, 2, 2}); - if (!is.fail()) - temp_offset = hours{ H } + minutes{ H < 0 ? -M : M }; + { + read(is, rs{H, 1, 2}); + if (!is.fail()) + temp_offset = hours{H}; + if (is.good()) + { + auto ic = is.peek(); + if (!Traits::eq_int_type(ic, Traits::eof())) + { + auto c = static_cast(Traits::to_char_type(ic)); + if (c == ':') + { + (void)is.get(); + read(is, ru{M, 2, 2}); + if (!is.fail()) + temp_offset += minutes{ H < 0 ? -M : M }; + } + } + } + } command = nullptr; width = -1; modified = CharT{};