sam / do fork watch download tarball
public
Rubygem
Description: DataObjects
Homepage: http://rubyforge.org/projects/dorb
Clone URL: git://github.com/sam/do.git
do_postgres timezones are now fully functional
Mon Jun 09 09:58:30 -0700 2008
commit  ac6c48f690e957eb5526b955a1e500b3079729a3
tree    dc0d85bbc48907019d422e5780fd3fce240b6e0a
parent  d46ac0ba667af3a6d3298446fa26e22f58e4dfc1
...
3
4
5
 
6
7
8
...
121
122
123
 
 
 
124
125
126
...
145
146
147
148
 
149
150
151
152
153
154
155
 
156
157
158
159
160
161
162
 
 
 
 
 
 
 
 
 
 
 
 
 
163
164
165
...
3
4
5
6
7
8
9
...
122
123
124
125
126
127
128
129
130
...
149
150
151
 
152
153
154
155
 
 
 
 
156
157
 
 
 
 
 
 
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
0
@@ -3,6 +3,7 @@
0
 #include <string.h>
0
 #include <math.h>
0
 #include <time.h>
0
+#include <locale.h>
0
 #include <libpq-fe.h>
0
 #include "type-oids.h"
0
 
0
@@ -121,6 +122,9 @@ static VALUE parse_date_time(const char *date) {
0
   int jd;
0
   do_int64 num, den;
0
   
0
+    long int gmt_offset;
0
+    int is_dst;
0
+  
0
   time_t rawtime;
0
   struct tm * timeinfo;
0
 
0
@@ -145,21 +149,25 @@ static VALUE parse_date_time(const char *date) {
0
   } else if (tokens_read == 3) {
0
     return parse_date(date);
0
   } else if (tokens_read >= (max_tokens - 3)) {
0
-    // We read the Date and Time, maybe the Sign, default to the current locale's offset
0
+    // We read the Date and Time, default to the current locale's offset
0
     
0
     // Get localtime
0
     time(&rawtime);
0
-    timeinfo = localtime(&rawtime);
0
-    
0
-    int offset = -timezone;
0
-    int is_dst = timeinfo->tm_isdst * 3600;
0
+        timeinfo = localtime(&rawtime);
0
     
0
-    offset += is_dst;
0
-      
0
-    // TODO: Refactor the following few lines to do the calculation with the *seconds*
0
-    // value instead of having to do the hour/minute math
0
-    hour_offset = offset / 3600;
0
-    minute_offset = offset % 3600 / 60;
0
+    is_dst = timeinfo->tm_isdst * 3600;
0
+        
0
+        // Reset to GM Time
0
+        timeinfo = gmtime(&rawtime);
0
+        
0
+        gmt_offset = mktime(timeinfo) - rawtime;
0
+        
0
+        if ( is_dst > 0 )
0
+            gmt_offset -= is_dst;
0
+        
0
+        hour_offset = -(gmt_offset / 3600);
0
+        minute_offset = -(gmt_offset % 3600 / 60);
0
+        
0
   } else {
0
     // Something went terribly wrong
0
     rb_raise(ePostgresError, "Couldn't parse date: %s", date);

Comments