Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8fde207
Refactor: libcrmcommon: Drop ha_set_tm_time()
nrwahl2 Nov 18, 2025
3057ab6
Doc: libcrmcommon: crm_time_new_undefined() guarantees non-NULL
nrwahl2 Nov 18, 2025
0d59dbc
Refactor: libcrmcommon: Avoid allocation in crm_time_compare()
nrwahl2 Nov 18, 2025
e1087ad
Refactor: libcrmcommon: Drop redundant checks after crm_get_utc_time()
nrwahl2 Nov 18, 2025
dba9b5f
Low: libraries: Ensure includes are outside extern in public headers
nrwahl2 Nov 18, 2025
bfc4b93
API: libcrmcommon: Deprecate crm_time_leapyear()
nrwahl2 Nov 18, 2025
a92dff1
API: libcrmcommon: Deprecate crm_time_days_in_month()
nrwahl2 Nov 18, 2025
a4b3761
Refactor: libcrmcommon: Rename crm_time_get_sec() to second_to_hms()
nrwahl2 Nov 18, 2025
2dc0b42
API: libcrmcommon: Deprecate crm_time_get_timezone()
nrwahl2 Nov 18, 2025
ddadab1
Refactor: libcrmcommon: crm_time_parse_sec() -> parse_hms()
nrwahl2 Nov 18, 2025
2fe7ccf
Refactor: libcrmcommon: crm_time_parse_offset() -> parse_offset()
nrwahl2 Nov 18, 2025
a8d0d70
Refactor: libcrmcommon: crm_time_parse() -> parse_time()
nrwahl2 Nov 18, 2025
0cb4d50
Refactor: libcrmcommon: Drop error label from crm_time_parse_period()
nrwahl2 Nov 18, 2025
d3f7132
Refactor: libcrmcommon: Avoid crm_time_new() in parse_date()
nrwahl2 Nov 18, 2025
efd2d0e
API: libcrmcommon: Deprecate crm_time_weeks_in_year()
nrwahl2 Nov 18, 2025
77e9a7f
API: libcrmcommon: Deprecate crm_time_january1_weekday()
nrwahl2 Nov 18, 2025
82e1771
Refactor: libpacemaker: Don't return NULL from generate_location_rule()
nrwahl2 Nov 18, 2025
29516b2
Refactor: libcrmcommon: Drop internal uses of crm_time_set()
nrwahl2 Nov 18, 2025
8f3de44
API: libcrmcommon: Deprecate crm_time_set()
nrwahl2 Nov 18, 2025
306a8e9
API: libcrmcommon: Deprecate crm_time_check()
nrwahl2 Nov 18, 2025
fe9d92f
Refactor: libcrmcommon: Drop crm_time_set_timet() internally
nrwahl2 Nov 18, 2025
f77d4fc
API: libcrmcommon: Deprecate crm_time_set_timet()
nrwahl2 Nov 18, 2025
d0ea4f2
Refactor: libcrmcommon: New pcmk__time_get_ywd()
nrwahl2 Nov 18, 2025
0729aa4
API: libcrmcommon: Deprecate crm_time_get_isoweek()
nrwahl2 Nov 18, 2025
2dbe1fd
Refactor: libcrmcommon: New pcmk__time_log{,_as}()
nrwahl2 Nov 18, 2025
83b6828
API: libcrmcommon: Deprecate crm_time_log()
nrwahl2 Nov 18, 2025
cd52621
API: libcrmcommon: Deprecate crm_time_log_alias()
nrwahl2 Nov 18, 2025
6dd7312
Refactor: libcrmcommon: Drop forward declaration for parse_date()
nrwahl2 Nov 18, 2025
922c72e
Refactor: libcrmcommon: Rename HOUR_SECONDS to SECONDS_IN_HOUR
nrwahl2 Nov 19, 2025
d4742d1
Refactor: libcrmcommon: Rename DAY_SECONDS to SECONDS_IN_DAY
nrwahl2 Nov 19, 2025
16839a0
Refactor: libcrmcommon: New SECONDS_IN_MINUTE
nrwahl2 Nov 19, 2025
2d5f89c
Refactor: libcrmcommon: New MINUTES_IN_HOUR
nrwahl2 Nov 19, 2025
dc2334c
Refactor: libcrmcommon: New HOURS_IN_DAY
nrwahl2 Nov 19, 2025
ad9a1ea
Low: libcrmcommon: Avoid integer overflow in seconds_to_hms()
nrwahl2 Nov 19, 2025
4a0c970
Low: libcrmcommon: Fix underflow in crm_time_add_days()
nrwahl2 Nov 22, 2025
5762141
Doc: libcrmcommon: Negative crm_time_t:years is treated inconistently
nrwahl2 Nov 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cts/cli/regression.dates.exp
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ iso8601: Invalid interval specified: 20191077T15/P1M
=#=#=#= End test: Invalid period - [20191077T15/P1M] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [20191077T15/P1M]
=#=#=#= Begin test: Invalid period - [2019-10-01T25:00:00Z/P1M] =#=#=#=
crm_time_parse_sec error: 25:00:00Z/P1M is not a valid ISO 8601 time specification because 25 is not a valid hour
parse_hms error: 25:00:00Z/P1M is not a valid ISO 8601 time specification because 25 is not a valid hour
iso8601: Invalid interval specified: 2019-10-01T25:00:00Z/P1M
=#=#=#= End test: Invalid period - [2019-10-01T25:00:00Z/P1M] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [2019-10-01T25:00:00Z/P1M]
=#=#=#= Begin test: Invalid period - [2019-10-01T24:00:01Z/P1M] =#=#=#=
crm_time_parse_sec error: 24:00:01Z/P1M is not a valid ISO 8601 time specification because 24 is not a valid hour
parse_hms error: 24:00:01Z/P1M is not a valid ISO 8601 time specification because 24 is not a valid hour
iso8601: Invalid interval specified: 2019-10-01T24:00:01Z/P1M
=#=#=#= End test: Invalid period - [2019-10-01T24:00:01Z/P1M] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [2019-10-01T24:00:01Z/P1M]
=#=#=#= Begin test: Invalid period - [PT5H/20191001T007000Z] =#=#=#=
crm_time_parse_sec error: 007000Z is not a valid ISO 8601 time specification because 70 is not a valid minute
parse_hms error: 007000Z is not a valid ISO 8601 time specification because 70 is not a valid minute
iso8601: Invalid interval specified: PT5H/20191001T007000Z
=#=#=#= End test: Invalid period - [PT5H/20191001T007000Z] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [PT5H/20191001T007000Z]
=#=#=#= Begin test: Invalid period - [2019-10-01 00:00:80Z/P1M] =#=#=#=
crm_time_parse_sec error: 00:00:80Z/P1M is not a valid ISO 8601 time specification because 80 is not a valid second
parse_hms error: 00:00:80Z/P1M is not a valid ISO 8601 time specification because 80 is not a valid second
iso8601: Invalid interval specified: 2019-10-01 00:00:80Z/P1M
=#=#=#= End test: Invalid period - [2019-10-01 00:00:80Z/P1M] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [2019-10-01 00:00:80Z/P1M]
=#=#=#= Begin test: Invalid period - [2019-10-01 00:00:10 +25:00/P1M] =#=#=#=
crm_time_parse_sec error: 25:00/P1M is not a valid ISO 8601 time specification because 25 is not a valid hour
parse_hms error: 25:00/P1M is not a valid ISO 8601 time specification because 25 is not a valid hour
iso8601: Invalid interval specified: 2019-10-01 00:00:10 +25:00/P1M
=#=#=#= End test: Invalid period - [2019-10-01 00:00:10 +25:00/P1M] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [2019-10-01 00:00:10 +25:00/P1M]
=#=#=#= Begin test: Invalid period - [20191001T000010 -00:61/P1M] =#=#=#=
crm_time_parse_sec error: 00:61/P1M is not a valid ISO 8601 time specification because 61 is not a valid minute
parse_hms error: 00:61/P1M is not a valid ISO 8601 time specification because 61 is not a valid minute
iso8601: Invalid interval specified: 20191001T000010 -00:61/P1M
=#=#=#= End test: Invalid period - [20191001T000010 -00:61/P1M] - Invalid parameter (2) =#=#=#=
* Passed: iso8601 - Invalid period - [20191001T000010 -00:61/P1M]
Expand Down
2 changes: 1 addition & 1 deletion cts/cts-cli.in
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def sanitize_output(s):
(r'@crm_feature_set=[0-9.]+, ', r''),
(r'\(crm_time_parse_duration@.*\.c:[0-9]+\)', r'crm_time_parse_duration'),
(r'\(crm_time_parse_period@.*\.c:[0-9]+\)', r'crm_time_parse_period'),
(r'\(crm_time_parse_sec@.*\.c:[0-9]+\)', r'crm_time_parse_sec'),
(r'\(parse_hms@.*\.c:[0-9]+\)', r'parse_hms'),
(re.escape(cts_cli_data), r'CTS_CLI_DATA'),
(r' default="[^"]*"', r' default=""'),
(r' end="[0-9][-+: 0-9]*Z*"', r' end=""'),
Expand Down
1 change: 1 addition & 0 deletions include/crm/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ header_HEADERS = acl.h \
ipc_pacemakerd.h \
ipc_schedulerd.h \
iso8601.h \
iso8601_compat.h \
logging.h \
logging_compat.h \
mainloop.h \
Expand Down
8 changes: 4 additions & 4 deletions include/crm/common/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ bool xml_acl_filtered_copy(const char *user, xmlNode* acl_source, xmlNode *xml,

bool pcmk_acl_required(const char *user);

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/acl_compat.h>
#endif // !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)

#ifdef __cplusplus
}
#endif

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/acl_compat.h>
#endif // !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)

