File: HsTime.c

package info (click to toggle)
ghc 9.6.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 158,216 kB
  • sloc: haskell: 648,228; ansic: 81,656; cpp: 11,808; javascript: 8,444; sh: 5,831; fortran: 3,527; python: 3,277; asm: 2,523; makefile: 2,298; yacc: 1,570; lisp: 532; xml: 196; perl: 145; csh: 2
file content (51 lines) | stat: -rw-r--r-- 1,584 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "HsTime.h"
#include <stdio.h>

long int get_current_timezone_seconds (time_t t,int* pdst,char const* * pname)
{
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
    // When compiling with MinGW (which does not provide a full POSIX
    // layer as opposed to Cygwin) it's better to use the CRT's
    // underscore-prefixed `_tzset()` variant to avoid linker issues
    // as Microsoft considers the POSIX named `tzset()` function
    // deprecated (see http://msdn.microsoft.com/en-us/library/ms235384.aspx)
    _tzset();
#else
    tzset();
#endif

#if HAVE_LOCALTIME_R
    struct tm tmd;
    struct tm* ptm = localtime_r(&t,&tmd);
#else
    struct tm* ptm = localtime(&t);
#endif
    if (ptm)
    {
        int dst = ptm -> tm_isdst;
        *pdst = dst;
#if HAVE_TM_ZONE
        *pname = ptm -> tm_zone;
        return ptm -> tm_gmtoff;
#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
        // We don't have a better API to use on Windows, the logic to
        // decide whether a given date/time falls within DST is
        // implemented as part of localtime() in the CRT.  This is_dst
        // flag is all we need here.
        *pname = dst ? _tzname[1] : _tzname[0];
        return - (dst ? _timezone - 3600 : _timezone);
#else
# if HAVE_TZNAME
        *pname = *tzname;
# else
#  error "Don't know how to get timezone name on your OS"
# endif
# if HAVE_DECL_ALTZONE
        return dst ? altzone : timezone;
# else
        return dst ? timezone - 3600 : timezone;
# endif
#endif // HAVE_TM_ZONE
    }
    else return 0x80000000;
}