diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index 78feafc962..19ffa76760 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -334,6 +334,7 @@ wxString wxDateTime::Format(const wxString& formatp, const TimeZone& tz) const time_t time = GetTicks(); bool canUseStrftime = time != (time_t)-1; + bool isPercent = false; // We also can't use strftime() if we use non standard specifier: either // our own extension "%l" or one of "%g", "%G", "%V", "%z" which are POSIX @@ -342,11 +343,15 @@ wxString wxDateTime::Format(const wxString& formatp, const TimeZone& tz) const canUseStrftime && p != format.end(); ++p ) { - if ( *p != '%' ) + if (!isPercent) + { + isPercent = *p == '%'; continue; + } + isPercent = false; // set the default format - switch ( (*++p).GetValue() ) + switch ( (*p).GetValue() ) { case 'l': #ifdef __WINDOWS__ diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index e0c146611f..15f17e856b 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -822,6 +822,8 @@ void DateTimeTestCase::TestTimeFormat() } } + CPPUNIT_ASSERT(wxDateTime::Now().Format("%") == "%"); + wxDateTime dt; #if 0