tst-bz29951.c 2.2 KB

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