added timeDurationToStringMilliseconds() method

This commit is contained in:
fgerlits 2005-07-01 17:24:21 +00:00
parent fdc676fc05
commit fbdeea6df4
4 changed files with 61 additions and 7 deletions

View file

@ -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/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.6 $
* @version $Revision: 1.7 $
*/
class TimeConversion
{
@ -138,6 +138,15 @@ class TimeConversion
*/
static void
sleep(Ptr<time_duration>::Ref duration) throw ();
/**
* Convert a time_duration to a format used in SMILs.
*
* @param duration sleep for this duration.
*/
static Ptr<std::string>::Ref
timeDurationToStringMilliseconds(Ptr<time_duration>::Ref duration)
throw ();
};

View file

@ -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/TimeConversion.cxx,v $
------------------------------------------------------------------------------*/
@ -152,3 +152,23 @@ TimeConversion :: sleep(Ptr<time_duration>::Ref duration)
}
}
/*------------------------------------------------------------------------------
* Convert a time_duration to a format used in SMILs.
*----------------------------------------------------------------------------*/
Ptr<std::string>::Ref
TimeConversion :: timeDurationToStringMilliseconds(
Ptr<time_duration>::Ref duration)
throw ()
{
std::stringstream stringStream;
stringStream << duration->total_seconds();
int microseconds = duration->fractional_seconds();
stringStream << "."
<< std::setw(3) << std::setfill('0') << std::dec
<< microseconds / 1000
<< 's';
Ptr<std::string>::Ref result(new std::string(stringStream.str()));
return result;
}

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.5 $
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversionTest.cxx,v $
------------------------------------------------------------------------------*/
@ -213,3 +213,19 @@ TimeConversionTest :: sleepTest(void)
CPPUNIT_ASSERT((*end - *start) >= *duration);
}
/*------------------------------------------------------------------------------
* Test the timeDurationToStringMilliseconds() function
*----------------------------------------------------------------------------*/
void
TimeConversionTest :: durationToStringTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<time_duration>::Ref duration(new time_duration(1,2,3,4000));
Ptr<std::string>::Ref durationString
= TimeConversion::timeDurationToStringMilliseconds(
duration);
CPPUNIT_ASSERT_EQUAL(std::string("3723.004s"), *durationString);
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
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.4 $
* @version $Revision: 1.5 $
* @see TimeConversion
*/
class TimeConversionTest : public CPPUNIT_NS::TestFixture
@ -69,6 +69,7 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(ptimeToTmTest);
CPPUNIT_TEST(nowTest);
CPPUNIT_TEST(sleepTest);
CPPUNIT_TEST(durationToStringTest);
CPPUNIT_TEST_SUITE_END();
protected:
@ -113,6 +114,14 @@ class TimeConversionTest : public CPPUNIT_NS::TestFixture
void
sleepTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the timeDurationToStringMilliseconds() function.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
durationToStringTest(void) throw (CPPUNIT_NS::Exception);
public: