diff options
| author | 2023-05-08 09:30:26 +0200 | |
|---|---|---|
| committer | 2023-05-08 09:30:26 +0200 | |
| commit | 7b349dd001f6642a216491d57e945fa3f0b69fe7 (patch) | |
| tree | 556efba588a5bd08653a15235f101a269883cf43 /xs_time.h | |
| parent | Moved sem_close() further to the end. (diff) | |
| download | penes-snac2-7b349dd001f6642a216491d57e945fa3f0b69fe7.tar.gz penes-snac2-7b349dd001f6642a216491d57e945fa3f0b69fe7.tar.xz penes-snac2-7b349dd001f6642a216491d57e945fa3f0b69fe7.zip | |
Backport from xs.
Diffstat (limited to '')
| -rw-r--r-- | xs_time.h | 13 |
1 files changed, 13 insertions, 0 deletions
| @@ -12,6 +12,7 @@ xs_str *xs_str_time(time_t t, const char *fmt, int local); | |||
| 12 | time_t xs_parse_time(const char *str, const char *fmt, int local); | 12 | time_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) |
| 15 | xs_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 | ||
| 41 | xs_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 | |||
| 40 | char *strptime(const char *s, const char *format, struct tm *tm); | 53 | char *strptime(const char *s, const char *format, struct tm *tm); |
| 41 | 54 | ||
| 42 | time_t xs_parse_time(const char *str, const char *fmt, int local) | 55 | time_t xs_parse_time(const char *str, const char *fmt, int local) |