-
Notifications
You must be signed in to change notification settings - Fork 3
/
timespec.h
73 lines (60 loc) · 1.88 KB
/
timespec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _TIMESPEC_H_
#define _TIMESPEC_H_
#include <stdint.h>
#include <time.h>
//#include "time64.h"
typedef struct timespec64 timespec64;
typedef struct duration duration;
duration * duration_new();
void duration_init(duration *d);
duration * duration_from_string(char *in);
int duration_parse(char *in, duration *d);
timespec64 timespec64_add_duration(timespec64 a, duration *d);
timespec64 timespec64_now();
timespec64 timespec64_undef();
int timespec64_cmp(timespec64 *a, timespec64 *b);
int timespec64_parse(const char *buf, timespec64 *t);
void timespec64_print(timespec64 *t);
size_t strftime64t(char *dst, size_t n, const char *fmt, timespec64 *t);
char * strptime64t(const char *buf, const char *fmt, timespec64 *t);
timespec64 timespec64_from_yjhmsf(int64_t year, int jday,
int hour, int min, int sec, int64_t ns);
timespec64 timespec64_from_ymdhmsf(int64_t year, int month, int day,
int hour, int min, int sec, int64_t ns);
void timespec64_to_ymd(timespec64 *t, int64_t *year, int *month, int *day, int *oday);
/**
* @brief High-precision, long duration time value
* @ingroup time
*/
struct timespec64 {
int64_t tv_sec; /**< Number of seconds, epoch 1970/1/1 00:00:00 */
int64_t tv_nsec; /**< Number of nanoseconds */
};
typedef enum TimeType TimeType;
/**
* @brief duration units
* @ingroup time
*
*/
enum TimeType {
Duration_None = 0,
Duration_Seconds = 1,
Duration_Minutes = 2,
Duration_Hours = 3,
Duration_Days = 4,
Duration_Weeks = 5,
Duration_Months = 6,
Duration_Years = 7,
Duration_Decades = 8,
Duration_Centuries = 9,
};
/**
* @brief time duration with units
* @ingroup time
*
*/
struct duration {
TimeType type; /**< duration unit */
int64_t n; /**< duration length */
};
#endif /* _TIMESPEC_H_ */