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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#pragma once
#include "allocator.h"
#include <stdint.h>
#define HMD_SEC_SPN (1)
#define HMD_MIN_SPN (60)
#define HMD_HOUR_SPN (HMD_MIN_SPN * 60)
#define HMD_DAY_SPN (HMD_HOUR_SPN * 24)
#define HMD_WEEK_SPN (HMD_DAY_SPN * 7)
enum hmd_err {
HMD_OK = 0,
HMD_ERR_OOB,
HMD_ERR_FMT,
HMD_ERR_SYS,
HMD_ERR_ARG,
HMD_ERR_INT
};
enum hmd_mon {
HMD_JAN,
HMD_FEB,
HMD_MAR,
HMD_APR,
HMD_MAY,
HMD_JUN,
HMD_JUL,
HMD_AUG,
HMD_SEP,
HMD_OCT,
HMD_NOV,
HMD_DEC
};
enum hmd_wday {
HMD_SUN,
HMD_MON,
HMD_TUE,
HMD_WED,
HMD_THU,
HMD_FRI,
HMD_SAT,
};
struct hmd_spn {
uint32_t years;
uint32_t weeks;
uint32_t days;
uint32_t hours;
uint32_t mins;
uint32_t secs;
};
struct hmd_date {
uint64_t ts; /* unix epoch */
uint64_t spn;
};
struct hmd_dd {
uint16_t year;
uint8_t month;
uint8_t day;
};
struct hmd_tod {
uint8_t hour;
uint8_t min;
uint8_t sec;
uint16_t spn;
};
enum hmd_err hmd_spn_parse(struct hmd_spn *spn, const char *arg);
enum hmd_err hmd_spn_ival_parse(struct hmd_spn *spn, const char *arg);
enum hmd_err hmd_spn_calc(struct hmd_spn *spn, uint64_t start, uint64_t end);
uint64_t hmd_spn_secs(struct hmd_spn *spn);
char *hmd_spn_str(struct hmd_spn *spn,
const struct allocator *allocator, int *rc);
char *hmd_spn_ival_str(struct hmd_spn *spn,
const struct allocator *allocator, int *rc);
enum hmd_err hmd_date_parse_daydate_reltime_weekday(
struct hmd_date *date, char *arg);
enum hmd_err hmd_date_parse_daydate_reltime_coarse(
struct hmd_date *date, char *arg);
enum hmd_err hmd_date_parse_daydate_iso8601(struct hmd_date *date, char *arg);
enum hmd_err hmd_timeofday_parse(struct hmd_tod *tod, char *arg);
enum hmd_err hmd_date_parse(struct hmd_date *date, char *arg);
char *hmd_date_str_reltime_exact(struct hmd_date *date,
const struct allocator *allocator, int *rc);
char *hmd_date_str_reltime_coarse(struct hmd_date *date,
const struct allocator *allocator, int *rc);
char *hmd_date_str_iso8601(struct hmd_date *date,
const struct allocator *allocator, int *rc);
char *hmd_date_str(struct hmd_date *date,
const struct allocator *allocator, int *rc);
extern const char *hmd_wdnames[7];
extern const char *hmd_mnames[12];
extern const int hmd_mdays[12];
|