summaryrefslogtreecommitdiff
path: root/xs_time.h
diff options
context:
space:
mode:
authorGravatar default2023-05-08 09:30:26 +0200
committerGravatar default2023-05-08 09:30:26 +0200
commit7b349dd001f6642a216491d57e945fa3f0b69fe7 (patch)
tree556efba588a5bd08653a15235f101a269883cf43 /xs_time.h
parentMoved sem_close() further to the end. (diff)
downloadpenes-snac2-7b349dd001f6642a216491d57e945fa3f0b69fe7.tar.gz
penes-snac2-7b349dd001f6642a216491d57e945fa3f0b69fe7.tar.xz
penes-snac2-7b349dd001f6642a216491d57e945fa3f0b69fe7.zip
Backport from xs.
Diffstat (limited to '')
-rw-r--r--xs_time.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/xs_time.h b/xs_time.h
index 94e472d..793b243 100644
--- a/xs_time.h
+++ b/xs_time.h
@@ -12,6 +12,7 @@ xs_str *xs_str_time(time_t t, const char *fmt, int local);
12time_t xs_parse_time(const char *str, const char *fmt, int local); 12time_t xs_parse_time(const char *str, const char *fmt, int local);
13#define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1) 13#define xs_parse_localtime(str, fmt) xs_parse_time(str, fmt, 1)
14#define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0) 14#define xs_parse_utctime(str, fmt) xs_parse_time(str, fmt, 0)
15xs_str *xs_str_time_diff(time_t time_diff);
15 16
16#ifdef XS_IMPLEMENTATION 17#ifdef XS_IMPLEMENTATION
17 18
@@ -37,6 +38,18 @@ xs_str *xs_str_time(time_t t, const char *fmt, int local)
37} 38}
38 39
39 40
41xs_str *xs_str_time_diff(time_t time_diff)
42/* returns time_diff in seconds to 'human' units (d:hh:mm:ss) */
43{
44 int secs = time_diff % 60;
45 int mins = (time_diff /= 60) % 60;
46 int hours = (time_diff /= 60) % 24;
47 int days = (time_diff /= 24);
48
49 return xs_fmt("%d:%02d:%02d:%02d", days, hours, mins, secs);
50}
51
52
40char *strptime(const char *s, const char *format, struct tm *tm); 53char *strptime(const char *s, const char *format, struct tm *tm);
41 54
42time_t xs_parse_time(const char *str, const char *fmt, int local) 55time_t xs_parse_time(const char *str, const char *fmt, int local)