#endif // PCMK__CRM_COMMON_ACL__H
33 changes: 11 additions & 22 deletions include/crm/common/iso8601.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2005-2024 the Pacemaker project contributors
* Copyright 2005-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
Expand Down Expand Up @@ -29,6 +29,12 @@ extern "C" {
* See https://en.wikipedia.org/wiki/ISO_8601
*/

/*!
* \brief An opaque date and time object
*
* \note Negative years are treated inconsistently and should not be relied
* upon.
*/
typedef struct crm_time_s crm_time_t;

typedef struct crm_time_period_s {
Expand Down Expand Up @@ -57,13 +63,6 @@ void crm_time_free(crm_time_t * dt);
bool crm_time_is_defined(const crm_time_t *t);
char *crm_time_as_string(const crm_time_t *dt, int flags);

#define crm_time_log(level, prefix, dt, flags) \
crm_time_log_alias(level, __FILE__, __func__, __LINE__, prefix, dt, flags)

void crm_time_log_alias(int log_level, const char *file, const char *function,
int line, const char *prefix,
const crm_time_t *date_time, int flags);

#define crm_time_log_date 0x001
#define crm_time_log_timeofday 0x002
#define crm_time_log_with_timezone 0x004
Expand All @@ -85,22 +84,16 @@ int crm_time_compare(const crm_time_t *a, const crm_time_t *b);

int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m,
uint32_t *s);
int crm_time_get_timezone(const crm_time_t *dt, uint32_t *h, uint32_t *m);
int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m,
uint32_t *d);
int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d);
int crm_time_get_isoweek(const crm_time_t *dt, uint32_t *y, uint32_t *w,
uint32_t * d);

