Add time zone parsing support for only specifying HH

This commit is contained in:
Dimitri Schoolwerth
2017-06-20 18:41:39 +04:00
committed by Dimitri Schoolwerth
parent 101433190f
commit 1a5163a882
2 changed files with 17 additions and 3 deletions

View File

@@ -1521,18 +1521,25 @@ wxDateTime::ParseFormat(const wxString& date,
} }
// Optionally followed by a colon separator. // Optionally followed by a colon separator.
bool mustHaveMinutes = false;
if ( input != end && *input == wxS(':') ) if ( input != end && *input == wxS(':') )
{ {
mustHaveMinutes = true;
++input; ++input;
} }
// Followed by exactly 2 digits for minutes (MM). // Optionally followed by exactly 2 digits for minutes (MM).
unsigned long minutes; unsigned long minutes = 0;
if ( !GetNumericToken(numRequiredDigits, input, end, if ( !GetNumericToken(numRequiredDigits, input, end,
&minutes, &numScannedDigits) &minutes, &numScannedDigits)
|| numScannedDigits != numRequiredDigits) || numScannedDigits != numRequiredDigits)
{ {
return false; // No match. if (mustHaveMinutes || numScannedDigits)
{
// No match if we must have minutes, or digits
// for minutes were specified but not exactly 2.
return false;
}
} }
if ( hours > 12 || minutes > 59 ) if ( hours > 12 || minutes > 59 )

View File

@@ -906,6 +906,11 @@ void DateTimeTestCase::TestTimeZoneParse()
// Z as UTC designator. // Z as UTC designator.
{ "13:37Z", true }, { "13:37Z", true },
// Only containing HH offset.
{ "09:37-04", true },
{ "13:37+00", true },
{ "17:37+04", true },
// Colon as HH and MM separator. // Colon as HH and MM separator.
{ "17:37+04:00", true }, { "17:37+04:00", true },
@@ -918,6 +923,8 @@ void DateTimeTestCase::TestTimeZoneParse()
{ "00:00-1300" }, // Offset out of range. { "00:00-1300" }, // Offset out of range.
{ "00:00+1300" }, // Offset out of range. { "00:00+1300" }, // Offset out of range.
{ "00:00+00:" }, // Minutes missing after colon separator.
// Not exactly 2 digits for hours and minutes. // Not exactly 2 digits for hours and minutes.
{ "17:37+4" }, { "17:37+4" },
{ "17:37+400" }, { "17:37+400" },