Ignore:
Timestamp:
01/12/11 19:43:22 (10 years ago)
Author:
alno
Message:

WebIf: remove redundant code by implementing a function sec2timeformat()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam-http-helpers.c

    r4413 r4427  
    612612    return j;
    613613}
     614
     615/* Format a seconds integer to hh:mm:ss or dd hh:mm:ss depending hrs >24 */
     616char *sec2timeformat(int seconds) {
     617    char *value = (char *) malloc((12 * sizeof(char)));
     618    value[0] = '\0';
     619    int secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;
     620
     621    if(seconds > 0) {
     622        secs = seconds % 60;
     623        if (seconds > 60) {
     624            fullmins = seconds / 60;
     625            mins = fullmins % 60;
     626            if(fullmins > 60) {
     627                fullhours = fullmins / 60;
     628                hours = fullhours % 24;
     629                days = fullhours / 24;
     630            }
     631        }
     632    }
     633    if(!days)   sprintf(value, "%02d:%02d:%02d", hours, mins, secs);
     634    else            sprintf(value, "%02dd %02d:%02d:%02d", days, hours, mins, secs);
     635
     636    return value;
     637}
     638
    614639#endif
Note: See TracChangeset for help on using the changeset viewer.