[Mulgara-svn] r1176 - trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa

ronald at mulgara.org ronald at mulgara.org
Mon Aug 25 11:18:30 UTC 2008


Author: ronald
Date: 2008-08-25 04:18:25 -0700 (Mon, 25 Aug 2008)
New Revision: 1176

Modified:
   trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPDateImpl.java
Log:
Fix backwards compatibility support added in r1144.

Pre r1081 the date was being stored in local-time, not UTC, i.e. as
midnight + local-time-offset. Reading that as UTC was then causing
delete-select to fail because globalization would return a pure date
with tz-offset 0, but subsequent localization would then not find the
db entry since the entry has a non-zero time (unless your locale happened
to be UTC). So now we figure out the tz-offset of the stored value and
use that instead.


Modified: trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPDateImpl.java
===================================================================
--- trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPDateImpl.java	2008-08-23 06:03:16 UTC (rev 1175)
+++ trunk/src/jar/store-stringpool/java/org/mulgara/store/stringpool/xa/SPDateImpl.java	2008-08-25 11:18:25 UTC (rev 1176)
@@ -36,6 +36,7 @@
 import org.apache.log4j.Logger;
 
 // Locally written packages
+import org.joda.time.DateTime;
 import org.joda.time.DateTimeZone;
 import org.joda.time.format.DateTimeFormatter;
 import org.joda.time.format.DateTimeFormatterBuilder;
@@ -115,10 +116,17 @@
 
 
   SPDateImpl(ByteBuffer data) {
-    this(data.getLong(), (data.limit() > Constants.SIZEOF_LONG) ? data.getInt() : 0);
+    this(data.getLong(), (data.limit() > Constants.SIZEOF_LONG) ? data.getInt() : calcTZOffset(data.getLong(0)));
   }
 
+  /** Guess the timezone offset the given time (date) was stored under */
+  private static int calcTZOffset(long time) {
+    int minutes = new DateTime(time, DateTimeZone.UTC).getMinuteOfDay();
+    return (minutes < 12*60) ? -minutes : (minutes > 12*60) ? 24*60 - minutes :
+           (DateTimeZone.getDefault().getOffset(time) > 0) ? -minutes : minutes;
+  }
 
+
   SPDateImpl(long l) {
     this(new Date(l), 0);
   }




More information about the Mulgara-svn mailing list