summaryrefslogtreecommitdiff
path: root/lang/swi-prolog-lite/patches/patch-ak
blob: aead3650a5f8b9d5d3ef4796fc3941e5d8d508a3 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$NetBSD: patch-ak,v 1.1 2006/10/12 14:14:13 joerg Exp $

--- src/pl-tai.c.orig	2006-07-28 09:20:12.000000000 +0000
+++ src/pl-tai.c
@@ -38,11 +38,8 @@ long set by tzset().  Not really clean .
 
 #ifdef WIN32
 #define timezone _timezone
-#define daylight _daylight
 #else
 extern char *tzname[2];
-extern long timezone;
-extern int daylight;
 #endif
 
 
@@ -82,8 +79,21 @@ do_tzset()
 
 static int
 tz_offset()
-{ do_tzset();
-  return timezone;
+{
+  time_t now = time(NULL), t_gmt, t_local;
+  struct tm gmt, local;
+  int diff;
+
+  do_tzset();
+  gmtime_r(&now, &gmt);
+  t_gmt = mktime(&gmt);
+  localtime_r(&now, &local);
+  t_local = mktime(&local);
+  diff = t_local - t_gmt;
+  if (local.tm_isdst)
+    diff += 3600;
+
+  return diff;
 }
 
 
@@ -312,14 +322,12 @@ PRED_IMPL("stamp_date_time", 3, stamp_da
 	  ct.hour       = tm.tm_hour;
 	  ct.minute     = tm.tm_min;
 	  tzatom = tz_name_as_atom(tm.tm_isdst);
-	  if ( daylight )			/* from tzset() */
-	  { if ( tm.tm_isdst )
+	  if ( tm.tm_isdst )
 	    { utcoffset -= 3600;
 	      dstatom    = ATOM_true;
 	    } else
 	    { dstatom    = ATOM_false;
 	    }
-	  }
 	  done = TRUE;
 	}
       } else if ( alocal == ATOM_utc )
@@ -721,12 +729,10 @@ PRED_IMPL("format_time", 3, format_time,
     { localtime_r(&unixt, &tb.tm);
       tb.sec = (double)tb.tm.tm_sec + modf(tb.stamp, &ip);
       tb.utcoff = tz_offset();
-      if ( daylight )
-      { if ( tb.tm.tm_isdst )
+      if ( tb.tm.tm_isdst )
 	{ tb.utcoff -= 3600;
 	  tb.isdst = TRUE;
 	}
-      }
       tb.tzname = tz_name_as_atom(tb.tm.tm_isdst);
       tb.flags  = HAS_STAMP|HAS_WYDAY;
     } else