20 assert_add_seconds(
const char *orig_date_time,
int seconds,
21 const char *expected_date_time)
26 assert_non_null(orig);
27 assert_non_null(expected);
37 invalid_argument(
void **state)
43 add_zero(
void **state)
45 assert_add_seconds(
"2024-01-01 00:30:00 +01:00", 0,
46 "2024-01-01 00:30:00 +01:00");
50 add_less_than_one_day(
void **state)
53 assert_add_seconds(
"2024-01-01 00:30:00 +01:00", 1,
54 "2024-01-01 00:30:01 +01:00");
55 assert_add_seconds(
"2024-01-01 00:30:00 +01:00", 59,
56 "2024-01-01 00:30:59 +01:00");
59 assert_add_seconds(
"2024-01-01 00:30:59 +02:00", 1,
60 "2024-01-01 00:31:00 +02:00");
61 assert_add_seconds(
"2024-01-01 00:44:30 +02:00", 60,
62 "2024-01-01 00:45:30 +02:00");
63 assert_add_seconds(
"2024-01-01 00:44:30 +02:00", 125,
64 "2024-01-01 00:46:35 +02:00");
67 assert_add_seconds(
"2024-01-01 00:59:59 -03:00", 1,
68 "2024-01-01 01:00:00 -03:00");
69 assert_add_seconds(
"2024-01-01 00:23:34 -03:00", 3600,
70 "2024-01-01 01:23:34 -03:00");
71 assert_add_seconds(
"2024-01-01 00:23:34 -03:00", 7210,
72 "2024-01-01 02:23:44 -03:00");
75 assert_add_seconds(
"2024-01-01 23:59:59 +04:00", 1,
76 "2024-01-02 00:00:00 +04:00");
77 assert_add_seconds(
"2024-02-28 00:05:00 +04:00", 86200,
78 "2024-02-29 00:01:40 +04:00");
81 assert_add_seconds(
"2023-02-28 00:05:00 -05:00", 86200,
82 "2023-03-01 00:01:40 -05:00");
83 assert_add_seconds(
"2024-02-29 23:59:00 -05:00", 60,
84 "2024-03-01 00:00:00 -05:00");
87 assert_add_seconds(
"2024-12-31 23:59:59 +06:00", 1,
88 "2025-01-01 00:00:00 +06:00");
92 add_more_than_one_day(
void **state)
95 assert_add_seconds(
"2024-01-01 00:00:00 +01:00", 86400 * 2,
96 "2024-01-03 00:00:00 +01:00");
97 assert_add_seconds(
"2024-02-27 23:59:59 +01:00", 86400 * 2,
98 "2024-02-29 23:59:59 +01:00");
101 assert_add_seconds(
"2023-02-26 23:59:59 -02:00", 86400 * 2 + 1,
102 "2023-03-01 00:00:00 -02:00");
103 assert_add_seconds(
"2024-02-27 23:59:59 -02:00", 86400 * 2 + 1,
104 "2024-03-01 00:00:00 -02:00");
107 assert_add_seconds(
"2024-12-01 00:00:00 +06:00", 86400 * 31,
108 "2025-01-01 00:00:00 +06:00");
112 subtract_less_than_one_day(
void **state)
115 assert_add_seconds(
"2024-01-01 00:30:01 +01:00", -1,
116 "2024-01-01 00:30:00 +01:00");
117 assert_add_seconds(
"2024-01-01 00:30:30 +01:00", -5,
118 "2024-01-01 00:30:25 +01:00");
119 assert_add_seconds(
"2024-01-01 00:30:59 +01:00", -59,
120 "2024-01-01 00:30:00 +01:00");
123 assert_add_seconds(
"2024-01-01 00:30:00 +02:00", -1,
124 "2024-01-01 00:29:59 +02:00");
125 assert_add_seconds(
"2024-01-01 00:44:30 +02:00", -60,
126 "2024-01-01 00:43:30 +02:00");
127 assert_add_seconds(
"2024-01-01 00:14:30 +02:00", -125,
128 "2024-01-01 00:12:25 +02:00");
131 assert_add_seconds(
"2024-01-01 01:00:00 -03:00", -1,
132 "2024-01-01 00:59:59 -03:00");
133 assert_add_seconds(
"2024-01-01 01:23:34 -03:00", -3600,
134 "2024-01-01 00:23:34 -03:00");
135 assert_add_seconds(
"2024-01-01 02:23:34 -03:00", -7210,
136 "2024-01-01 00:23:24 -03:00");
139 assert_add_seconds(
"2024-01-02 00:00:00 +04:00", -1,
140 "2024-01-01 23:59:59 +04:00");
141 assert_add_seconds(
"2024-02-29 00:01:40 +04:00", -86200,
142 "2024-02-28 00:05:00 +04:00");
145 assert_add_seconds(
"2023-03-01 00:01:40 -05:00", -86200,
146 "2023-02-28 00:05:00 -05:00");
147 assert_add_seconds(
"2024-03-01 00:00:00 -05:00", -60,
148 "2024-02-29 23:59:00 -05:00");
151 assert_add_seconds(
"2025-01-01 00:00:00 +06:00", -1,
152 "2024-12-31 23:59:59 +06:00");
156 subtract_more_than_one_day(
void **state)
159 assert_add_seconds(
"2024-01-03 00:00:00 +01:00", 86400 * -2,
160 "2024-01-01 00:00:00 +01:00");
161 assert_add_seconds(
"2024-02-29 23:59:59 +01:00", 86400 * -2,
162 "2024-02-27 23:59:59 +01:00");
165 assert_add_seconds(
"2023-03-03 00:00:00 -02:00", 86400 * -2 - 1,
166 "2023-02-28 23:59:59 -02:00");
167 assert_add_seconds(
"2024-03-03 00:00:00 -02:00", 86400 * -2 - 1,
168 "2024-02-29 23:59:59 -02:00");
171 assert_add_seconds(
"2025-01-01 00:00:00 +06:00", 86400 * -31,
172 "2024-12-01 00:00:00 +06:00");
176 cmocka_unit_test(invalid_argument),
177 cmocka_unit_test(add_zero),
178 cmocka_unit_test(add_less_than_one_day),
179 cmocka_unit_test(add_more_than_one_day),
180 cmocka_unit_test(subtract_less_than_one_day),
181 cmocka_unit_test(subtract_more_than_one_day));
void crm_time_add_seconds(crm_time_t *dt, int value)
Add a given number of seconds to a date/time or duration.
struct crm_time_s crm_time_t
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(invalid_argument), cmocka_unit_test(add_zero), cmocka_unit_test(add_less_than_one_day), cmocka_unit_test(add_more_than_one_day), cmocka_unit_test(subtract_less_than_one_day), cmocka_unit_test(subtract_more_than_one_day))
#define pcmk__assert_asserts(stmt)
int crm_time_compare(const crm_time_t *a, const crm_time_t *b)
crm_time_t * crm_time_new(const char *string)
void crm_time_free(crm_time_t *dt)