/* Time in seconds since 0000-01-01 00:00:00Z */
long long crm_time_get_seconds(const crm_time_t *dt);

/* Time in seconds since 1970-01-01 00:00:00Z */
long long crm_time_get_seconds_since_epoch(const crm_time_t *dt);

void crm_time_set(crm_time_t *target, const crm_time_t *source);
void crm_time_set_timet(crm_time_t *target, const time_t *source);

/* Returns a new time object */
crm_time_t *pcmk_copy_time(const crm_time_t *source);
crm_time_t *crm_time_add(const crm_time_t *dt, const crm_time_t *value);
Expand All @@ -115,16 +108,12 @@ void crm_time_add_weeks(crm_time_t * dt, int value);
void crm_time_add_months(crm_time_t * dt, int value);
void crm_time_add_years(crm_time_t * dt, int value);

/* Useful helper functions */
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);

bool crm_time_leapyear(int year);
bool crm_time_check(const crm_time_t *dt);

#ifdef __cplusplus
}
#endif

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/iso8601_compat.h>
#endif

#endif
73 changes: 73 additions & 0 deletions include/crm/common/iso8601_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2004-2025 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/

#ifndef PCMK__CRM_COMMON_ISO8601_COMPAT__H
#define PCMK__CRM_COMMON_ISO8601_COMPAT__H

#include <stdbool.h>
#include <stdint.h> // uint32_t
#include <time.h> // time_t

#include <crm/common/iso8601.h> // crm_time_t

