pacemaker  2.0.3-4b1f869f0f
Scalable High-Availability cluster resource manager
Macros | Functions
iso8601.c File Reference
#include <crm_internal.h>
#include <crm/crm.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <crm/common/iso8601.h>
#include <crm/common/iso8601_internal.h>
Include dependency graph for iso8601.c:

Go to the source code of this file.

Macros

#define GMTOFF(tm)   (-timezone+daylight)
 
#define HOUR_SECONDS   (60 * 60)
 
#define DAY_SECONDS   (HOUR_SECONDS * 24)
 
#define EPOCH_SECONDS   62135596800ULL /* Calculated using crm_time_get_seconds() */
 
#define DATE_MAX   128
 
#define s_if_plural(i)   (((i) == 1)? "" : "s")
 
#define do_cmp_field(l, r, field)
 

Functions

char * crm_time_as_string (crm_time_t *date_time, int flags)
 
gboolean check_for_ordinal (const char *str)
 
crm_time_tcrm_time_new (const char *date_time)
 
crm_time_tcrm_time_new_undefined ()
 Allocate memory for an uninitialized time object. More...
 
bool crm_time_is_defined (const crm_time_t *t)
 Check whether a time object has been initialized yet. More...
 
void crm_time_free (crm_time_t *dt)
 
int crm_time_january1_weekday (int year)
 
int crm_time_weeks_in_year (int year)
 
int crm_time_days_in_month (int month, int year)
 Return number of days in given month of given year. More...
 
bool crm_time_leapyear (int year)
 
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)
 
int crm_time_get_timeofday (crm_time_t *dt, uint *h, uint *m, uint *s)
 
int crm_time_get_timezone (crm_time_t *dt, uint *h, uint *m)
 
long long crm_time_get_seconds (crm_time_t *dt)
 
long long crm_time_get_seconds_since_epoch (crm_time_t *dt)
 
int crm_time_get_gregorian (crm_time_t *dt, uint *y, uint *m, uint *d)
 
int crm_time_get_ordinal (crm_time_t *dt, uint *y, uint *d)
 
int crm_time_get_isoweek (crm_time_t *dt, uint *y, uint *w, uint *d)
 
crm_time_tcrm_time_parse_duration (const char *period_s)
 Parse a time duration from an ISO 8601 duration specification. More...
 
crm_time_period_tcrm_time_parse_period (const char *period_str)
 Parse a time period from an ISO 8601 interval specification. More...
 
void crm_time_free_period (crm_time_period_t *period)
 Free a dynamically allocated time period object. More...
 
void crm_time_set (crm_time_t *target, crm_time_t *source)
 
void crm_time_set_timet (crm_time_t *target, time_t *source)
 
crm_time_tcrm_time_add (crm_time_t *dt, crm_time_t *value)
 
crm_time_tcrm_time_calculate_duration (crm_time_t *dt, crm_time_t *value)
 
crm_time_tcrm_time_subtract (crm_time_t *dt, crm_time_t *value)
 
bool crm_time_check (crm_time_t *dt)
 Check whether a time object represents a sensible date/time. More...
 
int crm_time_compare (crm_time_t *a, crm_time_t *b)
 
void crm_time_add_seconds (crm_time_t *a_time, int extra)
 Add a given number of seconds to a date/time or duration. More...
 
void crm_time_add_days (crm_time_t *a_time, int extra)
 
void crm_time_add_months (crm_time_t *a_time, int extra)
 
void crm_time_add_minutes (crm_time_t *a_time, int extra)
 
void crm_time_add_hours (crm_time_t *a_time, int extra)
 
void crm_time_add_weeks (crm_time_t *a_time, int extra)
 
void crm_time_add_years (crm_time_t *a_time, int extra)
 
crm_time_hr_tcrm_time_hr_convert (crm_time_hr_t *target, crm_time_t *dt)
 
void crm_time_set_hr_dt (crm_time_t *target, crm_time_hr_t *hr_dt)
 
crm_time_hr_tcrm_time_timeval_hr_convert (crm_time_hr_t *target, struct timeval *tv)
 
crm_time_hr_tcrm_time_hr_new (const char *date_time)
 
void crm_time_hr_free (crm_time_hr_t *hr_dt)
 
char * crm_time_format_hr (const char *format, crm_time_hr_t *hr_dt)
 
const char * crm_now_string (time_t *when)
 

Macro Definition Documentation

◆ DATE_MAX

#define DATE_MAX   128

Definition at line 453 of file iso8601.c.

◆ DAY_SECONDS

#define DAY_SECONDS   (HOUR_SECONDS * 24)

