/cbits/HsTime.c
C | 40 lines | 35 code | 1 blank | 4 comment | 6 complexity | 5db3c72b5a6e65f00429d1ba5b095644 MD5 | raw file
Possible License(s): BSD-3-Clause
1#include "HsTime.h" 2#include <stdio.h> 3 4long int get_current_timezone_seconds (time_t t,int* pdst,char const* * pname) 5{ 6#if HAVE_LOCALTIME_R 7 struct tm tmd; 8 struct tm* ptm = localtime_r(&t,&tmd); 9#else 10 struct tm* ptm = localtime(&t); 11#endif 12 if (ptm) 13 { 14 int dst = ptm -> tm_isdst; 15 *pdst = dst; 16#if HAVE_TM_ZONE 17 *pname = ptm -> tm_zone; 18 return ptm -> tm_gmtoff; 19#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) 20 // We don't have a better API to use on Windows, the logic to 21 // decide whether a given date/time falls within DST is 22 // implemented as part of localtime() in the CRT. This is_dst 23 // flag is all we need here. 24 *pname = dst ? _tzname[1] : _tzname[0]; 25 return - (dst ? _timezone - 3600 : _timezone); 26#else 27# if HAVE_TZNAME 28 *pname = *tzname; 29# else 30# error "Don't know how to get timezone name on your OS" 31# endif 32# if HAVE_DECL_ALTZONE 33 return dst ? altzone : timezone; 34# else 35 return dst ? timezone - 3600 : timezone; 36# endif 37#endif // HAVE_TM_ZONE 38 } 39 else return 0x80000000; 40}