48 const std::size_t secondsPerMinute = 60;
49 const std::size_t secondsPerHour = 60 * secondsPerMinute;
50 const std::size_t secondsPerDay = 24 * secondsPerHour;
53 std::size_t iSeconds =
static_cast< std::size_t
>( totalSeconds );
54 const std::size_t days = iSeconds / secondsPerDay;
56 iSeconds %= secondsPerDay;
57 const std::size_t hours = iSeconds / secondsPerHour;
59 iSeconds %= secondsPerHour;
60 const std::size_t minutes = iSeconds / secondsPerMinute;
64 const double dSeconds = std::fmod( totalSeconds, 60.0 );
68 std::ostringstream make_string(
"" );
69 if( days != 0 ) { make_string << days <<
"d"; nonzero =
true; }
70 if( hours != 0 || nonzero ) { make_string << hours <<
"h"; nonzero =
true; }
71 if( minutes != 0 || nonzero ) { make_string << minutes <<
"m"; nonzero =
true; }
72 make_string << std::showpoint << std::fixed << std::setprecision( precision );
73 make_string << dSeconds <<
"s";
76 return make_string.str();
87 const std::time_t rawtime{ std::time(
nullptr ) };
91 const std::tm*
const localTimePtr{ std::localtime( &rawtime ) };
93 if (localTimePtr ==
nullptr)
95 assert(!
"std::localtime should not return null!");
101 const std::tm localTimeValue( *localTimePtr );
103 constexpr std::size_t maxNumberOfChars{ 32 };
104 char timeAsString[maxNumberOfChars]{};
105 static_assert(maxNumberOfChars >
sizeof(
"Thu Aug 23 14:55:02 2001"),
106 "timeAsString should be large enough to hold a typical example date and time");
108 if (std::strftime(timeAsString, maxNumberOfChars,
"%c", &localTimeValue) == 0)
110 assert(!
"std::strftime has failed!");
std::string ConvertSecondsToDHMS(const double totalSeconds, const unsigned int precision=0)
std::string GetCurrentDateAndTime(void)