1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdlib.h>
17 #include <time.h>
18 #include "functionalext.h"
19
20 struct difftime_struct {
21 const char *tz;
22 const double result;
23 };
24
25 static const struct difftime_struct gResultData[] = {
26 {"Pacific/Rarotonga", 10.000000},
27 {"Pacific/Wake", 10.000000},
28 {"Pacific/Tarawa", 10.000000},
29 {"Pacific/Fakaofo", 10.000000},
30 {"Pacific/Apia", 10.000000},
31 {"Pacific/Kwajalein", 10.000000},
32 {"Pacific/Tahiti", 10.000000},
33 {"Pacific/Easter", 10.000000},
34 {"Pacific/Tongatapu", 10.000000},
35 {"Pacific/Guadalcanal", 10.000000},
36 {"Pacific/Chuuk", 10.000000},
37 {"Pacific/Pitcairn", 10.000000},
38 {"Pacific/Pohnpei", 10.000000},
39 {"Pacific/Fiji", 10.000000},
40 {"Pacific/Majuro", 10.000000},
41 {"Pacific/Kiritimati", 10.000000},
42 {"Pacific/Port_Moresby", 10.000000},
43 {"Pacific/Galapagos", 10.000000},
44 {"Pacific/Saipan", 10.000000},
45 {"Pacific/Marquesas", 10.000000},
46 {"Pacific/Wallis", 10.000000},
47 {"Pacific/Palau", 10.000000},
48 {"Pacific/Bougainville", 10.000000},
49 {"Pacific/Honolulu", 10.000000},
50 {"Pacific/Noumea", 10.000000},
51 {"Pacific/Pago_Pago", 10.000000},
52 {"Pacific/Guam", 10.000000},
53 {"Pacific/Auckland", 10.000000},
54 {"Pacific/Norfolk", 10.000000},
55 {"Pacific/Kosrae", 10.000000},
56 {"Pacific/Nauru", 10.000000},
57 {"Pacific/Chatham", 10.000000},
58 {"Pacific/Efate", 10.000000},
59 {"Pacific/Midway", 10.000000},
60 {"Pacific/Niue", 10.000000},
61 {"Pacific/Enderbury", 10.000000},
62 {"Pacific/Funafuti", 10.000000},
63 {"Pacific/Gambier", 10.000000},
64 {"EET", 10.000000},
65 {"MST", 10.000000},
66 {"Europe/Dublin", 10.000000},
67 {"Europe/Minsk", 10.000000},
68 {"Europe/Budapest", 10.000000},
69 {"Europe/Riga", 10.000000},
70 {"Europe/Jersey", 10.000000},
71 {"Europe/London", 10.000000},
72 {"Europe/Istanbul", 10.000000},
73 {"Europe/Moscow", 10.000000},
74 {"Europe/Chisinau", 10.000000},
75 {"Europe/Andorra", 10.000000},
76 {"Europe/Vaduz", 10.000000},
77 {"Europe/Zaporozhye", 10.000000},
78 {"Europe/San_Marino", 10.000000},
79 {"Europe/Monaco", 10.000000},
80 {"Europe/Ulyanovsk", 10.000000},
81 {"Europe/Isle_of_Man", 10.000000},
82 {"Europe/Tirane", 10.000000},
83 {"Europe/Vatican", 10.000000},
84 {"Europe/Belgrade", 10.000000},
85 {"Europe/Paris", 10.000000},
86 {"Europe/Nicosia", 10.000000},
87 {"Europe/Athens", 10.000000},
88 {"Europe/Malta", 10.000000},
89 {"Europe/Astrakhan", 10.000000},
90 {"Europe/Bratislava", 10.000000},
91 {"Europe/Uzhgorod", 10.000000},
92 {"Europe/Zurich", 10.000000},
93 {"Europe/Brussels", 10.000000},
94 {"Europe/Sofia", 10.000000},
95 {"Europe/Kiev", 10.000000},
96 {"Europe/Guernsey", 10.000000},
97 {"Europe/Busingen", 10.000000},
98 {"Europe/Copenhagen", 10.000000},
99 {"Europe/Skopje", 10.000000},
100 {"Europe/Luxembourg", 10.000000},
101 {"Europe/Lisbon", 10.000000},
102 {"Europe/Saratov", 10.000000},
103 {"Europe/Zagreb", 10.000000},
104 {"Europe/Simferopol", 10.000000},
105 {"Europe/Amsterdam", 10.000000},
106 {"Europe/Oslo", 10.000000},
107 {"Europe/Samara", 10.000000},
108 {"Europe/Warsaw", 10.000000},
109 {"Europe/Prague", 10.000000},
110 {"Europe/Vienna", 10.000000},
111 {"Europe/Mariehamn", 10.000000},
112 {"Europe/Gibraltar", 10.000000},
113 {"Europe/Stockholm", 10.000000},
114 {"Europe/Tallinn", 10.000000},
115 {"Europe/Kaliningrad", 10.000000},
116 {"Europe/Podgorica", 10.000000},
117 {"Europe/Kirov", 10.000000},
118 {"Europe/Helsinki", 10.000000},
119 {"Europe/Sarajevo", 10.000000},
120 {"Europe/Rome", 10.000000},
121 {"Europe/Bucharest", 10.000000},
122 {"Europe/Berlin", 10.000000},
123 {"Europe/Volgograd", 10.000000},
124 {"Europe/Ljubljana", 10.000000},
125 {"Europe/Vilnius", 10.000000},
126 {"Europe/Madrid", 10.000000},
127 {"Antarctica/Casey", 10.000000},
128 {"Antarctica/Macquarie", 10.000000},
129 {"Antarctica/Rothera", 10.000000},
130 {"Antarctica/Vostok", 10.000000},
131 {"Antarctica/Davis", 10.000000},
132 {"Antarctica/Troll", 10.000000},
133 {"Antarctica/Mawson", 10.000000},
134 {"Antarctica/McMurdo", 10.000000},
135 {"Antarctica/DumontDUrville", 10.000000},
136 {"Antarctica/Palmer", 10.000000},
137 {"Antarctica/Syowa", 10.000000},
138 {"WET", 10.000000},
139 {"CST6CDT", 10.000000},
140 {"MET", 10.000000},
141 {"Arctic/Longyearbyen", 10.000000},
142 {"Atlantic/Faroe", 10.000000},
143 {"Atlantic/Madeira", 10.000000},
144 {"Atlantic/Canary", 10.000000},
145 {"Atlantic/Reykjavik", 10.000000},
146 {"Atlantic/St_Helena", 10.000000},
147 {"Atlantic/South_Georgia", 10.000000},
148 {"Atlantic/Azores", 10.000000},
149 {"Atlantic/Bermuda", 10.000000},
150 {"Atlantic/Stanley", 10.000000},
151 {"Atlantic/Cape_Verde", 10.000000},
152 {"Africa/Niamey", 10.000000},
153 {"Africa/Algiers", 10.000000},
154 {"Africa/Maputo", 10.000000},
155 {"Africa/Johannesburg", 10.000000},
156 {"Africa/Addis_Ababa", 10.000000},
157 {"Africa/Malabo", 10.000000},
158 {"Africa/Cairo", 10.000000},
159 {"Africa/Bissau", 10.000000},
160 {"Africa/Ndjamena", 10.000000},
161 {"Africa/Tunis", 10.000000},
162 {"Africa/Harare", 10.000000},
163 {"Africa/El_Aaiun", 10.000000},
164 {"Africa/Kampala", 10.000000},
165 {"Africa/Libreville", 10.000000},
166 {"Africa/Blantyre", 10.000000},
167 {"Africa/Brazzaville", 10.000000},
168 {"Africa/Bangui", 10.000000},
169 {"Africa/Luanda", 10.000000},
170 {"Africa/Freetown", 10.000000},
171 {"Africa/Casablanca", 10.000000},
172 {"Africa/Conakry", 10.000000},
173 {"Africa/Kinshasa", 10.000000},
174 {"Africa/Dakar", 10.000000},
175 {"Africa/Ouagadougou", 10.000000},
176 {"Africa/Nouakchott", 10.000000},
177 {"Africa/Monrovia", 10.000000},
178 {"Africa/Kigali", 10.000000},
179 {"Africa/Windhoek", 10.000000},
180 {"Africa/Juba", 10.000000},
181 {"Africa/Sao_Tome", 10.000000},
182 {"Africa/Banjul", 10.000000},
183 {"Africa/Mbabane", 10.000000},
184 {"Africa/Asmara", 10.000000},
185 {"Africa/Djibouti", 10.000000},
186 {"Africa/Tripoli", 10.000000},
187 {"Africa/Ceuta", 10.000000},
188 {"Africa/Khartoum", 10.000000},
189 {"Africa/Bamako", 10.000000},
190 {"Africa/Porto-Novo", 10.000000},
191 {"Africa/Mogadishu", 10.000000},
192 {"Africa/Abidjan", 10.000000},
193 {"Africa/Lusaka", 10.000000},
194 {"Africa/Lagos", 10.000000},
195 {"Africa/Lubumbashi", 10.000000},
196 {"Africa/Nairobi", 10.000000},
197 {"Africa/Accra", 10.000000},
198 {"Africa/Maseru", 10.000000},
199 {"Africa/Lome", 10.000000},
200 {"Africa/Douala", 10.000000},
201 {"Africa/Bujumbura", 10.000000},
202 {"Africa/Dar_es_Salaam", 10.000000},
203 {"Africa/Gaborone", 10.000000},
204 {"Australia/Adelaide", 10.000000},
205 {"Australia/Broken_Hill", 10.000000},
206 {"Australia/Perth", 10.000000},
207 {"Australia/Darwin", 10.000000},
208 {"Australia/Lord_Howe", 10.000000},
209 {"Australia/Hobart", 10.000000},
210 {"Australia/Brisbane", 10.000000},
211 {"Australia/Sydney", 10.000000},
212 {"Australia/Lindeman", 10.000000},
213 {"Australia/Melbourne", 10.000000},
214 {"Australia/Eucla", 10.000000},
215 {"America/Grand_Turk", 10.000000},
216 {"America/St_Thomas", 10.000000},
217 {"America/Havana", 10.000000},
218 {"America/Thunder_Bay", 10.000000},
219 {"America/Inuvik", 10.000000},
220 {"America/Winnipeg", 10.000000},
221 {"America/Maceio", 10.000000},
222 {"America/Chihuahua", 10.000000},
223 {"America/North_Dakota/Beulah", 10.000000},
224 {"America/North_Dakota/Center", 10.000000},
225 {"America/North_Dakota/New_Salem", 10.000000},
226 {"America/Campo_Grande", 10.000000},
227 {"America/Scoresbysund", 10.000000},
228 {"America/Tijuana", 10.000000},
229 {"America/Bahia", 10.000000},
230 {"America/St_Vincent", 10.000000},
231 {"America/Creston", 10.000000},
232 {"America/Dawson", 10.000000},
233 {"America/Tegucigalpa", 10.000000},
234 {"America/Lima", 10.000000},
235 {"America/Mexico_City", 10.000000},
236 {"America/Dominica", 10.000000},
237 {"America/Atikokan", 10.000000},
238 {"America/Port-au-Prince", 10.000000},
239 {"America/Yakutat", 10.000000},
240 {"America/St_Kitts", 10.000000},
241 {"America/Guatemala", 10.000000},
242 {"America/St_Barthelemy", 10.000000},
243 {"America/Vancouver", 10.000000},
244 {"America/Jamaica", 10.000000},
245 {"America/Whitehorse", 10.000000},
246 {"America/Asuncion", 10.000000},
247 {"America/Toronto", 10.000000},
248 {"America/Hermosillo", 10.000000},
249 {"America/Denver", 10.000000},
250 {"America/Mazatlan", 10.000000},
251 {"America/Iqaluit", 10.000000},
252 {"America/Nuuk", 10.000000},
253 {"America/Cayenne", 10.000000},
254 {"America/Santarem", 10.000000},
255 {"America/Noronha", 10.000000},
256 {"America/Ojinaga", 10.000000},
257 {"America/Fort_Nelson", 10.000000},
258 {"America/Aruba", 10.000000},
259 {"America/Indiana/Vevay", 10.000000},
260 {"America/Indiana/Marengo", 10.000000},
261 {"America/Indiana/Indianapolis", 10.000000},
262 {"America/Indiana/Tell_City", 10.000000},
263 {"America/Indiana/Petersburg", 10.000000},
264 {"America/Indiana/Winamac", 10.000000},
265 {"America/Indiana/Knox", 10.000000},
266 {"America/Indiana/Vincennes", 10.000000},
267 {"America/Cayman", 10.000000},
268 {"America/Sao_Paulo", 10.000000},
269 {"America/Curacao", 10.000000},
270 {"America/Anchorage", 10.000000},
271 {"America/Guyana", 10.000000},
272 {"America/Rankin_Inlet", 10.000000},
273 {"America/Antigua", 10.000000},
274 {"America/Juneau", 10.000000},
275 {"America/Merida", 10.000000},
276 {"America/Punta_Arenas", 10.000000},
277 {"America/Moncton", 10.000000},
278 {"America/Fortaleza", 10.000000},
279 {"America/Resolute", 10.000000},
280 {"America/Nassau", 10.000000},
281 {"America/Edmonton", 10.000000},
282 {"America/Regina", 10.000000},
283 {"America/Halifax", 10.000000},
284 {"America/Danmarkshavn", 10.000000},
285 {"America/Metlakatla", 10.000000},
286 {"America/Guadeloupe", 10.000000},
287 {"America/Caracas", 10.000000},
288 {"America/Detroit", 10.000000},
289 {"America/Matamoros", 10.000000},
290 {"America/Glace_Bay", 10.000000},
291 {"America/Phoenix", 10.000000},
292 {"America/La_Paz", 10.000000},
293 {"America/Swift_Current", 10.000000},
294 {"America/Nipigon", 10.000000},
295 {"America/Cancun", 10.000000},
296 {"America/Port_of_Spain", 10.000000},
297 {"America/Kralendijk", 10.000000},
298 {"America/Grenada", 10.000000},
299 {"America/Belem", 10.000000},
300 {"America/Managua", 10.000000},
301 {"America/Adak", 10.000000},
302 {"America/St_Lucia", 10.000000},
303 {"America/Rio_Branco", 10.000000},
304 {"America/Santiago", 10.000000},
305 {"America/Puerto_Rico", 10.000000},
306 {"America/Miquelon", 10.000000},
307 {"America/Cuiaba", 10.000000},
308 {"America/Martinique", 10.000000},
309 {"America/Argentina/Buenos_Aires", 10.000000},
310 {"America/Argentina/San_Luis", 10.000000},
311 {"America/Argentina/Catamarca", 10.000000},
312 {"America/Argentina/Jujuy", 10.000000},
313 {"America/Argentina/Salta", 10.000000},
314 {"America/Argentina/Ushuaia", 10.000000},
315 {"America/Argentina/Mendoza", 10.000000},
316 {"America/Argentina/Rio_Gallegos", 10.000000},
317 {"America/Argentina/Tucuman", 10.000000},
318 {"America/Argentina/San_Juan", 10.000000},
319 {"America/Argentina/Cordoba", 10.000000},
320 {"America/Argentina/La_Rioja", 10.000000},
321 {"America/Barbados", 10.000000},
322 {"America/Monterrey", 10.000000},
323 {"America/Thule", 10.000000},
324 {"America/Montserrat", 10.000000},
325 {"America/Guayaquil", 10.000000},
326 {"America/St_Johns", 10.000000},
327 {"America/Boise", 10.000000},
328 {"America/Manaus", 10.000000},
329 {"America/Nome", 10.000000},
330 {"America/Goose_Bay", 10.000000},
331 {"America/Belize", 10.000000},
332 {"America/Sitka", 10.000000},
333 {"America/Dawson_Creek", 10.000000},
334 {"America/Recife", 10.000000},
335 {"America/Kentucky/Louisville", 10.000000},
336 {"America/Kentucky/Monticello", 10.000000},
337 {"America/New_York", 10.000000},
338 {"America/Tortola", 10.000000},
339 {"America/Chicago", 10.000000},
340 {"America/Pangnirtung", 10.000000},
341 {"America/Boa_Vista", 10.000000},
342 {"America/Bogota", 10.000000},
343 {"America/Rainy_River", 10.000000},
344 {"America/El_Salvador", 10.000000},
345 {"America/Bahia_Banderas", 10.000000},
346 {"America/Yellowknife", 10.000000},
347 {"America/Montevideo", 10.000000},
348 {"America/Cambridge_Bay", 10.000000},
349 {"America/Panama", 10.000000},
350 {"America/Santo_Domingo", 10.000000},
351 {"America/Anguilla", 10.000000},
352 {"America/Paramaribo", 10.000000},
353 {"America/Marigot", 10.000000},
354 {"America/Menominee", 10.000000},
355 {"America/Blanc-Sablon", 10.000000},
356 {"America/Costa_Rica", 10.000000},
357 {"America/Los_Angeles", 10.000000},
358 {"America/Lower_Princes", 10.000000},
359 {"America/Eirunepe", 10.000000},
360 {"America/Araguaina", 10.000000},
361 {"America/Porto_Velho", 10.000000},
362 {"EST", 10.000000},
363 {"CET", 10.000000},
364 {"MST7MDT", 10.000000},
365 {"Indian/Chagos", 10.000000},
366 {"Indian/Kerguelen", 10.000000},
367 {"Indian/Reunion", 10.000000},
368 {"Indian/Antananarivo", 10.000000},
369 {"Indian/Cocos", 10.000000},
370 {"Indian/Mauritius", 10.000000},
371 {"Indian/Christmas", 10.000000},
372 {"Indian/Maldives", 10.000000},
373 {"Indian/Comoro", 10.000000},
374 {"Indian/Mahe", 10.000000},
375 {"Indian/Mayotte", 10.000000},
376 {"Asia/Novokuznetsk", 10.000000},
377 {"Asia/Magadan", 10.000000},
378 {"Asia/Yangon", 10.000000},
379 {"Asia/Samarkand", 10.000000},
380 {"Asia/Tehran", 10.000000},
381 {"Asia/Dili", 10.000000},
382 {"Asia/Yerevan", 10.000000},
383 {"Asia/Qatar", 10.000000},
384 {"Asia/Chita", 10.000000},
385 {"Asia/Makassar", 10.000000},
386 {"Asia/Hovd", 10.000000},
387 {"Asia/Istanbul", 10.000000},
388 {"Asia/Irkutsk", 10.000000},
389 {"Asia/Pontianak", 10.000000},
390 {"Asia/Qyzylorda", 10.000000},
391 {"Asia/Srednekolymsk", 10.000000},
392 {"Asia/Aden", 10.000000},
393 {"Asia/Kabul", 10.000000},
394 {"Asia/Macau", 10.000000},
395 {"Asia/Riyadh", 10.000000},
396 {"Asia/Taipei", 10.000000},
397 {"Asia/Manila", 10.000000},
398 {"Asia/Aqtau", 10.000000},
399 {"Asia/Thimphu", 10.000000},
400 {"Asia/Shanghai", 10.000000},
401 {"Asia/Choibalsan", 10.000000},
402 {"Asia/Nicosia", 10.000000},
403 {"Asia/Dubai", 10.000000},
404 {"Asia/Baku", 10.000000},
405 {"Asia/Kuching", 10.000000},
406 {"Asia/Gaza", 10.000000},
407 {"Asia/Jayapura", 10.000000},
408 {"Asia/Tokyo", 10.000000},
409 {"Asia/Muscat", 10.000000},
410 {"Asia/Kolkata", 10.000000},
411 {"Asia/Ho_Chi_Minh", 10.000000},
412 {"Asia/Tashkent", 10.000000},
413 {"Asia/Bangkok", 10.000000},
414 {"Asia/Karachi", 10.000000},
415 {"Asia/Krasnoyarsk", 10.000000},
416 {"Asia/Yekaterinburg", 10.000000},
417 {"Asia/Famagusta", 10.000000},
418 {"Asia/Ulaanbaatar", 10.000000},
419 {"Asia/Bahrain", 10.000000},
420 {"Asia/Barnaul", 10.000000},
421 {"Asia/Jerusalem", 10.000000},
422 {"Asia/Qostanay", 10.000000},
423 {"Asia/Ust-Nera", 10.000000},
424 {"Asia/Tomsk", 10.000000},
425 {"Asia/Kuala_Lumpur", 10.000000},
426 {"Asia/Brunei", 10.000000},
427 {"Asia/Aqtobe", 10.000000},
428 {"Asia/Vladivostok", 10.000000},
429 {"Asia/Damascus", 10.000000},
430 {"Asia/Omsk", 10.000000},
431 {"Asia/Almaty", 10.000000},
432 {"Asia/Dhaka", 10.000000},
433 {"Asia/Tbilisi", 10.000000},
434 {"Asia/Baghdad", 10.000000},
435 {"Asia/Phnom_Penh", 10.000000},
436 {"Asia/Kamchatka", 10.000000},
437 {"Asia/Ashgabat", 10.000000},
438 {"Asia/Sakhalin", 10.000000},
439 {"Asia/Novosibirsk", 10.000000},
440 {"Asia/Kuwait", 10.000000},
441 {"Asia/Hong_Kong", 10.000000},
442 {"Asia/Amman", 10.000000},
443 {"Asia/Beirut", 10.000000},
444 {"Asia/Yakutsk", 10.000000},
445 {"Asia/Colombo", 10.000000},
446 {"Asia/Oral", 10.000000},
447 {"Asia/Kathmandu", 10.000000},
448 {"Asia/Bishkek", 10.000000},
449 {"Asia/Hebron", 10.000000},
450 {"Asia/Singapore", 10.000000},
451 {"Asia/Atyrau", 10.000000},
452 {"Asia/Khandyga", 10.000000},
453 {"Asia/Vientiane", 10.000000},
454 {"Asia/Jakarta", 10.000000},
455 {"Asia/Dushanbe", 10.000000},
456 {"Asia/Seoul", 10.000000},
457 {"Asia/Pyongyang", 10.000000},
458 {"Asia/Urumqi", 10.000000},
459 {"Asia/Anadyr", 10.000000},
460 {"PST8PDT", 10.000000},
461 {"HST", 10.000000},
462 {"EST5EDT", 10.000000},
463 };
464
465 /**
466 * @tc.name : difftime_0100
467 * @tc.desc : according to different time zones, calculate the time difference between two moments
468 * @tc.level : Level 0
469 */
difftime_0100(void)470 void difftime_0100(void)
471 {
472 time_t timeStart = 20000;
473 time_t timeEnd = 20010;
474 for (int32_t i = 0; i < (int32_t)(sizeof(gResultData) / sizeof(gResultData[0])); i++) {
475 const char *tz = gResultData[i].tz;
476 const char *handlerChar;
477 #ifdef TIME_ZONE_SUB_TAG
478 char *str = strrchr(tz, TIME_ZONE_SUB_TAG);
479 if (str) {
480 handlerChar = ++str;
481 } else {
482 handlerChar = tz;
483 }
484 #else
485 handlerChar = tz;
486 #endif
487 setenv("TZ", handlerChar, 1);
488 tzset();
489 double returnVal;
490 returnVal = difftime(timeEnd, timeStart);
491 EXPECT_TRUE(
492 "difftime_0100", abs(gResultData[i].result - returnVal) >= 0 && abs(gResultData[i].result - returnVal) < 1);
493 }
494 }
495
main(void)496 int main(void)
497 {
498 difftime_0100();
499 return t_status;
500 }