]> source.dussan.org Git - jackcess.git/commitdiff
fix date handling, patch from joniles 1445597
authorJames Ahlborn <jtahlborn@yahoo.com>
Thu, 9 Mar 2006 20:03:44 +0000 (20:03 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Thu, 9 Mar 2006 20:03:44 +0000 (20:03 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@39 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/Column.java

index 50bc36a710f24776be5c4da691dcc6ee117d4f07..6397415c207268b64e2a240b0b5664d3bc141fdc 100644 (file)
@@ -229,13 +229,19 @@ public class Column implements Comparable<Column> {
     } else if (_type == DataType.FLOAT) {
       return new Float(buffer.getFloat());
     } else if (_type == DataType.SHORT_DATE_TIME) {
-      long time = (long) ((buffer.getDouble() - DAYS_BETWEEN_EPOCH_AND_1900) *
-          MILLISECONDS_PER_DAY);
-      Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-      cal.setTimeInMillis(time);
-      //Not sure why we're off by 1...
-      cal.add(Calendar.DATE, 1);
-      return cal.getTime();
+      // seems access stores dates in the local timezone.  guess you just hope
+      // you read it in the same timezone in which it was written!
+      double dval = buffer.getDouble();
+      dval *= MILLISECONDS_PER_DAY;
+      dval -= (DAYS_BETWEEN_EPOCH_AND_1900 * MILLISECONDS_PER_DAY);
+      long time = (long)dval;
+      TimeZone tz = TimeZone.getDefault();
+      Date date = new Date(time - tz.getRawOffset());
+      if (tz.inDaylightTime(date))
+      {
+        date = new Date(date.getTime() - tz.getDSTSavings());
+      }
+      return date;
     } else if (_type == DataType.BINARY) {
       return data;
     } else if (_type == DataType.TEXT) {
@@ -516,6 +522,8 @@ public class Column implements Comparable<Column> {
       buffer.putFloat(obj != null ? ((Number) obj).floatValue() : (float) 0);
     } else if (_type == DataType.SHORT_DATE_TIME) {
       if (obj instanceof Date) {
+        // seems access stores dates in the local timezone.  guess you just
+        // hope you read it in the same timezone in which it was written!
         Calendar cal = Calendar.getInstance();
         cal.setTime((Date) obj);
         long ms = cal.getTimeInMillis();