File: HsTime.c

package info (click to toggle)
haskell-time 1.0-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 304 kB
  • ctags: 5
  • sloc: haskell: 796; makefile: 60; ansic: 49; sh: 22
file content (52 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download | duplicates (6)
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
52
#include "HsTime.h"
#include <stdio.h>

long int get_current_timezone_seconds (time_t t,int* pdst,char const* * pname)
{
	struct tm* ptm;
	long gmtoff;
	int dst;
	const char *name;

#if HAVE_LOCALTIME_R
	struct tm tmd;
	ptm = localtime_r(&t,&tmd);
#else
	ptm = localtime(&t);
#endif
	// We don't have a better API to use on Windows, the logic to
	// decide whether a given data/time falls within DST is
	// implemented as part of localtime() in the CRT.  This is_dst
	// flag is all we need here.

	if (ptm)
	{
	        dst = ptm -> tm_isdst;
#if HAVE_TM_ZONE
		name = ptm -> tm_zone;
		gmtoff = ptm -> tm_gmtoff;
#elif defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)
		name = dst ? _tzname[1] : _tzname[0];
		gmtoff = dst ? _timezone - 3600 : _timezone;
#else

# if HAVE_TZNAME
		name = *tzname;
# else
#  error "Don't know how to get at timezone name on your OS"
# endif

# if HAVE_DECL_ALTZONE
		gmtoff = dst ? altzone : timezone;
# else
		gmtoff = dst ? timezone - 3600 : timezone;
# endif

#endif // HAVE_TM_ZONE
	        *pdst  = dst;
		*pname = name;
		return gmtoff;

	}
	else return 0x80000000;
}