1
2
3
4
5
6
7
8
9
10 #ifndef CRM_COMMON_ISO8601
11 # define CRM_COMMON_ISO8601
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17
18
19
20
21
22
23
24
25
26
27 # include <time.h>
28 # include <ctype.h>
29 # include <stdint.h>
30 # include <stdbool.h>
31
32 typedef struct crm_time_s crm_time_t;
33
34 typedef struct crm_time_period_s {
35 crm_time_t *start;
36 crm_time_t *end;
37 crm_time_t *diff;
38 } crm_time_period_t;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 crm_time_t *crm_time_new(const char *string);
54 crm_time_t *crm_time_new_undefined(void);
55 void crm_time_free(crm_time_t * dt);
56
57 bool crm_time_is_defined(const crm_time_t *t);
58 char *crm_time_as_string(crm_time_t * dt, int flags);
59
60 #define crm_time_log(level, prefix, dt, flags) \
61 crm_time_log_alias(level, __FILE__, __func__, __LINE__, prefix, dt, flags)
62
63 void crm_time_log_alias(int log_level, const char *file, const char *function, int line,
64 const char *prefix, crm_time_t * date_time, int flags);
65
66 # define crm_time_log_date 0x001
67 # define crm_time_log_timeofday 0x002
68 # define crm_time_log_with_timezone 0x004
69 # define crm_time_log_duration 0x008
70
71 # define crm_time_ordinal 0x010
72 # define crm_time_weeks 0x020
73 # define crm_time_seconds 0x100
74 # define crm_time_epoch 0x200
75
76 crm_time_t *crm_time_parse_duration(const char *duration_str);
77 crm_time_t *crm_time_calculate_duration(crm_time_t * dt, crm_time_t * value);
78 crm_time_period_t *crm_time_parse_period(const char *period_str);
79 void crm_time_free_period(crm_time_period_t *period);
80
81 int crm_time_compare(crm_time_t * dt, crm_time_t * rhs);
82
83 int crm_time_get_timeofday(crm_time_t * dt, uint32_t * h, uint32_t * m, uint32_t * s);
84 int crm_time_get_timezone(crm_time_t * dt, uint32_t * h, uint32_t * m);
85 int crm_time_get_gregorian(crm_time_t * dt, uint32_t * y, uint32_t * m, uint32_t * d);
86 int crm_time_get_ordinal(crm_time_t * dt, uint32_t * y, uint32_t * d);
87 int crm_time_get_isoweek(crm_time_t * dt, uint32_t * y, uint32_t * w, uint32_t * d);
88
89
90 long long int crm_time_get_seconds(crm_time_t * dt);
91
92
93 long long int crm_time_get_seconds_since_epoch(crm_time_t * dt);
94
95 void crm_time_set(crm_time_t * target, crm_time_t * source);
96 void crm_time_set_timet(crm_time_t * target, time_t * source);
97
98
99 crm_time_t *pcmk_copy_time(crm_time_t *source);
100 crm_time_t *crm_time_add(crm_time_t * dt, crm_time_t * value);
101 crm_time_t *crm_time_subtract(crm_time_t * dt, crm_time_t * value);
102
103
104 void crm_time_add_seconds(crm_time_t * dt, int value);
105 void crm_time_add_minutes(crm_time_t * dt, int value);
106 void crm_time_add_hours(crm_time_t * dt, int value);
107 void crm_time_add_days(crm_time_t * dt, int value);
108 void crm_time_add_weeks(crm_time_t * dt, int value);
109 void crm_time_add_months(crm_time_t * dt, int value);
110 void crm_time_add_years(crm_time_t * dt, int value);
111
112
113 int crm_time_january1_weekday(int year);
114 int crm_time_weeks_in_year(int year);
115 int crm_time_days_in_month(int month, int year);
116
117 bool crm_time_leapyear(int year);
118 bool crm_time_check(crm_time_t * dt);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif