#include #include #include #define PRINT int main(void) { struct tm tm, *stm; time_t res; putenv("TZ=UTC"); tm.tm_sec = tm.tm_min = 0; tm.tm_hour = 12; tm.tm_mday = 1; tm.tm_mon = 0; tm.tm_year = 120; tm.tm_isdst = 0; // test 2020-01-01 res = mktime(&tm); #ifdef PRINT printf("day %ld\n", res); #else if(res != 1577880000L) exit(1); #endif // and can we go back to POSIXlt? #ifdef HAVE_GMTIME_R stm = gmtime_r(&res, &tm); #else stm = gmtime(&res); #endif #ifdef PRINT printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+stm->tm_year, 1+stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec); #else if(stm->tm_year != 120 || stm->tm_mon != 0 || stm->tm_mday != 1 || stm->tm_hour != 12 || stm-> tm_isdst != 0) exit(10); #endif tm.tm_mon = 6; tm.tm_isdst = 0; // test 2020-07-01 res = mktime(&tm); #ifdef PRINT printf("res %ld\n", res); #else if(res != 1593604800L) exit(2); #endif #ifdef HAVE_GMTIME_R stm = gmtime_r(&res, &tm); #else stm = gmtime(&res); #endif #ifdef PRINT printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+stm->tm_year, 1+stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec); #else if(stm->tm_year != 120 || stm->tm_mon != 6 || stm->tm_mday != 1 || stm->tm_hour != 12 || stm-> tm_isdst != 0) exit(20); #endif putenv("TZ=Europe/London"); tm.tm_sec = tm.tm_min = 0; tm.tm_hour = 12; tm.tm_mday = 1; tm.tm_mon = 0; tm.tm_year = 120; tm.tm_isdst = -1; // test 2020-01-01, whoch is assumed to be in GMT res = mktime(&tm); #ifdef PRINT printf("res %ld\n", res); #else if(res != 1577880000L) exit(3); #endif #ifdef HAVE_LOCALTIME_R stm = localtime_r(&res, &tm); #else stm = localtime(&res); #endif #ifdef PRINT printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+stm->tm_year, 1+stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec); #else if(stm->tm_year != 120 || stm->tm_mon != 0 || stm->tm_mday != 1 || stm->tm_hour != 12 || stm-> tm_isdst != 0) exit(30); #endif tm.tm_mon = 6; tm.tm_isdst = -1; // test 2020-07-01 which is assumed to be in BST res = mktime(&tm); #ifdef PRINT printf("res %ld\n", res); #else if(res != 1593601200L) exit(4); #endif #ifdef HAVE_LOCALTIME_R stm = localtime_r(&res, &tm); #else stm = localtime(&res); #endif #ifdef PRINT printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+stm->tm_year, 1+stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec); #else if(stm->tm_year != 120 || stm->tm_mon != 6 || stm->tm_mday != 1 || stm->tm_hour != 12 || stm-> tm_isdst != 1) exit(40); #endif putenv("TZ=Pacific/Auckland"); tm.tm_sec = tm.tm_min = 0; tm.tm_hour = 12; tm.tm_mday = 1; tm.tm_mon = 0; tm.tm_year = 120; tm.tm_isdst = -1; res = mktime(&tm); #ifdef PRINT printf("res %ld\n", res); #else if(res != 1577833200L) exit(5); #endif #ifdef HAVE_LOCALTIME_R stm = localtime_r(&res, &tm); #else stm = localtime(&res); #endif #ifdef PRINT printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+stm->tm_year, 1+stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec); #else if(stm->tm_year != 120 || stm->tm_mon != 0 || stm->tm_mday != 1 || stm->tm_hour != 12 || stm-> tm_isdst != 1) exit(50); #endif tm.tm_mon = 6; tm.tm_isdst = -1; res = mktime(&tm); #ifdef PRINT printf("res %ld\n", res); #else if(res != 1593561600L) exit(6); #endif #ifdef HAVE_LOCALTIME_R stm = localtime_r(&res, &tm); #else stm = localtime(&res); #endif #ifdef PRINT printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+stm->tm_year, 1+stm->tm_mon, stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec); #else if(stm->tm_year != 120 || stm->tm_mon != 6 || stm->tm_mday != 1 || stm->tm_hour != 12 || stm-> tm_isdst != 0) exit(60); #endif exit(0); }