pacemaker  2.0.1-15814c6c0d
Scalable High-Availability cluster resource manager
iso8601.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef CRM_COMMON_ISO8601
20 # define CRM_COMMON_ISO8601
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
32 /*
33  * http://en.wikipedia.org/wiki/ISO_8601
34  *
35  */
36 
37 # include <time.h>
38 # include <ctype.h>
39 # include <stdbool.h>
40 
41 typedef struct crm_time_s crm_time_t;
42 
43 typedef struct crm_time_period_s {
48 
49 /* Creates a new date/time object conforming to iso8601:
50  * http://en.wikipedia.org/wiki/ISO_8601
51  *
52  * Eg.
53  * Ordinal: 2010-01 12:00:00 +10:00
54  * Gregorian: 2010-01-01 12:00:00 +10:00
55  * ISO Week: 2010-W53-6 12:00:00 +10:00
56  *
57  * Notes:
58  * Only one of date, time is required
59  * If date or timezone is unspecified, they default to the current one
60  * Supplying NULL results in the current date/time
61  * Dashes may be ommitted from dates
62  * Colons may be ommitted from times and timezones
63  * A timezone of 'Z' denoted UTC time
64  */
65 crm_time_t *crm_time_new(const char *string);
66 void crm_time_free(crm_time_t * dt);
67 
68 char *crm_time_as_string(crm_time_t * dt, int flags);
69 
70 # define crm_time_log(level, prefix, dt, flags) crm_time_log_alias(level, __FILE__, __FUNCTION__, __LINE__, prefix, dt, flags)
71 void crm_time_log_alias(int log_level, const char *file, const char *function, int line,
72  const char *prefix, crm_time_t * date_time, int flags);
73 
74 # define crm_time_log_date 0x001
75 # define crm_time_log_timeofday 0x002
76 # define crm_time_log_with_timezone 0x004
77 # define crm_time_log_duration 0x008
78 
79 # define crm_time_ordinal 0x010
80 # define crm_time_weeks 0x020
81 # define crm_time_seconds 0x100
82 # define crm_time_epoch 0x200
83 
84 crm_time_t *crm_time_parse_duration(const char *duration_str);
86 crm_time_period_t *crm_time_parse_period(const char *period_str);
87 
88 int crm_time_compare(crm_time_t * dt, crm_time_t * rhs);
89 
95 
96 /* Time in seconds since 0000-01-01 00:00:00Z */
97 long long int crm_time_get_seconds(crm_time_t * dt);
98 
99 /* Time in seconds since 1970-01-01 00:00:00Z */
100 long long int crm_time_get_seconds_since_epoch(crm_time_t * dt);
101 
102 void crm_time_set(crm_time_t * target, crm_time_t * source);
103 void crm_time_set_timet(crm_time_t * target, time_t * source);
104 
105 /* Returns a new time object */
108 
109 /* All crm_time_add_... functions support negative values */
110 void crm_time_add_seconds(crm_time_t * dt, int value);
111 void crm_time_add_minutes(crm_time_t * dt, int value);
112 void crm_time_add_hours(crm_time_t * dt, int value);
113 void crm_time_add_days(crm_time_t * dt, int value);
114 void crm_time_add_weeks(crm_time_t * dt, int value);
115 void crm_time_add_months(crm_time_t * dt, int value);
116 void crm_time_add_years(crm_time_t * dt, int value);
117 
118 /* Useful helper functions */
119 int crm_time_january1_weekday(int year);
120 int crm_time_weeks_in_year(int year);
121 int crm_time_days_in_month(int month, int year);
122 
123 bool crm_time_leapyear(int year);
124 bool crm_time_check(crm_time_t * dt);
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif
void crm_time_add_years(crm_time_t *dt, int value)
Definition: iso8601.c:1272
void crm_time_add_seconds(crm_time_t *dt, int value)
Definition: iso8601.c:1166
struct crm_time_s crm_time_t
Definition: iso8601.h:41
crm_time_period_t * crm_time_parse_period(const char *period_str)
Definition: iso8601.c:894
int crm_time_weeks_in_year(int year)
Definition: iso8601.c:146
int crm_time_get_timezone(crm_time_t *dt, uint32_t *h, uint32_t *m)
int crm_time_get_ordinal(crm_time_t *dt, uint32_t *y, uint32_t *d)
crm_time_t * crm_time_parse_duration(const char *duration_str)
Definition: iso8601.c:822
void crm_time_add_hours(crm_time_t *dt, int value)
Definition: iso8601.c:1260
void crm_time_add_weeks(crm_time_t *dt, int value)
Definition: iso8601.c:1266
bool crm_time_leapyear(int year)
Definition: iso8601.c:177
crm_time_t * crm_time_calculate_duration(crm_time_t *dt, crm_time_t *value)
Definition: iso8601.c:1062
crm_time_t * start
Definition: iso8601.h:44
void crm_time_add_months(crm_time_t *dt, int value)
Definition: iso8601.c:1212
void crm_time_set_timet(crm_time_t *target, time_t *source)
Definition: iso8601.c:1034
crm_time_t * end
Definition: iso8601.h:45
long long int crm_time_get_seconds_since_epoch(crm_time_t *dt)
Definition: iso8601.c:295
void crm_time_add_minutes(crm_time_t *dt, int value)
Definition: iso8601.c:1254
crm_time_t * diff
Definition: iso8601.h:46
int crm_time_january1_weekday(int year)
Definition: iso8601.c:133
struct crm_time_period_s crm_time_period_t
long long int crm_time_get_seconds(crm_time_t *dt)
Definition: iso8601.c:259
crm_time_t * crm_time_add(crm_time_t *dt, crm_time_t *value)
Definition: iso8601.c:1040
int crm_time_get_gregorian(crm_time_t *dt, uint32_t *y, uint32_t *m, uint32_t *d)
int crm_time_get_timeofday(crm_time_t *dt, uint32_t *h, uint32_t *m, uint32_t *s)
void crm_time_set(crm_time_t *target, crm_time_t *source)
Definition: iso8601.c:972
void crm_time_log_alias(int log_level, const char *file, const char *function, int line, const char *prefix, crm_time_t *date_time, int flags)
Definition: iso8601.c:202
crm_time_t * crm_time_new(const char *string)
Definition: iso8601.c:88
#define uint32_t
Definition: stdint.in.h:158
int crm_time_compare(crm_time_t *dt, crm_time_t *rhs)
Definition: iso8601.c:1139
bool crm_time_check(crm_time_t *dt)
Definition: iso8601.c:1107
crm_time_t * crm_time_subtract(crm_time_t *dt, crm_time_t *value)
Definition: iso8601.c:1085
char * crm_time_as_string(crm_time_t *dt, int flags)
Definition: iso8601.c:397
int crm_time_get_isoweek(crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d)
void crm_time_add_days(crm_time_t *dt, int value)
Definition: iso8601.c:1187
uint64_t flags
Definition: remote.c:148
int crm_time_days_in_month(int month, int year)
Definition: iso8601.c:168
void crm_time_free(crm_time_t *dt)
Definition: iso8601.c:105