2024-07-01 10:23:00 +00:00
|
|
|
#ifndef _DURATION_H
|
|
|
|
#define _DURATION_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2024-07-09 12:43:55 +00:00
|
|
|
static unsigned long long parse_uint(const char *str) {
|
2024-07-01 10:23:00 +00:00
|
|
|
char *p = NULL;
|
|
|
|
|
|
|
|
unsigned long long res = strtoull(str, &p, 0);
|
|
|
|
|
|
|
|
/* Parse suffix */
|
|
|
|
if (*p) {
|
|
|
|
switch (p[0]) {
|
|
|
|
case 'm':
|
|
|
|
res *= 60;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
res *= 3600;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
res *= 86400;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-07-09 12:43:55 +00:00
|
|
|
static unsigned long long mu_parse_duration(const char *arg) {
|
2024-07-01 10:23:00 +00:00
|
|
|
if (strchr(arg, '.')) {
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
/* Sec */
|
|
|
|
return parse_uint(arg) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|