Commit ed86abfe authored by rswindell's avatar rswindell
Browse files

Created parse_duration(), similar to parse_bytes() but for durations

(or possibly intervals) in seconds or fractions of a second. Supports
multipliers: (Y)ear, (W)eek, (D)ay, (H)our, and (M)inute.
parent 1765f7da
......@@ -231,6 +231,28 @@ int64_t DLLCALL parse_byte_count(const char* str, ulong unit)
return((int64_t)(unit>1 ? (bytes/unit):bytes));
/* Parse a duration string, default unit is in seconds */
/* (Y)ears, (W)eeks, (D)ays, (H)ours, and (M)inutes */
/* suffixes/multipliers are supported.
/* Return value is in seconds */
double DLLCALL parse_duration(const char* str)
char* p=NULL;
double t;
if(p!=NULL) {
switch(toupper(*p)) {
case 'Y': t*=365.0*24.0*60.0*60.0; break;
case 'W': t*= 7.0*24.0*60.0*60.0; break;
case 'D': t*= 24.0*60.0*60.0; break;
case 'H': t*= 60.0*60.0; break;
case 'M': t*= 60.0; break;
return t;
/* Convert ASCIIZ string to upper case */
......@@ -369,6 +369,7 @@ DLLEXPORT char DLLCALL c_unescape_char(char ch);
/* Power-of-2 byte count string parser (e.g. "100K" returns 102400 if unit is 1) */
DLLEXPORT int64_t DLLCALL parse_byte_count(const char*, ulong unit);
DLLEXPORT double DLLCALL parse_duration(const char*);
/* Microsoft (e.g. DOS/Win32) real-time system clock API (ticks since process started) */
typedef clock_t msclock_t;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment