added timeDurationToHhMmSsString() function
This commit is contained in:
parent
5b751a1809
commit
4d1574ca0b
4 changed files with 75 additions and 16 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.8 $
|
||||
Version : $Revision: 1.9 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -71,7 +71,7 @@ using namespace LiveSupport;
|
|||
* A helper object holding static time conversion functions.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.8 $
|
||||
* @version $Revision: 1.9 $
|
||||
*/
|
||||
class TimeConversion
|
||||
{
|
||||
|
@ -141,11 +141,25 @@ class TimeConversion
|
|||
|
||||
/**
|
||||
* Convert a time_duration to a format used in SMILs.
|
||||
* This means number of seconds, rounded to the nearest millisecond.
|
||||
* For example: "1234.567s", "0.890s", or "3.000s".
|
||||
*
|
||||
* @param duration sleep for this duration.
|
||||
* @param duration the time duration to convert.
|
||||
*/
|
||||
static Ptr<std::string>::Ref
|
||||
timeDurationToSmilString(Ptr<time_duration>::Ref duration)
|
||||
timeDurationToSmilString(Ptr<time_duration>::Ref duration)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
* Convert a time_duration to a rounded format used on the screen.
|
||||
* This means a hh:mm:ss format, rounded to the nearest second.
|
||||
* For example: "01:02:03" or "00:10:00". The hours field can be
|
||||
* more than two characters wide, e.g.: "8765:48:45".
|
||||
*
|
||||
* @param duration the time duration to convert.
|
||||
*/
|
||||
static Ptr<std::string>::Ref
|
||||
timeDurationToHhMmSsString(Ptr<time_duration>::Ref duration)
|
||||
throw ();
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.8 $
|
||||
Version : $Revision: 1.9 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -162,13 +162,48 @@ TimeConversion :: timeDurationToSmilString(
|
|||
throw ()
|
||||
{
|
||||
std::stringstream stringStream;
|
||||
stringStream << duration->total_seconds();
|
||||
int microseconds = duration->fractional_seconds();
|
||||
stringStream << std::dec
|
||||
<< duration->total_seconds();
|
||||
|
||||
int microseconds = duration->fractional_seconds();
|
||||
stringStream << "."
|
||||
<< std::setw(3) << std::setfill('0') << std::dec
|
||||
<< std::setw(3)
|
||||
<< std::setfill('0')
|
||||
<< (microseconds + 500) / 1000
|
||||
<< 's';
|
||||
Ptr<std::string>::Ref result(new std::string(stringStream.str()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Convert a time_duration to a rounded format used on the screen.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<std::string>::Ref
|
||||
TimeConversion :: timeDurationToHhMmSsString(
|
||||
Ptr<time_duration>::Ref duration)
|
||||
throw ()
|
||||
{
|
||||
std::stringstream stringStream;
|
||||
stringStream << std::dec
|
||||
<< std::setw(2)
|
||||
<< std::setfill('0')
|
||||
<< duration->hours()
|
||||
<< ":"
|
||||
<< std::setw(2)
|
||||
<< std::setfill('0')
|
||||
<< duration->minutes();
|
||||
|
||||
int seconds = duration->seconds();
|
||||
if (duration->fractional_seconds() >= 500000) {
|
||||
++seconds;
|
||||
}
|
||||
stringStream << ":"
|
||||
<< std::setw(2)
|
||||
<< std::setfill('0')
|
||||
<< seconds;
|
||||
|
||||
Ptr<std::string>::Ref result(new std::string(stringStream.str()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.7 $
|
||||
Version : $Revision: 1.8 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -215,18 +215,27 @@ TimeConversionTest :: sleepTest(void)
|
|||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test the timeDurationToSmilString() function
|
||||
* Test the timeDurationToSmilString() and timeDurationToHhMmSs() functions
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
TimeConversionTest :: durationToStringTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<time_duration>::Ref duration(new time_duration(duration_from_string(
|
||||
"01:02:03.003700" )));
|
||||
"01:02:03.503700" )));
|
||||
|
||||
Ptr<std::string>::Ref durationString
|
||||
Ptr<std::string>::Ref smilString
|
||||
= TimeConversion::timeDurationToSmilString(
|
||||
duration);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("3723.004s"), *durationString);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("3723.504s"), *smilString);
|
||||
|
||||
Ptr<std::string>::Ref hhMmSsString
|
||||
= TimeConversion::timeDurationToHhMmSsString(
|
||||
duration);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("01:02:04"), *hhMmSsString);
|
||||
|
||||
duration.reset(new time_duration(duration_from_string("111:22:33")));
|
||||
hhMmSsString = TimeConversion::timeDurationToHhMmSsString(duration);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("111:22:33"), *hhMmSsString);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.6 $
|
||||
Version : $Revision: 1.7 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -58,7 +58,7 @@ namespace Core {
|
|||
* Unit test for the TimeConversion class.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.6 $
|
||||
* @version $Revision: 1.7 $
|
||||
* @see TimeConversion
|
||||
*/
|
||||
class TimeConversionTest : public CPPUNIT_NS::TestFixture
|
||||
|
@ -115,7 +115,8 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
|
|||
sleepTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test the timeDurationToSmilString() function.
|
||||
* Test the timeDurationToSmilString() and timeDurationToHhMmSs()
|
||||
* functions.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue