diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2013-02-28 13:28:35 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2013-02-28 13:28:35 +0000 |
commit | 77d30c4fdb8c2a875b5271bf808d49d5f2ea2e4d (patch) | |
tree | 362294596fadc164751e0006a4dfe42462dfeeb4 /src | |
parent | f7b8c4a72b75b9a0f0b724a186abaa2586e64574 (diff) | |
download | jackcess-77d30c4fdb8c2a875b5271bf808d49d5f2ea2e4d.tar.gz jackcess-77d30c4fdb8c2a875b5271bf808d49d5f2ea2e4d.zip |
use shared Calendar instance to converting Dates
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@663 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Column.java | 10 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Database.java | 16 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 8e3033d..57df40e 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -601,12 +601,12 @@ public class Column implements Comparable<Column> { return _fixedDataOffset; } - protected Charset getCharset() { + Charset getCharset() { return getDatabase().getCharset(); } - protected TimeZone getTimeZone() { - return getDatabase().getTimeZone(); + Calendar getCalendar() { + return getDatabase().getCalendar(); } /** @@ -1179,7 +1179,7 @@ public class Column implements Comparable<Column> { */ private long getToLocalTimeZoneOffset(long time) { - Calendar c = Calendar.getInstance(getTimeZone()); + Calendar c = getCalendar(); c.setTimeInMillis(time); return ((long)c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)); } @@ -1192,7 +1192,7 @@ public class Column implements Comparable<Column> { { // getting from local time back to UTC is a little wonky (and not // guaranteed to get you back to where you started) - Calendar c = Calendar.getInstance(getTimeZone()); + Calendar c = getCalendar(); c.setTimeInMillis(time); // apply the zone offset first to get us closer to the original time c.setTimeInMillis(time - c.get(Calendar.ZONE_OFFSET)); diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index d9fe435..2867587 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -46,6 +46,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.ConcurrentModificationException; @@ -490,6 +491,8 @@ public class Database /** shared state used when enforcing foreign keys */ private final FKEnforcer.SharedState _fkEnforcerSharedState = FKEnforcer.initSharedState(); + /** Calendar for use interpreting dates/times in Columns */ + private Calendar _calendar; /** * Open an existing Database. If the existing file is not writeable, the @@ -1063,6 +1066,8 @@ public class Database newTimeZone = getDefaultTimeZone(); } _timeZone = newTimeZone; + // clear cached calendar when timezone is changed + _calendar = null; } /** @@ -1135,6 +1140,17 @@ public class Database } /** + * @usage _advanced_method_ + */ + Calendar getCalendar() + { + if(_calendar == null) { + _calendar = Calendar.getInstance(_timeZone); + } + return _calendar; + } + + /** * @returns the current handler for reading/writing properties, creating if * necessary */ |