Author: jolee
Date: 2012-08-23 14:14:04 -0400 (Thu, 23 Aug 2012)
New Revision: 4363
Modified:
branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
Log:
TEIID-2112 (reprise): consistent handling of local timezone on xsd:date, xsd:datetime, and
xsd:time values that have no timezone specified.
Modified:
branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java
===================================================================
---
branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java 2012-08-23
17:56:45 UTC (rev 4362)
+++
branches/7.4.x/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java 2012-08-23
18:14:04 UTC (rev 4363)
@@ -22,6 +22,8 @@
package org.teiid.core.util;
+import static org.junit.Assert.*;
+
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
@@ -29,28 +31,20 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.GregorianCalendar;
import java.util.TimeZone;
-import org.teiid.core.util.TimestampWithTimezone;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-import junit.framework.TestCase;
+public class TestTimestampWithTimezone {
-public class TestTimestampWithTimezone extends TestCase {
-
- /**
- * Constructor for TestTimestampWithTimezone.
- *
- * @param name
- */
- public TestTimestampWithTimezone(String name) {
- super(name);
- }
-
- public void setUp() {
+ @Before public void setUp() {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("America/Chicago"));
//$NON-NLS-1$
}
- public void tearDown() {
+ @After public void tearDown() {
TimestampWithTimezone.resetCalendar(null);
}
@@ -117,7 +111,7 @@
return ts;
}
- public void testDST() {
+ @Test public void testDST() {
helpTestSame("2005-10-30 02:39:10", 1, "America/Chicago",
//$NON-NLS-1$ //$NON-NLS-2$
"GMT-05:00"); //$NON-NLS-1$
@@ -137,32 +131,32 @@
}
- public void testTimezone() {
+ @Test public void testTimezone() {
helpTestSame("2004-06-29 15:39:10", 1, "GMT-06:00",
//$NON-NLS-1$ //$NON-NLS-2$
"GMT-05:00"); //$NON-NLS-1$
}
- public void testTimezone2() {
+ @Test public void testTimezone2() {
helpTestSame("2004-06-29 15:39:10", 1, "GMT-08:00",
//$NON-NLS-1$ //$NON-NLS-2$
"GMT-06:00"); //$NON-NLS-1$
}
- public void testTimezone3() {
+ @Test public void testTimezone3() {
helpTestSame("2004-08-31 18:25:54", 1, "Europe/London",
//$NON-NLS-1$ //$NON-NLS-2$
"GMT"); //$NON-NLS-1$
}
- public void testTimezoneOverMidnight() {
+ @Test public void testTimezoneOverMidnight() {
helpTestSame("2004-06-30 23:39:10", 1, "America/Los_Angeles",
//$NON-NLS-1$ //$NON-NLS-2$
"America/Chicago"); //$NON-NLS-1$
}
- public void testCase2852() {
+ @Test public void testCase2852() {
helpTestSame("2005-05-17 22:35:33", 508659, "GMT",
//$NON-NLS-1$ //$NON-NLS-2$
"America/New_York"); //$NON-NLS-1$
}
- public void testCreateDate() {
+ @Test public void testCreateDate() {
Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201");
//$NON-NLS-1$
Date date = TimestampWithTimezone.createDate(t);
@@ -179,7 +173,7 @@
assertEquals(cal.get(Calendar.DATE), 30);
}
- public void testCreateTime() {
+ @Test public void testCreateTime() {
Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201");
//$NON-NLS-1$
Time date = TimestampWithTimezone.createTime(t);
@@ -199,14 +193,14 @@
/**
* Even though the id of the timezones are different, this should not change the
result
*/
- public void testDateToDateConversion() {
+ @Test public void testDateToDateConversion() {
Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
Date converted = TimestampWithTimezone.createDate(t,
TimeZone.getTimeZone("America/Chicago"),
Calendar.getInstance(TimeZone.getTimeZone("US/Central"))); //$NON-NLS-1$
//$NON-NLS-2$
assertEquals(t.getTime(), converted.getTime());
}
- public void testDateToDateConversion1() {
+ @Test public void testDateToDateConversion1() {
Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
Date converted = TimestampWithTimezone.createDate(t,
TimeZone.getTimeZone("America/Chicago"),
Calendar.getInstance(TimeZone.getTimeZone("GMT"))); //$NON-NLS-1$ //$NON-NLS-2$
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2012-08-23
17:56:45 UTC (rev 4362)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2012-08-23
18:14:04 UTC (rev 4363)
@@ -22,15 +22,14 @@
package org.teiid.query.processor.relational;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.TimeZone;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
@@ -56,7 +55,6 @@
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.XMLType;
-import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.FunctionDescriptor;
import org.teiid.query.sql.lang.XMLTable;
@@ -258,10 +256,11 @@
if (value instanceof CalendarValue) {
CalendarValue cv = (CalendarValue)value;
if (!cv.hasTimezone()) {
+ int tzMin = getContext().getServerTimeZone().getRawOffset()/60000;
+ cv.setTimezoneInMinutes(tzMin);
Calendar cal = cv.getCalendar();
- Date d = cal.getTime();
- cal.setTimeZone(getContext().getServerTimeZone());
- return TimestampWithTimezone.createTimestamp(d,
TimeZone.getTimeZone("GMT"), cal);
+
+ return new Timestamp(cal.getTime().getTime());
}
}
return Value.convertToJava(value);
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2012-08-23
17:56:45 UTC (rev 4362)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2012-08-23
18:14:04 UTC (rev 4363)
@@ -194,10 +194,10 @@
}
@Test public void testXmlTableDateTime() throws Exception {
- String sql = "select * from xmltable('/a' passing convert('<a
dt=\"2011-11-17T07:38:49\" dtz=\"2011-11-17T07:38:49Z\"
t=\"13:23:14\" d=\"2010-04-05\" />', xml) columns x timestamp
path '@dt', x1 timestamp path '@dtz', y date path '@d', z time
path '@t') as x"; //$NON-NLS-1$
+ String sql = "select * from xmltable('/a' passing convert('<a
dt=\"0001-11-17T07:38:49\" dtz=\"2011-11-17T07:38:49Z\"
t=\"13:23:14\" d=\"2010-04-05\" />', xml) columns x timestamp
path '@dt', x1 timestamp path '@dtz', y date path '@d', z time
path '@t') as x"; //$NON-NLS-1$
List<?>[] expected = new List<?>[] {
- Arrays.asList(TimestampUtil.createTimestamp(111, 10, 17, 7, 38, 49, 0),
TimestampUtil.createTimestamp(111, 10, 17, 1, 38, 49, 0), TimestampUtil.createDate(110, 3,
5), TimestampUtil.createTime(13, 23, 14))
+ Arrays.asList(TimestampUtil.createTimestamp(-1899, 10, 19, 7, 38, 49, 0),
TimestampUtil.createTimestamp(111, 10, 17, 1, 38, 49, 0), TimestampUtil.createDate(110, 3,
5), TimestampUtil.createTime(13, 23, 14))
};
process(sql, expected);