summaryrefslogtreecommitdiff
path: root/ghc/runtime/io/toLocalTime.lc
blob: 50a5a104c8012e4ba9ef354dfc6fd2e55dcca504 (plain)
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
%
% (c) The GRASP/AQUA Project, Glasgow University, 1995
%
\subsection[toLocalTime.lc]{toCalendarTime Runtime Support}

\begin{code}

#include "rtsdefs.h"
#include "stgio.h"
#include "timezone.h"

StgAddr 
toLocalTime(size, d)
StgInt size;
StgByteArray d;
{
    time_t t;
    struct tm *tm;
    static struct tm cache_tm;

    switch(size) {
	default:
	    return NULL;
	case 0:
	    t = 0;
	    break;
	case -1:
	    t = - (time_t) ((StgInt *)d)[0];
	    if (t > 0) 
		return NULL;
	    break;
	case 1:
	    t = (time_t) ((StgInt *)d)[0];
	    if (t < 0) 
		return NULL;
	    break;
	}
    tm = localtime(&t);
    
    if (tm == NULL)
	return NULL;

    cache_tm = *tm;
    return &cache_tm;
}

\end{code}