Definition at line 48 of file iso8601.c.

◆ do_cmp_field

#define do_cmp_field (   l,
  r,
  field 
)
Value:
if(rc == 0) { \
if(l->field > r->field) { \
crm_trace("%s: %d > %d", \
#field, l->field, r->field); \
rc = 1; \
} else if(l->field < r->field) { \
crm_trace("%s: %d < %d", \
#field, l->field, r->field); \
rc = -1; \
} \
}

Definition at line 1370 of file iso8601.c.

◆ EPOCH_SECONDS

#define EPOCH_SECONDS   62135596800ULL /* Calculated using crm_time_get_seconds() */

Definition at line 352 of file iso8601.c.

◆ GMTOFF

#define GMTOFF (   tm)    (-timezone+daylight)

Definition at line 44 of file iso8601.c.

◆ HOUR_SECONDS

#define HOUR_SECONDS   (60 * 60)

Definition at line 47 of file iso8601.c.

◆ s_if_plural

#define s_if_plural (   i)    (((i) == 1)? "" : "s")

Definition at line 454 of file iso8601.c.

Function Documentation

◆ check_for_ordinal()

gboolean check_for_ordinal ( const char *  str)

◆ crm_now_string()

const char* crm_now_string ( time_t *  when)

Definition at line 1701 of file iso8601.c.

◆ crm_time_add()

crm_time_t* crm_time_add ( crm_time_t dt,
crm_time_t value 
)

Definition at line 1265 of file iso8601.c.

◆ crm_time_add_days()

void crm_time_add_days ( crm_time_t a_time,
int  extra 
)

Definition at line 1434 of file iso8601.c.

◆ crm_time_add_hours()

void crm_time_add_hours ( crm_time_t a_time,
int  extra 
)

Definition at line 1507 of file iso8601.c.

◆ crm_time_add_minutes()

void crm_time_add_minutes ( crm_time_t a_time,
int  extra 
)

Definition at line 1501 of file iso8601.c.

◆ crm_time_add_months()

void crm_time_add_months ( crm_time_t a_time,
int  extra 
)

Definition at line 1459 of file iso8601.c.

◆ crm_time_add_seconds()

void crm_time_add_seconds ( crm_time_t a_time,
int  extra 
)

Add a given number of seconds to a date/time or duration.

Parameters
[in]a_timeDate/time or duration to add seconds to
[in]extraNumber of seconds to add

Definition at line 1414 of file iso8601.c.

◆ crm_time_add_weeks()

void crm_time_add_weeks ( crm_time_t a_time,
int  extra 
)

Definition at line 1513 of file iso8601.c.

◆ crm_time_add_years()

void crm_time_add_years ( crm_time_t a_time,
int  extra 
)

Definition at line 1519 of file iso8601.c.

◆ crm_time_as_string()

char* crm_time_as_string ( crm_time_t date_time,
int  flags 
)

Definition at line 501 of file iso8601.c.

◆ crm_time_calculate_duration()

crm_time_t* crm_time_calculate_duration ( crm_time_t dt,
crm_time_t value 
)

Definition at line 1294 of file iso8601.c.

◆ crm_time_check()

bool crm_time_check ( crm_time_t dt)

Check whether a time object represents a sensible date/time.

Parameters
[in]dtDate/time object to check
Returns
TRUE if years, days, and seconds are sensible, FALSE otherwise

Definition at line 1363 of file iso8601.c.

◆ crm_time_compare()

int crm_time_compare ( crm_time_t a,
crm_time_t b 
)

Definition at line 1384 of file iso8601.c.

◆ crm_time_days_in_month()

int crm_time_days_in_month ( int  month,
int  year 
)

Return number of days in given month of given year.

Parameters
[in]Ordinalmonth (1-12)
[in]Gregorianyear
Returns
Number of days in given month (0 if given month is invalid)

Definition at line 218 of file iso8601.c.

◆ crm_time_format_hr()

char* crm_time_format_hr ( const char *  format,
crm_time_hr_t hr_dt 
)

Definition at line 1618 of file iso8601.c.

◆ crm_time_free()

void crm_time_free ( crm_time_t dt)

Definition at line 144 of file iso8601.c.

◆ crm_time_free_period()

void crm_time_free_period ( crm_time_period_t period)

Free a dynamically allocated time period object.

Parameters
[in]periodTime period to free

Definition at line 1186 of file iso8601.c.

◆ crm_time_get_gregorian()

int crm_time_get_gregorian ( crm_time_t dt,
uint *  y,
uint *  m,
uint *  d 
)

Definition at line 360 of file iso8601.c.

◆ crm_time_get_isoweek()

int crm_time_get_isoweek ( crm_time_t dt,
uint *  y,
uint *  w,
uint *  d 
)

Definition at line 400 of file iso8601.c.

◆ crm_time_get_ordinal()

int crm_time_get_ordinal ( crm_time_t dt,
uint *  y,
uint *  d 
)

Definition at line 392 of file iso8601.c.

◆ crm_time_get_seconds()

long long crm_time_get_seconds ( crm_time_t dt)

Definition at line 311 of file iso8601.c.

◆ crm_time_get_seconds_since_epoch()

long long crm_time_get_seconds_since_epoch ( crm_time_t dt)

Definition at line 354 of file iso8601.c.

◆ crm_time_get_timeofday()

int crm_time_get_timeofday ( crm_time_t dt,
uint *  h,
uint *  m,
uint *  s 
)

Definition at line 297 of file iso8601.c.

◆ crm_time_get_timezone()

int crm_time_get_timezone ( crm_time_t dt,
uint *  h,
uint *  m 
)

Definition at line 303 of file iso8601.c.

◆ crm_time_hr_convert()

crm_time_hr_t* crm_time_hr_convert ( crm_time_hr_t target,
crm_time_t dt 
)

Definition at line 1543 of file iso8601.c.

◆ crm_time_hr_free()

void crm_time_hr_free ( crm_time_hr_t hr_dt)

Definition at line 1612 of file iso8601.c.

◆ crm_time_hr_new()

crm_time_hr_t* crm_time_hr_new ( const char *  date_time)

Definition at line 1592 of file iso8601.c.

◆ crm_time_is_defined()

bool crm_time_is_defined ( const crm_time_t t)

Check whether a time object has been initialized yet.

Parameters
[in]tTime object to check
Returns
TRUE if time object has been initialized, FALSE otherwise

Definition at line 136 of file iso8601.c.

◆ crm_time_january1_weekday()

int crm_time_january1_weekday ( int  year)

Definition at line 172 of file iso8601.c.

◆ crm_time_leapyear()

bool crm_time_leapyear ( int  year)

Definition at line 230 of file iso8601.c.

◆ crm_time_log_alias()

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 at line 255 of file iso8601.c.

◆ crm_time_new()

crm_time_t* crm_time_new ( const char *  date_time)

Definition at line 96 of file iso8601.c.

◆ crm_time_new_undefined()

crm_time_t* crm_time_new_undefined ( )

Allocate memory for an uninitialized time object.

Returns
Newly allocated time object
Note
The caller is responsible for freeing the return value using crm_time_free().

Definition at line 120 of file iso8601.c.

◆ crm_time_parse_duration()

crm_time_t* crm_time_parse_duration ( const char *  period_s)

Parse a time duration from an ISO 8601 duration specification.

Parameters
[in]period_sISO 8601 duration specification (optionally followed by whitespace, after which the rest of the string will be ignored)
Returns
New time object on success, NULL (and set errno) otherwise
Note
It is the caller's responsibility to return the result using crm_time_free().

Definition at line 987 of file iso8601.c.

◆ crm_time_parse_period()

crm_time_period_t* crm_time_parse_period ( const char *  period_str)

Parse a time period from an ISO 8601 interval specification.

Parameters
[in]period_strISO 8601 interval specification (start/end, start/duration, or duration/end)
Returns
New time period object on success, NULL (and set errno) otherwise
Note
The caller is responsible for freeing the result using crm_time_free_period().

Definition at line 1095 of file iso8601.c.

◆ crm_time_set()

void crm_time_set ( crm_time_t target,
crm_time_t source 
)

Definition at line 1197 of file iso8601.c.

◆ crm_time_set_hr_dt()

void crm_time_set_hr_dt ( crm_time_t target,
crm_time_hr_t hr_dt 
)

Definition at line 1564 of file iso8601.c.

◆ crm_time_set_timet()

void crm_time_set_timet ( crm_time_t target,
time_t *  source 
)

Definition at line 1259 of file iso8601.c.

◆ crm_time_subtract()

crm_time_t* crm_time_subtract ( crm_time_t dt,
crm_time_t value 
)

Definition at line 1328 of file iso8601.c.

◆ crm_time_timeval_hr_convert()

crm_time_hr_t* crm_time_timeval_hr_convert ( crm_time_hr_t target,
struct timeval *  tv 
)

Definition at line 1578 of file iso8601.c.

◆ crm_time_weeks_in_year()

int crm_time_weeks_in_year ( int  year)

Definition at line 185 of file iso8601.c.