1 /*
2 * Copyright (c) 2019 Peter Bigot Consulting
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /* Tests where time_t is a 32-bit value */
8
9 #include <zephyr/ztest.h>
10 #include "timeutil_test.h"
11
12 static const struct timeutil_test_data tests[] = {
13 /* Simple tests */
14 { .ux = -1,
15 .civil = "1969-12-31 23:59:59 Wed 365",
16 .tm = {
17 .tm_sec = 59,
18 .tm_min = 59,
19 .tm_hour = 23,
20 .tm_mday = 31,
21 .tm_mon = 11,
22 .tm_year = 69,
23 .tm_wday = 3,
24 .tm_yday = 364,
25 } },
26 { .ux = 0,
27 .civil = "1970-01-01 00:00:00 Thu 001",
28 .tm = {
29 .tm_sec = 0,
30 .tm_min = 0,
31 .tm_hour = 0,
32 .tm_mday = 1,
33 .tm_mon = 0,
34 .tm_year = 70,
35 .tm_wday = 4,
36 .tm_yday = 0,
37 } },
38 { .ux = 1498577363,
39 .civil = "2017-06-27 15:29:23 Tue 178",
40 .tm = {
41 .tm_sec = 23,
42 .tm_min = 29,
43 .tm_hour = 15,
44 .tm_mday = 27,
45 .tm_mon = 5,
46 .tm_year = 117,
47 .tm_wday = 2,
48 .tm_yday = 177,
49 } },
50
51 /*
52 * 32-bit extreme values. Lower range is limited due
53 * algorithm subtraction rounding to days.
54 */
55 { .ux = -2147483648 + 86399,
56 .civil = "1901-12-14 20:45:51 Sat 348",
57 .tm = {
58 .tm_sec = 51,
59 .tm_min = 45,
60 .tm_hour = 20,
61 .tm_mday = 14,
62 .tm_mon = 11,
63 .tm_year = 1,
64 .tm_wday = 6,
65 .tm_yday = 347,
66 } },
67 { .ux = 2147483647,
68 .civil = "2038-01-19 03:14:07 Tue 019",
69 .tm = {
70 .tm_sec = 7,
71 .tm_min = 14,
72 .tm_hour = 3,
73 .tm_mday = 19,
74 .tm_mon = 0,
75 .tm_year = 138,
76 .tm_wday = 2,
77 .tm_yday = 18,
78 } },
79
80 /* Normal leap year: 1972 */
81 { .ux = 63071999,
82 .civil = "1971-12-31 23:59:59 Fri 365",
83 .tm = {
84 .tm_sec = 59,
85 .tm_min = 59,
86 .tm_hour = 23,
87 .tm_mday = 31,
88 .tm_mon = 11,
89 .tm_year = 71,
90 .tm_wday = 5,
91 .tm_yday = 364,
92 } },
93 { .ux = 63072000,
94 .civil = "1972-01-01 00:00:00 Sat 001",
95 .tm = {
96 .tm_sec = 0,
97 .tm_min = 0,
98 .tm_hour = 0,
99 .tm_mday = 1,
100 .tm_mon = 0,
101 .tm_year = 72,
102 .tm_wday = 6,
103 .tm_yday = 0,
104 } },
105 { .ux = 68083200,
106 .civil = "1972-02-28 00:00:00 Mon 059",
107 .tm = {
108 .tm_sec = 0,
109 .tm_min = 0,
110 .tm_hour = 0,
111 .tm_mday = 28,
112 .tm_mon = 1,
113 .tm_year = 72,
114 .tm_wday = 1,
115 .tm_yday = 58,
116 } },
117 { .ux = 68169600,
118 .civil = "1972-02-29 00:00:00 Tue 060",
119 .tm = {
120 .tm_sec = 0,
121 .tm_min = 0,
122 .tm_hour = 0,
123 .tm_mday = 29,
124 .tm_mon = 1,
125 .tm_year = 72,
126 .tm_wday = 2,
127 .tm_yday = 59,
128 } },
129 { .ux = 68256000,
130 .civil = "1972-03-01 00:00:00 Wed 061",
131 .tm = {
132 .tm_sec = 0,
133 .tm_min = 0,
134 .tm_hour = 0,
135 .tm_mday = 1,
136 .tm_mon = 2,
137 .tm_year = 72,
138 .tm_wday = 3,
139 .tm_yday = 60,
140 } },
141 { .ux = 94521600,
142 .civil = "1972-12-30 00:00:00 Sat 365",
143 .tm = {
144 .tm_sec = 0,
145 .tm_min = 0,
146 .tm_hour = 0,
147 .tm_mday = 30,
148 .tm_mon = 11,
149 .tm_year = 72,
150 .tm_wday = 6,
151 .tm_yday = 364,
152 } },
153 { .ux = 94608000,
154 .civil = "1972-12-31 00:00:00 Sun 366",
155 .tm = {
156 .tm_sec = 0,
157 .tm_min = 0,
158 .tm_hour = 0,
159 .tm_mday = 31,
160 .tm_mon = 11,
161 .tm_year = 72,
162 .tm_wday = 0,
163 .tm_yday = 365,
164 } },
165 { .ux = 94694400,
166 .civil = "1973-01-01 00:00:00 Mon 001",
167 .tm = {
168 .tm_sec = 0,
169 .tm_min = 0,
170 .tm_hour = 0,
171 .tm_mday = 1,
172 .tm_mon = 0,
173 .tm_year = 73,
174 .tm_wday = 1,
175 .tm_yday = 0,
176 } },
177
178 /* Start of era 5, special leap year */
179 { .ux = 946684799,
180 .civil = "1999-12-31 23:59:59 Fri 365",
181 .tm = {
182 .tm_sec = 59,
183 .tm_min = 59,
184 .tm_hour = 23,
185 .tm_mday = 31,
186 .tm_mon = 11,
187 .tm_year = 99,
188 .tm_wday = 5,
189 .tm_yday = 364,
190 } },
191 { .ux = 946684800,
192 .civil = "2000-01-01 00:00:00 Sat 001",
193 .tm = {
194 .tm_sec = 0,
195 .tm_min = 0,
196 .tm_hour = 0,
197 .tm_mday = 1,
198 .tm_mon = 0,
199 .tm_year = 100,
200 .tm_wday = 6,
201 .tm_yday = 0,
202 } },
203 { .ux = 951696000,
204 .civil = "2000-02-28 00:00:00 Mon 059",
205 .tm = {
206 .tm_sec = 0,
207 .tm_min = 0,
208 .tm_hour = 0,
209 .tm_mday = 28,
210 .tm_mon = 1,
211 .tm_year = 100,
212 .tm_wday = 1,
213 .tm_yday = 58,
214 } },
215 { .ux = 951782400,
216 .civil = "2000-02-29 00:00:00 Tue 060",
217 .tm = {
218 .tm_sec = 0,
219 .tm_min = 0,
220 .tm_hour = 0,
221 .tm_mday = 29,
222 .tm_mon = 1,
223 .tm_year = 100,
224 .tm_wday = 2,
225 .tm_yday = 59,
226 } },
227 { .ux = 951868800,
228 .civil = "2000-03-01 00:00:00 Wed 061",
229 .tm = {
230 .tm_sec = 0,
231 .tm_min = 0,
232 .tm_hour = 0,
233 .tm_mday = 1,
234 .tm_mon = 2,
235 .tm_year = 100,
236 .tm_wday = 3,
237 .tm_yday = 60,
238 } },
239 };
240
ZTEST(timeutil_api,test_s32)241 ZTEST(timeutil_api, test_s32)
242 {
243 timeutil_check(tests, sizeof(tests) / sizeof(*tests));
244 }
245