fix wxTimeSpan::Format() for negative spans with 0 hour component (#10055)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c0ccc082e2
commit
c9e46deaa7
@ -4274,6 +4274,14 @@ enum TimeSpanPart
|
||||
// %l milliseconds (000 - 999)
|
||||
wxString wxTimeSpan::Format(const wxString& format) const
|
||||
{
|
||||
// we deal with only positive time spans here and just add the sign in
|
||||
// front for the negative ones
|
||||
if ( IsNegative() )
|
||||
{
|
||||
wxString str(Negate().Format(format));
|
||||
return "-" + str;
|
||||
}
|
||||
|
||||
wxCHECK_MSG( !format.empty(), wxEmptyString,
|
||||
_T("NULL format in wxTimeSpan::Format") );
|
||||
|
||||
@ -4345,13 +4353,6 @@ wxString wxTimeSpan::Format(const wxString& format) const
|
||||
n = GetHours();
|
||||
if ( partBiggest < Part_Hour )
|
||||
{
|
||||
if ( n < 0 )
|
||||
{
|
||||
// the sign has already been taken into account
|
||||
// when outputting the biggest part
|
||||
n = -n;
|
||||
}
|
||||
|
||||
n %= HOURS_PER_DAY;
|
||||
}
|
||||
else
|
||||
@ -4366,9 +4367,6 @@ wxString wxTimeSpan::Format(const wxString& format) const
|
||||
n = GetMilliseconds().ToLong();
|
||||
if ( partBiggest < Part_MSec )
|
||||
{
|
||||
if ( n < 0 )
|
||||
n = -n;
|
||||
|
||||
n %= 1000;
|
||||
}
|
||||
//else: no need to reset partBiggest to Part_MSec, it is
|
||||
@ -4381,9 +4379,6 @@ wxString wxTimeSpan::Format(const wxString& format) const
|
||||
n = GetMinutes();
|
||||
if ( partBiggest < Part_Min )
|
||||
{
|
||||
if ( n < 0 )
|
||||
n = -n;
|
||||
|
||||
n %= MIN_PER_HOUR;
|
||||
}
|
||||
else
|
||||
@ -4398,9 +4393,6 @@ wxString wxTimeSpan::Format(const wxString& format) const
|
||||
n = GetSeconds().ToLong();
|
||||
if ( partBiggest < Part_Sec )
|
||||
{
|
||||
if ( n < 0 )
|
||||
n = -n;
|
||||
|
||||
n %= SEC_PER_MIN;
|
||||
}
|
||||
else
|
||||
@ -4414,10 +4406,6 @@ wxString wxTimeSpan::Format(const wxString& format) const
|
||||
|
||||
if ( digits )
|
||||
{
|
||||
// negative numbers need one extra position for '-' display
|
||||
if ( n < 0 )
|
||||
digits++;
|
||||
|
||||
fmtPrefix << _T("0") << digits;
|
||||
}
|
||||
|
||||
|
@ -738,13 +738,15 @@ void DateTimeTestCase::TestTimeSpanFormat()
|
||||
{ 219, 0, 0, 0, "%H", "219" },
|
||||
{ 219, 0, 0, 0, "%D, %H", "9, 03" },
|
||||
{ 219, 0, 0, 0, "%E, %D, %H", "1, 2, 03" },
|
||||
{ 0, -1, 0, 0, "%H:%M:%S", "-00:01:00" },
|
||||
{ 0, 0, -1, 0, "%H:%M:%S", "-00:00:01" },
|
||||
};
|
||||
|
||||
for ( size_t n = 0; n < WXSIZEOF(testSpans); n++ )
|
||||
{
|
||||
const TimeSpanFormatTestData& td = testSpans[n];
|
||||
wxTimeSpan ts(td.h, td.min, td.sec, td.msec);
|
||||
CPPUNIT_ASSERT_EQUAL( wxString(td.result), ts.Format(td.fmt) );
|
||||
CPPUNIT_ASSERT_EQUAL( td.result, ts.Format(td.fmt) );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user