fix wxTimeSpan::Format() for negative spans with 0 hour component (#10055)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@57474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -95,6 +95,7 @@ All:
|
|||||||
|
|
||||||
- wxHashMap::insert() doesn't update the value if it didn't insert the element
|
- wxHashMap::insert() doesn't update the value if it didn't insert the element
|
||||||
any more (Marcin Malich).
|
any more (Marcin Malich).
|
||||||
|
- Correct bug in wxTimeSpan::Format() for negative spans.
|
||||||
- Added Vietnamese translation (Tran Ngoc Quan).
|
- Added Vietnamese translation (Tran Ngoc Quan).
|
||||||
- Updated Slovenian translation (Martin Srebotnjak).
|
- Updated Slovenian translation (Martin Srebotnjak).
|
||||||
|
|
||||||
|
@@ -4271,7 +4271,16 @@ enum TimeSpanPart
|
|||||||
// %l milliseconds (000 - 999)
|
// %l milliseconds (000 - 999)
|
||||||
wxString wxTimeSpan::Format(const wxChar *format) const
|
wxString wxTimeSpan::Format(const wxChar *format) const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( format, wxEmptyString, _T("NULL format in wxTimeSpan::Format") );
|
// 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, wxEmptyString,
|
||||||
|
_T("NULL format in wxTimeSpan::Format") );
|
||||||
|
|
||||||
wxString str;
|
wxString str;
|
||||||
str.Alloc(wxStrlen(format));
|
str.Alloc(wxStrlen(format));
|
||||||
@@ -4341,13 +4350,6 @@ wxString wxTimeSpan::Format(const wxChar *format) const
|
|||||||
n = GetHours();
|
n = GetHours();
|
||||||
if ( partBiggest < Part_Hour )
|
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;
|
n %= HOURS_PER_DAY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -4362,9 +4364,6 @@ wxString wxTimeSpan::Format(const wxChar *format) const
|
|||||||
n = GetMilliseconds().ToLong();
|
n = GetMilliseconds().ToLong();
|
||||||
if ( partBiggest < Part_MSec )
|
if ( partBiggest < Part_MSec )
|
||||||
{
|
{
|
||||||
if ( n < 0 )
|
|
||||||
n = -n;
|
|
||||||
|
|
||||||
n %= 1000;
|
n %= 1000;
|
||||||
}
|
}
|
||||||
//else: no need to reset partBiggest to Part_MSec, it is
|
//else: no need to reset partBiggest to Part_MSec, it is
|
||||||
@@ -4377,9 +4376,6 @@ wxString wxTimeSpan::Format(const wxChar *format) const
|
|||||||
n = GetMinutes();
|
n = GetMinutes();
|
||||||
if ( partBiggest < Part_Min )
|
if ( partBiggest < Part_Min )
|
||||||
{
|
{
|
||||||
if ( n < 0 )
|
|
||||||
n = -n;
|
|
||||||
|
|
||||||
n %= MIN_PER_HOUR;
|
n %= MIN_PER_HOUR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -4394,9 +4390,6 @@ wxString wxTimeSpan::Format(const wxChar *format) const
|
|||||||
n = GetSeconds().ToLong();
|
n = GetSeconds().ToLong();
|
||||||
if ( partBiggest < Part_Sec )
|
if ( partBiggest < Part_Sec )
|
||||||
{
|
{
|
||||||
if ( n < 0 )
|
|
||||||
n = -n;
|
|
||||||
|
|
||||||
n %= SEC_PER_MIN;
|
n %= SEC_PER_MIN;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -4410,10 +4403,6 @@ wxString wxTimeSpan::Format(const wxChar *format) const
|
|||||||
|
|
||||||
if ( digits )
|
if ( digits )
|
||||||
{
|
{
|
||||||
// negative numbers need one extra position for '-' display
|
|
||||||
if ( n < 0 )
|
|
||||||
digits++;
|
|
||||||
|
|
||||||
fmtPrefix << _T("0") << digits;
|
fmtPrefix << _T("0") << digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -706,6 +706,8 @@ void DateTimeTestCase::TestTimeSpanFormat()
|
|||||||
{ 219, 0, 0, 0, _T("%H"), _T("219") },
|
{ 219, 0, 0, 0, _T("%H"), _T("219") },
|
||||||
{ 219, 0, 0, 0, _T("%D, %H"), _T("9, 03") },
|
{ 219, 0, 0, 0, _T("%D, %H"), _T("9, 03") },
|
||||||
{ 219, 0, 0, 0, _T("%E, %D, %H"), _T("1, 2, 03") },
|
{ 219, 0, 0, 0, _T("%E, %D, %H"), _T("1, 2, 03") },
|
||||||
|
{ 0, -1, 0, 0, _T("%H:%M:%S"), _T("-00:01:00") },
|
||||||
|
{ 0, 0, -1, 0, _T("%H:%M:%S"), _T("-00:00:01") },
|
||||||
};
|
};
|
||||||
|
|
||||||
for ( size_t n = 0; n < WXSIZEOF(testSpans); n++ )
|
for ( size_t n = 0; n < WXSIZEOF(testSpans); n++ )
|
||||||
|
Reference in New Issue
Block a user