#ifdef __cplusplus
extern "C" {
#endif

/**
* \file
* \brief Deprecated Pacemaker time API
* \ingroup core
* \deprecated Do not include this header directly. The time APIs in this
* header, and the header itself, will be removed in a future
* release.
*/

//! \deprecated Do not use
bool crm_time_leapyear(int year);

//! \deprecated Do not use
int crm_time_days_in_month(int month, int year);

//! \deprecated Do not use
int crm_time_get_timezone(const crm_time_t *dt, uint32_t *h, uint32_t *m);

//! \deprecated Do not use
int crm_time_weeks_in_year(int year);

//! \deprecated Do not use
int crm_time_january1_weekday(int year);

//! \deprecated Do not use
void crm_time_set(crm_time_t *target, const crm_time_t *source);

//! \deprecated Do not use
bool crm_time_check(const crm_time_t *dt);

//! \deprecated Do not use
void crm_time_set_timet(crm_time_t *target, const time_t *source_sec);

//! \deprecated Do not use
int crm_time_get_isoweek(const crm_time_t *dt, uint32_t *y, uint32_t *w,
uint32_t *d);

//! \deprecated Do not use
#define crm_time_log(level, prefix, dt, flags) \
crm_time_log_alias(level, __FILE__, __func__, __LINE__, prefix, dt, flags)

//! \deprecated Do not use
void crm_time_log_alias(int log_level, const char *file, const char *function,
int line, const char *prefix,
const crm_time_t *date_time, int flags);

#ifdef __cplusplus
}
#endif

#endif // PCMK__CRM_COMMON_ISO8601_COMPAT__H
19 changes: 15 additions & 4 deletions include/crm/common/iso8601_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@
#ifndef PCMK__CRM_COMMON_ISO8601_INTERNAL__H
#define PCMK__CRM_COMMON_ISO8601_INTERNAL__H

#include <glib.h>
#include <time.h>
#include <sys/time.h>
#include <ctype.h>
#include <stdint.h> // uint8_t, uint32_t
#include <sys/time.h>
#include <time.h>

#include <glib.h>
#include <crm/common/iso8601.h>

#ifdef __cplusplus
extern "C" {
#endif

void pcmk__time_get_ywd(const crm_time_t *dt, uint32_t *y, uint32_t *w,
uint32_t *d);
char *pcmk__time_format_hr(const char *format, const crm_time_t *dt, int usec);
char *pcmk__epoch2str(const time_t *source, uint32_t flags);
char *pcmk__timespec2str(const struct timespec *ts, uint32_t flags);
const char *pcmk__readable_interval(guint interval_ms);
crm_time_t *pcmk__copy_timet(time_t source);
crm_time_t *pcmk__copy_timet(time_t source_sec);

void pcmk__time_log_as(const char *file, const char *function, int line,
uint8_t level, const char *prefix, const crm_time_t *dt,
uint32_t flags);

#define pcmk__time_log(level, prefix, dt, flags) \
pcmk__time_log_as(__FILE__, __func__, __LINE__, level, prefix, dt, flags);

// A date/time or duration
struct crm_time_s {
Expand Down
8 changes: 4 additions & 4 deletions include/crm/common/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ extern "C" {

int pcmk_parse_interval_spec(const char *input, guint *result_ms);

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/strings_compat.h>
#endif

#ifdef __cplusplus
}
#endif

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/strings_compat.h>
#endif

#endif // PCMK__CRM_COMMON_STRINGS__H
8 changes: 4 additions & 4 deletions include/crm/common/xml_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ extern "C" {
* \ingroup core
*/

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/xml_io_compat.h>
#endif

#ifdef __cplusplus
}
#endif

#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
#include <crm/common/xml_io_compat.h>
#endif

#endif // PCMK__CRM_COMMON_XML_IO__H
7 changes: 4 additions & 3 deletions lib/common/fuzzers/iso8601_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
crm_time_period_t *period = NULL;

struct timespec tv = { 0, };
crm_time_t now = { 0, };
crm_time_t *now = NULL;
char *result = NULL;

// Ensure we have enough data.
Expand All @@ -38,9 +38,10 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
crm_time_free_period(period);

qb_util_timespec_from_epoch_get(&tv);
crm_time_set_timet(&now, &(tv.tv_sec));
result = pcmk__time_format_hr(ns, &now,
now = pcmk__copy_timet(tv.tv_sec);
result = pcmk__time_format_hr(ns, now,
(int) (tv.tv_nsec / QB_TIME_NS_IN_USEC));
crm_time_free(now);
free(result);

free(ns);
Expand Down
Loading