2 * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
4 * $Id: toLocalTime.c,v 1.3 1998/12/02 13:28:02 simonm Exp $
6 * toCalendarTime Runtime Support
14 toLocalTime(I_ size, StgByteArray d, StgByteArray res)
16 struct tm *tm,*tmp=(struct tm *)res;
26 t = - (time_t) ((StgInt *)d)[0];
31 t = (time_t) ((StgInt *)d)[0];
42 localtime() may return a ptr to statically allocated storage,
43 so to make toLocalTime reentrant, we manually copy
44 the structure into the (struct tm *) passed in.
46 tmp->tm_sec = tm->tm_sec;
47 tmp->tm_min = tm->tm_min;
48 tmp->tm_hour = tm->tm_hour;
49 tmp->tm_mday = tm->tm_mday;
50 tmp->tm_mon = tm->tm_mon;
51 tmp->tm_year = tm->tm_year;
52 tmp->tm_wday = tm->tm_wday;
53 tmp->tm_yday = tm->tm_yday;
54 tmp->tm_isdst = tm->tm_isdst;
56 If you don't have tm_zone in (struct tm), but
57 you get at it via the shared tmzone[], you'll
58 lose. Same goes for the tm_gmtoff field.
62 strcpy(tmp->tm_zone,tm->tm_zone);
63 tmp->tm_gmtoff = tm->tm_gmtoff;
69 /* Note that we DO NOT return res as a result.
70 * res is typically a MutableByteArray and it seems very dubious
71 * to return a pointer into the middle of it.
73 StgInt prim_toLocalTime ( StgInt64 d, StgByteArray res)
75 struct tm *tm,*tmp=(struct tm *)res;
76 time_t t = (time_t) d;
87 localtime() may return a ptr to statically allocated storage,
88 so to make toLocalTime reentrant, we manually copy
89 the structure into the (struct tm *) passed in.
91 tmp->tm_sec = tm->tm_sec;
92 tmp->tm_min = tm->tm_min;
93 tmp->tm_hour = tm->tm_hour;
94 tmp->tm_mday = tm->tm_mday;
95 tmp->tm_mon = tm->tm_mon;
96 tmp->tm_year = tm->tm_year;
97 tmp->tm_wday = tm->tm_wday;
98 tmp->tm_yday = tm->tm_yday;
99 tmp->tm_isdst = tm->tm_isdst;
101 If you don't have tm_zone in (struct tm), but
102 you get at it via the shared tmzone[], you'll
103 lose. Same goes for the tm_gmtoff field.
107 strcpy(tmp->tm_zone,tm->tm_zone);
108 tmp->tm_gmtoff = tm->tm_gmtoff;