0.9.13.47: Thread safety miscellania
[sbcl.git] / src / runtime / time.c
1 /*
2  * time support routines that are easier to do in C than in Lisp
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
9  * This software is derived from the CMU CL system, which was
10  * written at Carnegie Mellon University and released into the
11  * public domain. The software is in the public domain and is
12  * provided with absolutely no warranty. See the COPYING and CREDITS
13  * files for more information.
14  */
15
16 #include <stdio.h>
17 #include <time.h>
18 #include "sbcl.h"
19 #include "runtime.h"
20
21 void get_timezone(time_t when, int *secwest, boolean *dst)
22 {
23     struct tm ltm, gtm;
24     int sw;
25
26     ltm = *localtime_r(&when, &ltm);
27     gtm = *gmtime_r(&when, &gtm);
28
29     sw = (((gtm.tm_hour*60)+gtm.tm_min)*60+gtm.tm_sec) - (((ltm.tm_hour*60)+ltm.tm_min)*60+ltm.tm_sec);
30     if ((gtm.tm_wday + 1) % 7 == ltm.tm_wday)
31         sw -= 24*3600;
32     else if (gtm.tm_wday == (ltm.tm_wday + 1) % 7)
33         sw += 24*3600;
34     *secwest = sw;
35     *dst = ltm.tm_isdst;
36 }