/cbits/HsTime.c

http://github.com/takano-akio/time · C · 40 lines · 35 code · 1 blank · 4 comment · 6 complexity · 5db3c72b5a6e65f00429d1ba5b095644 MD5 · raw file

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