Fix bug for parsing negative offsets of less than 1h

This commit is contained in:
Howard Hinnant
2018-05-05 12:01:56 -04:00
parent a91ceefb4e
commit 5d15157bbb

View File

@@ -6997,14 +6997,22 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{ {
int tH, tM; int tH, tM;
minutes toff = not_a_offset; minutes toff = not_a_offset;
bool neg = false;
auto ic = is.peek();
if (!Traits::eq_int_type(ic, Traits::eof()))
{
auto c = static_cast<char>(Traits::to_char_type(ic));
if (c == '-')
neg = true;
}
if (modified == CharT{}) if (modified == CharT{})
{ {
read(is, rs{tH, 2, 2}); read(is, rs{tH, 2, 2});
if (!is.fail()) if (!is.fail())
toff = hours{tH}; toff = hours{std::abs(tH)};
if (is.good()) if (is.good())
{ {
auto ic = is.peek(); ic = is.peek();
if (!Traits::eq_int_type(ic, Traits::eof())) if (!Traits::eq_int_type(ic, Traits::eof()))
{ {
auto c = static_cast<char>(Traits::to_char_type(ic)); auto c = static_cast<char>(Traits::to_char_type(ic));
@@ -7012,7 +7020,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{ {
read(is, ru{tM, 2, 2}); read(is, ru{tM, 2, 2});
if (!is.fail()) if (!is.fail())
toff += minutes{ tH < 0 ? -tM : tM }; toff += minutes{tM};
} }
} }
} }
@@ -7021,10 +7029,10 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{ {
read(is, rs{tH, 1, 2}); read(is, rs{tH, 1, 2});
if (!is.fail()) if (!is.fail())
toff = hours{tH}; toff = hours{std::abs(tH)};
if (is.good()) if (is.good())
{ {
auto ic = is.peek(); ic = is.peek();
if (!Traits::eq_int_type(ic, Traits::eof())) if (!Traits::eq_int_type(ic, Traits::eof()))
{ {
auto c = static_cast<char>(Traits::to_char_type(ic)); auto c = static_cast<char>(Traits::to_char_type(ic));
@@ -7033,11 +7041,13 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
(void)is.get(); (void)is.get();
read(is, ru{tM, 2, 2}); read(is, ru{tM, 2, 2});
if (!is.fail()) if (!is.fail())
toff += minutes{ tH < 0 ? -tM : tM }; toff += minutes{tM};
} }
} }
} }
} }
if (neg)
toff = -toff;
checked_set(temp_offset, toff, not_a_offset, is); checked_set(temp_offset, toff, not_a_offset, is);
command = nullptr; command = nullptr;
width = -1; width = -1;