diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index 916486242a..30964b3106 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -1521,18 +1521,25 @@ wxDateTime::ParseFormat(const wxString& date, } // Optionally followed by a colon separator. + bool mustHaveMinutes = false; if ( input != end && *input == wxS(':') ) { + mustHaveMinutes = true; ++input; } - // Followed by exactly 2 digits for minutes (MM). - unsigned long minutes; + // Optionally followed by exactly 2 digits for minutes (MM). + unsigned long minutes = 0; if ( !GetNumericToken(numRequiredDigits, input, end, &minutes, &numScannedDigits) || 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 ) diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 37f1f18a2f..25907d1318 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -906,6 +906,11 @@ void DateTimeTestCase::TestTimeZoneParse() // Z as UTC designator. { "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. { "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+00:" }, // Minutes missing after colon separator. + // Not exactly 2 digits for hours and minutes. { "17:37+4" }, { "17:37+400" },