gmtime.c 1.2 KB

12345678910111213141516171819202122232425262728
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int main(void) {
  6. time_t a = 0;
  7. struct tm expected = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 1, .tm_year = 70,
  8. .tm_wday = 4, .tm_yday = 0, .tm_isdst = 0, .tm_gmtoff = 0, .tm_zone = "UTC" };
  9. struct tm *info = gmtime(&a);
  10. if (info->tm_sec != expected.tm_sec || info->tm_min != expected.tm_min ||
  11. info->tm_hour != expected.tm_hour || info->tm_mday != expected.tm_mday ||
  12. info->tm_year != expected.tm_year || info->tm_wday != expected.tm_wday ||
  13. info->tm_yday != expected.tm_yday || info->tm_isdst != expected.tm_isdst ||
  14. info->tm_gmtoff != expected.tm_gmtoff || strcmp(info->tm_zone, expected.tm_zone) != 0) {
  15. exit(1);
  16. }
  17. if (info->tm_sec != expected.tm_sec || info->tm_min != expected.tm_min ||
  18. info->tm_hour != expected.tm_hour || info->tm_mday != expected.tm_mday ||
  19. info->tm_year != expected.tm_year || info->tm_wday != expected.tm_wday ||
  20. info->tm_yday != expected.tm_yday || info->tm_isdst != expected.tm_isdst ||
  21. info->tm_gmtoff != expected.tm_gmtoff || strcmp(info->tm_zone, expected.tm_zone) != 0) {
  22. exit(1);
  23. }
  24. return 0;
  25. }