X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Ftest-mktime.cxx;h=6c6734d5133978b406c07aff2be597c08c656a51;hb=8777663fc083411346346df58b2d42720fd9954e;hp=7602d17424d4c25548ca9d96a4fbe5175be6416a;hpb=c90db01dc8d5462a3da22771ffa7c96f5ea31217;p=flightgear.git diff --git a/tests/test-mktime.cxx b/tests/test-mktime.cxx index 7602d1742..6c6734d51 100644 --- a/tests/test-mktime.cxx +++ b/tests/test-mktime.cxx @@ -22,6 +22,13 @@ #define LST_MAGIC_TIME_1998 890481600 +// For now we assume that if daylight is not defined in +// /usr/include/time.h that we have a machine with a BSD behaving +// mktime() +#if !defined(HAVE_DAYLIGHT) +# define MK_TIME_IS_GMT 1 +#endif + // Fix up timezone if using ftime() long int fix_up_timezone( long int timezone_orig ) { @@ -53,18 +60,6 @@ long int fix_up_timezone( long int timezone_orig ) { time_t get_start_gmt(int year) { struct tm mt; - // For now we assume that if daylight is not defined in - // /usr/include/time.h that we have a machine with a BSD behaving - // mktime() -# if !defined(HAVE_DAYLIGHT) -# define MK_TIME_IS_GMT 1 -# endif - - // timezone seems to work as a proper offset for Linux & Solaris -# if defined( __linux__ ) || defined( __sun__ ) -# define TIMEZONE_OFFSET_WORKS 1 -# endif - mt.tm_mon = 2; mt.tm_mday = 21; mt.tm_year = year; @@ -73,22 +68,35 @@ time_t get_start_gmt(int year) { mt.tm_sec = 0; mt.tm_isdst = -1; // let the system determine the proper time zone -# if defined( MK_TIME_IS_GMT ) +#if defined( HAVE_TIMEGM ) + return ( timegm(&mt) ); +#elif defined( MK_TIME_IS_GMT ) return ( mktime(&mt) ); -# else // ! defined ( MK_TIME_IS_GMT ) +#else // ! defined ( MK_TIME_IS_GMT ) - long int start = mktime(&mt); + // timezone seems to work as a proper offset for Linux & Solaris +# if defined( __linux__ ) || defined( __sun__ ) || defined( __CYGWIN__ ) +# define TIMEZONE_OFFSET_WORKS 1 +# endif + +#if defined(__CYGWIN__) +#define TIMEZONE _timezone +#else +#define TIMEZONE timezone +#endif + + time_t start = mktime(&mt); printf("start1 = %ld\n", start); printf("start2 = %s", ctime(&start)); printf("(tm_isdst = %d)\n", mt.tm_isdst); - timezone = fix_up_timezone( timezone ); - -# if defined( TIMEZONE_OFFSET_WORKS ) - printf("start = %ld, timezone = %ld\n", start, timezone); - return( start - timezone ); -# else // ! defined( TIMEZONE_OFFSET_WORKS ) + TIMEZONE = fix_up_timezone( TIMEZONE ); + +# if defined( TIMEZONE_OFFSET_WORKS ) + printf("start = %ld, timezone = %ld\n", start, TIMEZONE); + return( start - TIMEZONE ); +# else // ! defined( TIMEZONE_OFFSET_WORKS ) daylight = mt.tm_isdst; if ( daylight > 0 ) { @@ -97,19 +105,19 @@ time_t get_start_gmt(int year) { printf("OOOPS, problem in fg_time.cxx, no daylight savings info.\n"); } - long int offset = -(timezone / 3600 - daylight); + long int offset = -(TIMEZONE / 3600 - daylight); - printf(" Raw time zone offset = %ld\n", timezone); + printf(" Raw time zone offset = %ld\n", TIMEZONE); printf(" Daylight Savings = %d\n", daylight); printf(" Local hours from GMT = %ld\n", offset); - long int start_gmt = start - timezone + (daylight * 3600); + long int start_gmt = start - TIMEZONE + (daylight * 3600); printf(" March 21 noon (CST) = %ld\n", start); return ( start_gmt ); -# endif // ! defined( TIMEZONE_OFFSET_WORKS ) -# endif // ! defined ( MK_TIME_IS_GMT ) +# endif // ! defined( TIMEZONE_OFFSET_WORKS ) +#endif // ! defined ( MK_TIME_IS_GMT ) } @@ -120,13 +128,19 @@ int main() { if ( start_gmt == LST_MAGIC_TIME_1998 ) { -#ifdef MK_TIME_IS_GMT - printf("mktime() assumes GMT on your system, lucky you!\n"); + printf("Time test = PASSED\n\n"); +#ifdef HAVE_TIMEGM + printf("You have timegm() which is just like mktime() except that\n"); + printf("it explicitely expects input in GMT ... lucky you!\n"); +#elif MK_TIME_IS_GMT + printf("You don't seem to have timegm(), but mktime() seems to\n"); + printf("assume input is GMT on your system ... I guess that works\n"); #else printf("mktime() assumes local time zone on your system, but we can\n"); printf("compensate just fine.\n"); #endif } else { + printf("Time test = FAILED\n\n"); printf("There is likely a problem with mktime() on your system.\n"); printf("This will cause the sun/moon/stars/planets to be in the\n"); printf("wrong place in the sky and the rendered time of day will be\n");