|
18 | 18 |
|
19 | 19 | #include <assert.h>
|
20 | 20 | #include <unistd.h>
|
| 21 | +#include <stdlib.h> |
21 | 22 | #include "../src/time.h"
|
22 | 23 |
|
23 | 24 | /* XXX: keep it synchronized with time.c */
|
@@ -138,11 +139,60 @@ static void test_03(void)
|
138 | 139 | /* TODO: check DST wrap */
|
139 | 140 | }
|
140 | 141 |
|
| 142 | +static void test_04(void) |
| 143 | +{ |
| 144 | + struct tm tm = { |
| 145 | + .tm_sec = 59, |
| 146 | + .tm_min = 58, |
| 147 | + .tm_hour = 3, |
| 148 | + |
| 149 | + .tm_mday = 31, |
| 150 | + .tm_mon = 11, |
| 151 | + .tm_year = 2023 - 1900, |
| 152 | + |
| 153 | + .tm_isdst = -1, |
| 154 | + }; |
| 155 | + |
| 156 | + time_t now = mktime(&tm); |
| 157 | + |
| 158 | + assert(time_max_lt(now, -1) == 0); |
| 159 | + assert(time_max_lt(now, 500) == 1 * 3600 + 1 * 60 + 1 + EXTRA_DAILY_TM); |
| 160 | + assert(time_max_lt(now, 100) == 25 * 3600 + EXTRA_DAILY_TM - (3 * 3600 + 58 * 60 + 59)); |
| 161 | +} |
| 162 | + |
| 163 | +static void test_05(void) |
| 164 | +{ |
| 165 | + /* CEST -> CET DST change */ |
| 166 | + |
| 167 | + /* Sat Mar 25 12:00:00 CET 2023 */ |
| 168 | + assert(time_max_lt(1679742000, 500) == 1679799600 - 1679742000 + EXTRA_DAILY_TM); |
| 169 | + |
| 170 | + /* Sun Mar 26 01:00:00 CET 2023 */ |
| 171 | + assert(time_max_lt(1679788800, 500) == 1679799600 - 1679788800 + EXTRA_DAILY_TM); |
| 172 | + |
| 173 | + /* Sun Mar 26 12:00:00 CEST 2023 */ |
| 174 | + assert(time_max_lt(1679824800, 500) == 1679886000 - 1679824800 + EXTRA_DAILY_TM); |
| 175 | + |
| 176 | + |
| 177 | + /* Sat Oct 28 12:00:00 CEST 2023 */ |
| 178 | + assert(time_max_lt(1698487200, 500) == 1698552000 - 1698487200 + EXTRA_DAILY_TM); |
| 179 | + |
| 180 | + /* Sun Oct 29 01:00:00 CEST 2023 */ |
| 181 | + assert(time_max_lt(1698534000, 500) == 1698552000 - 1698534000 + EXTRA_DAILY_TM); |
| 182 | + |
| 183 | + /* Sun Oct 29 12:00:00 CET 2023 */ |
| 184 | + assert(time_max_lt(1698577200, 500) == 1698638400 - 1698577200 + EXTRA_DAILY_TM); |
| 185 | +} |
| 186 | + |
141 | 187 | #undef main
|
142 | 188 | int main(void)
|
143 | 189 | {
|
| 190 | + setenv("TZ", "Europe/Berlin", 1); |
| 191 | + |
144 | 192 | test_00();
|
145 | 193 | test_01();
|
146 | 194 | test_02();
|
147 | 195 | test_03();
|
| 196 | + test_04(); |
| 197 | + test_05(); |
148 | 198 | }
|
0 commit comments