diff --git a/campcaster/src/modules/core/include/LiveSupport/Core/TimeConversion.h b/campcaster/src/modules/core/include/LiveSupport/Core/TimeConversion.h index 7ba1161b7..dfd1793ab 100644 --- a/campcaster/src/modules/core/include/LiveSupport/Core/TimeConversion.h +++ b/campcaster/src/modules/core/include/LiveSupport/Core/TimeConversion.h @@ -191,7 +191,7 @@ class TimeConversion * @param duration sleep for this duration. */ static void - sleep(Ptr::Ref duration) throw (); + sleep(Ptr::Ref duration) throw (); /** * Convert a time_duration to a format used in SMILs. @@ -201,7 +201,7 @@ class TimeConversion * @param duration the time duration to convert. */ static Ptr::Ref - timeDurationToSmilString(Ptr::Ref duration) + timeDurationToSmilString(Ptr::Ref duration) throw (); /** @@ -216,7 +216,7 @@ class TimeConversion * @return the time duration in string format */ static Ptr::Ref - timeDurationToHhMmSsString(Ptr::Ref duration) + timeDurationToHhMmSsString(Ptr::Ref duration) throw (); /** @@ -232,7 +232,7 @@ class TimeConversion * @return the time duration in string format */ static Ptr::Ref - timeDurationToShortString(Ptr::Ref duration) + timeDurationToShortString(Ptr::Ref duration) throw (); /** @@ -257,10 +257,21 @@ class TimeConversion /** * Get the number of digits used for fractional seconds * in time durations. - * Returns the constant 6, for microsecond precision. + * @return the constant 6, for microsecond precision. */ static int getNumberOfDigitsPrecision(void) throw (); + + /** + * Round the time duration to the nearest second. + * + * @param duration the time to be rounded; it will not be + * modified. + * @return the rounded value. + */ + static Ptr::Ref + roundToNearestSecond(Ptr::Ref duration) + throw (); }; diff --git a/campcaster/src/modules/core/src/TimeConversion.cxx b/campcaster/src/modules/core/src/TimeConversion.cxx index 087124a32..8dea4881d 100644 --- a/campcaster/src/modules/core/src/TimeConversion.cxx +++ b/campcaster/src/modules/core/src/TimeConversion.cxx @@ -154,7 +154,7 @@ TimeConversion :: nowString(void) * Sleep for the specified duration. *----------------------------------------------------------------------------*/ void -TimeConversion :: sleep(Ptr::Ref duration) +TimeConversion :: sleep(Ptr::Ref duration) throw () { int ret; @@ -179,7 +179,7 @@ TimeConversion :: sleep(Ptr::Ref duration) *----------------------------------------------------------------------------*/ Ptr::Ref TimeConversion :: timeDurationToSmilString( - Ptr::Ref duration) + Ptr::Ref duration) throw () { std::stringstream stringStream; @@ -202,38 +202,24 @@ TimeConversion :: timeDurationToSmilString( *----------------------------------------------------------------------------*/ Ptr::Ref TimeConversion :: timeDurationToHhMmSsString( - Ptr::Ref duration) + Ptr::Ref duration) throw () { - int hours = duration->hours(); - int minutes = duration->minutes(); - int seconds = duration->seconds(); - - if (duration->fractional_seconds() >= 500000) { - ++seconds; - } - if (seconds == 60) { - seconds = 0; - ++minutes; - } - if (minutes == 60) { - minutes = 0; - ++hours; - } - + Ptr::Ref roundedDuration = roundToNearestSecond( + duration); std::stringstream stringStream; stringStream << std::dec << std::setw(2) << std::setfill('0') - << hours + << roundedDuration->hours() << ":" << std::setw(2) << std::setfill('0') - << minutes + << roundedDuration->minutes() << ":" << std::setw(2) << std::setfill('0') - << seconds; + << roundedDuration->seconds(); Ptr::Ref result(new std::string(stringStream.str())); return result; @@ -245,7 +231,7 @@ TimeConversion :: timeDurationToHhMmSsString( *----------------------------------------------------------------------------*/ Ptr::Ref TimeConversion :: timeDurationToShortString( - Ptr::Ref duration) + Ptr::Ref duration) throw () { std::stringstream stringStream; @@ -397,3 +383,32 @@ TimeConversion :: getNumberOfDigitsPrecision(void) throw () return numberOfDigitsPrecision; } + +/*------------------------------------------------------------------------------ + * Round the time duration to the nearest second. + *----------------------------------------------------------------------------*/ +Ptr::Ref +TimeConversion :: roundToNearestSecond(Ptr::Ref duration) + throw () +{ + int hours = duration->hours(); + int minutes = duration->minutes(); + int seconds = duration->seconds(); + + if (duration->fractional_seconds() >= 500000) { + ++seconds; + } + if (seconds == 60) { + seconds = 0; + ++minutes; + } + if (minutes == 60) { + minutes = 0; + ++hours; + } + + Ptr::Ref roundedDuration(new time_duration( + hours, minutes, seconds, 0)); + return roundedDuration; +} + diff --git a/campcaster/src/products/gLiveSupport/src/NowPlaying.cxx b/campcaster/src/products/gLiveSupport/src/NowPlaying.cxx index e4cffd3a4..b84492da6 100644 --- a/campcaster/src/products/gLiveSupport/src/NowPlaying.cxx +++ b/campcaster/src/products/gLiveSupport/src/NowPlaying.cxx @@ -184,7 +184,8 @@ NowPlaying :: setPlayable(Ptr::Ref playable) throw () } creatorLabel->set_markup(*infoString); - audioLength = playable->getPlaylength(); + audioLength = TimeConversion::roundToNearestSecond( + playable->getPlaylength()); resetRemainsTimeState(); } else {