pacemaker 2.1.1-77db578727
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
iso8601.h
Go to the documentation of this file.
1/*
2 * Copyright 2005-2020 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#ifndef CRM_COMMON_ISO8601
11# define CRM_COMMON_ISO8601
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
23/*
24 * See https://en.wikipedia.org/wiki/ISO_8601
25 */
26
27# include <time.h>
28# include <ctype.h>
29# include <stdint.h> // uint32_t
30# include <stdbool.h> // bool
31
32typedef struct crm_time_s crm_time_t;
33
39
40/* Creates a new date/time object conforming to ISO 8601, for example:
41 * Ordinal: 2010-01 12:00:00 +10:00
42 * Gregorian: 2010-01-01 12:00:00 +10:00
43 * ISO Week: 2010-W53-6 12:00:00 +10:00
44 *
45 * Notes:
46 * Only one of date, time is required
47 * If date or timezone is unspecified, they default to the current one
48 * Supplying NULL results in the current date/time
49 * Dashes may be omitted from dates
50 * Colons may be omitted from times and timezones
51 * A timezone of 'Z' denotes UTC time
52 */
53crm_time_t *crm_time_new(const char *string);
55void crm_time_free(crm_time_t * dt);
56
57bool crm_time_is_defined(const crm_time_t *t);
58char *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
63void 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
76crm_time_t *crm_time_parse_duration(const char *duration_str);
78crm_time_period_t *crm_time_parse_period(const char *period_str);
80
82
83int crm_time_get_timeofday(crm_time_t * dt, uint32_t * h, uint32_t * m, uint32_t * s);
84int crm_time_get_timezone(crm_time_t * dt, uint32_t * h, uint32_t * m);
85int crm_time_get_gregorian(crm_time_t * dt, uint32_t * y, uint32_t * m, uint32_t * d);
86int crm_time_get_ordinal(crm_time_t * dt, uint32_t * y, uint32_t * d);
87int crm_time_get_isoweek(crm_time_t * dt, uint32_t * y, uint32_t * w, uint32_t * d);
88
89/* Time in seconds since 0000-01-01 00:00:00Z */
90long long int crm_time_get_seconds(crm_time_t * dt);
91
92/* Time in seconds since 1970-01-01 00:00:00Z */
94
96void crm_time_set_timet(crm_time_t * target, time_t * source);
97
98/* Returns a new time object */
102
103/* All crm_time_add_... functions support negative values */
104void crm_time_add_seconds(crm_time_t * dt, int value);
105void crm_time_add_minutes(crm_time_t * dt, int value);
106void crm_time_add_hours(crm_time_t * dt, int value);
107void crm_time_add_days(crm_time_t * dt, int value);
108void crm_time_add_weeks(crm_time_t * dt, int value);
109void crm_time_add_months(crm_time_t * dt, int value);
110void crm_time_add_years(crm_time_t * dt, int value);
111
112/* Useful helper functions */
113int crm_time_january1_weekday(int year);
114int crm_time_weeks_in_year(int year);
115int crm_time_days_in_month(int month, int year);
116
117bool crm_time_leapyear(int year);
118bool crm_time_check(crm_time_t * dt);
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif
uint64_t flags
Definition remote.c:3
int crm_time_get_gregorian(crm_time_t *dt, uint32_t *y, uint32_t *m, uint32_t *d)
void crm_time_add_hours(crm_time_t *dt, int value)
Definition iso8601.c:1510
crm_time_t * crm_time_subtract(crm_time_t *dt, crm_time_t *value)
Definition iso8601.c:1332
void crm_time_add_seconds(crm_time_t *dt, int value)
Add a given number of seconds to a date/time or duration.
Definition iso8601.c:1417
char * crm_time_as_string(crm_time_t *dt, int flags)
Definition iso8601.c:497
crm_time_t * pcmk_copy_time(crm_time_t *source)
Definition iso8601.c:1261
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:252
void crm_time_add_weeks(crm_time_t *dt, int value)
Definition iso8601.c:1516
void crm_time_add_days(crm_time_t *dt, int value)
Definition iso8601.c:1437
crm_time_t * crm_time_parse_duration(const char *duration_str)
Parse a time duration from an ISO 8601 duration specification.
Definition iso8601.c:983
long long int crm_time_get_seconds_since_epoch(crm_time_t *dt)
Definition iso8601.c:351
int crm_time_get_isoweek(crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d)
crm_time_period_t * crm_time_parse_period(const char *period_str)
Parse a time period from an ISO 8601 interval specification.
Definition iso8601.c:1091
int crm_time_compare(crm_time_t *dt, crm_time_t *rhs)
Definition iso8601.c:1387
int crm_time_january1_weekday(int year)
Definition iso8601.c:169
struct crm_time_period_s crm_time_period_t
void crm_time_free(crm_time_t *dt)
Definition iso8601.c:141
void crm_time_free_period(crm_time_period_t *period)
Free a dynamically allocated time period object.
Definition iso8601.c:1182
int crm_time_get_timezone(crm_time_t *dt, uint32_t *h, uint32_t *m)
bool crm_time_check(crm_time_t *dt)
Check whether a time object represents a sensible date/time.
Definition iso8601.c:1366
void crm_time_set_timet(crm_time_t *target, time_t *source)
Definition iso8601.c:1255
int crm_time_days_in_month(int month, int year)
Return number of days in given month of given year.
Definition iso8601.c:215
void crm_time_add_years(crm_time_t *dt, int value)
Definition iso8601.c:1522
crm_time_t * crm_time_add(crm_time_t *dt, crm_time_t *value)
Definition iso8601.c:1270
bool crm_time_is_defined(const crm_time_t *t)
Check whether a time object has been initialized yet.
Definition iso8601.c:133
int crm_time_weeks_in_year(int year)
Definition iso8601.c:182
int crm_time_get_timeofday(crm_time_t *dt, uint32_t *h, uint32_t *m, uint32_t *s)
void crm_time_add_months(crm_time_t *dt, int value)
Definition iso8601.c:1462
crm_time_t * crm_time_calculate_duration(crm_time_t *dt, crm_time_t *value)
Definition iso8601.c:1298
bool crm_time_leapyear(int year)
Definition iso8601.c:227
void crm_time_set(crm_time_t *target, crm_time_t *source)
Definition iso8601.c:1193
crm_time_t * crm_time_new(const char *string)
Definition iso8601.c:93
long long int crm_time_get_seconds(crm_time_t *dt)
Definition iso8601.c:308
crm_time_t * crm_time_new_undefined(void)
Allocate memory for an uninitialized time object.
Definition iso8601.c:117
struct crm_time_s crm_time_t
Definition iso8601.h:32
int crm_time_get_ordinal(crm_time_t *dt, uint32_t *y, uint32_t *d)
void crm_time_add_minutes(crm_time_t *dt, int value)
Definition iso8601.c:1504
const char * target
Definition pcmk_fence.c:29
crm_time_t * end
Definition iso8601.h:36
crm_time_t * diff
Definition iso8601.h:37
crm_time_t * start
Definition iso8601.h:35