lib: added function secs_to_hmsf() which converts (double) seconds

to a string 0h00m00s00

svn path=/trunk/boinc/; revision=25655
This commit is contained in:
Bernd Machenschalk 2012-05-07 15:41:34 +00:00
parent 4d1063728b
commit 91c3ddda93
3 changed files with 19 additions and 0 deletions

View File

@ -3723,3 +3723,10 @@ David 7 May 2012
html/user/
view_profile.php
Bernd 7 May 2012
- lib: added function secs_to_hmsf() which converts (double) seconds
to a string 0h00m00s00
lib/
str_util.cpp, .h

View File

@ -211,6 +211,17 @@ int ndays_to_string (double x, int smallest_timescale, char *buf) {
return 0;
}
// convert seconds into a string "0h00m00s00"
void secs_to_hmsf(double secs, char*buf) {
uint s = secs;
uint f = (secs - s) * 100.0;
uint h = s / 3600;
s -= h * 3600;
uint m = s / 60;
s -= m * 60;
sprintf(buf, "%uh%02um%02us%02u", h, m, s, f);
}
// Convert nbytes into a string. If total_bytes is non-zero,
// convert the two into a fractional display (i.e. 4/16 KB)
//

View File

@ -36,6 +36,7 @@ extern void strip_whitespace(std::string&);
#define safe_strcat(x, y) if (strlen(x)+strlen(y)<sizeof(x)) strcat(x, y)
extern char* time_to_string(double);
extern char* precision_time_to_string(double);
extern void secs_to_hmsf(double, char*);
extern std::string timediff_format(double);
inline bool ends_with(std::string const& s, std::string const& suffix) {