summaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2008-01-24 04:07:46 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2008-01-24 04:07:46 +0000
commitf96fd8b8dc0adbfea1d5a84ced5b56b499037f2e (patch)
tree03954a82dde704c5221e6a0b0d0152c9a840c83d /src/java
parent3534af761572c618c3d5a82f34e7e81a677b5590 (diff)
downloadjackcess-f96fd8b8dc0adbfea1d5a84ced5b56b499037f2e.tar.gz
jackcess-f96fd8b8dc0adbfea1d5a84ced5b56b499037f2e.zip
Resolve more edge cases around date handling
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@224 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Column.java42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java
index 3cfd4fe..73fa511 100644
--- a/src/java/com/healthmarketscience/jackcess/Column.java
+++ b/src/java/com/healthmarketscience/jackcess/Column.java
@@ -37,7 +37,6 @@ import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
-import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -640,19 +639,14 @@ public class Column implements Comparable<Column> {
{
// 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;
+ double dTime = buffer.getDouble();
+ dTime *= MILLISECONDS_PER_DAY;
+ dTime -= (DAYS_BETWEEN_EPOCH_AND_1900 * MILLISECONDS_PER_DAY);
+ long time = (long)dTime;
+ time -= getTimeZoneOffset(time);
+ return new Date(time);
}
-
+
/**
* Writes a date value.
*/
@@ -663,16 +657,26 @@ public class Column implements Comparable<Column> {
} else {
// 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) value);
- long ms = cal.getTimeInMillis();
- ms += (long) TimeZone.getDefault().getOffset(ms);
- buffer.putDouble((double) ms / MILLISECONDS_PER_DAY +
- DAYS_BETWEEN_EPOCH_AND_1900);
+ long time = ((Date)value).getTime();
+ time += getTimeZoneOffset(time);
+
+ double dTime = (((double)time) / MILLISECONDS_PER_DAY) +
+ DAYS_BETWEEN_EPOCH_AND_1900;
+ buffer.putDouble(dTime);
}
}
/**
+ * Gets the timezone offset from UTC for the given time (including DST).
+ */
+ private static long getTimeZoneOffset(long time)
+ {
+ Calendar c = Calendar.getInstance();
+ c.setTimeInMillis(time);
+ return ((long)c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET));
+ }
+
+ /**
* Decodes a GUID value.
*/
private String readGUIDValue(ByteBuffer buffer)