| 1 | /* Check that daylight is set if the last DST transition did not change offset. |
| 2 | Copyright (C) 2023-2024 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <errno.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <support/check.h> |
| 22 | #include <time.h> |
| 23 | |
| 24 | /* Set the specified time zone with error checking. */ |
| 25 | static void |
| 26 | set_timezone (const char *name) |
| 27 | { |
| 28 | TEST_VERIFY (setenv ("TZ" , name, 1) == 0); |
| 29 | errno = 0; |
| 30 | tzset (); |
| 31 | TEST_COMPARE (errno, 0); |
| 32 | } |
| 33 | |
| 34 | static int |
| 35 | do_test (void) |
| 36 | { |
| 37 | /* Test zone based on tz-2022g version of Africa/Tripoli. The last |
| 38 | DST transition coincided with a change in the standard time |
| 39 | offset, effectively making it a no-op. |
| 40 | |
| 41 | Africa/Tripoli Thu Oct 24 23:59:59 2013 UT |
| 42 | = Fri Oct 25 01:59:59 2013 CEST isdst=1 gmtoff=7200 |
| 43 | Africa/Tripoli Fri Oct 25 00:00:00 2013 UT |
| 44 | = Fri Oct 25 02:00:00 2013 EET isdst=0 gmtoff=7200 |
| 45 | */ |
| 46 | set_timezone ("XT6" ); |
| 47 | TEST_VERIFY (daylight != 0); |
| 48 | TEST_COMPARE (timezone, -7200); |
| 49 | |
| 50 | /* Check that localtime re-initializes the two variables. */ |
| 51 | daylight = timezone = 17; |
| 52 | time_t t = 844034401; |
| 53 | struct tm *tm = localtime (timer: &t); |
| 54 | TEST_VERIFY (daylight != 0); |
| 55 | TEST_COMPARE (timezone, -7200); |
| 56 | TEST_COMPARE (tm->tm_year, 96); |
| 57 | TEST_COMPARE (tm->tm_mon, 8); |
| 58 | TEST_COMPARE (tm->tm_mday, 29); |
| 59 | TEST_COMPARE (tm->tm_hour, 23); |
| 60 | TEST_COMPARE (tm->tm_min, 0); |
| 61 | TEST_COMPARE (tm->tm_sec, 1); |
| 62 | TEST_COMPARE (tm->tm_gmtoff, 3600); |
| 63 | TEST_COMPARE (tm->tm_isdst, 0); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | #include <support/test-driver.c> |
| 69 | |