<!-- 
RSS generated by JIRA (4.4#649-r158309) at Sat May 18 17:28:08 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/JDBC-35/JDBC-35.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[JDBC-35] Wrong timezone for java.sql.Date, java.sql.Time and java.sql.Timestamp objects returned by with-query-results</title>
                <link>http://dev.clojure.org/jira/browse/JDBC-35</link>
                <project id="10021" key="JDBC">java.jdbc</project>
                        <description>&lt;p&gt;Our database stores date and time related information in UTC. But, the results from &lt;tt&gt;with-query-results&lt;/tt&gt; creates objects in the local timezone. This is causing a lot of unexpected behavior when constructing Joda &lt;tt&gt;DateTime&lt;/tt&gt; objects in &lt;tt&gt;clj-time&lt;/tt&gt;.  Currently, the &lt;tt&gt;with-query-results&lt;/tt&gt; function is using the single argument getter functions in the &lt;tt&gt;ResultSet&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;	&lt;tt&gt;getDate(int columnIndex)&lt;/tt&gt;&lt;br/&gt;
	&lt;tt&gt;getTime(int columnIndex)&lt;/tt&gt;&lt;br/&gt;
	&lt;tt&gt;getTimestamp(int columnIndex)&lt;/tt&gt; &lt;/p&gt;

&lt;p&gt;We can solve this problem if we can optionally pass the timezone information and call the two argument getter functions.&lt;/p&gt;

&lt;p&gt;	&lt;tt&gt;getDate(int columnIndex, Calendar cal)&lt;/tt&gt; &lt;br/&gt;
	&lt;tt&gt;getTime(int columnIndex, Calendar cal)&lt;/tt&gt; &lt;br/&gt;
	&lt;tt&gt;getTimestamp(int columnIndex, Calendar cal)&lt;/tt&gt;&lt;/p&gt;</description>
                <environment></environment>
            <key id="15583">JDBC-35</key>
            <summary>Wrong timezone for java.sql.Date, java.sql.Time and java.sql.Timestamp objects returned by with-query-results</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="3" iconUrl="http://dev.clojure.org/jira/images/icons/priority_major.gif">Major</priority>
                    <status id="5" iconUrl="http://dev.clojure.org/jira/images/icons/status_resolved.gif">Resolved</status>
                    <resolution id="2">Declined</resolution>
                                <assignee username="seancorfield">Sean Corfield</assignee>
                                <reporter username="jestinepaul">Jestine Paul</reporter>
                        <labels>
                        <label>bug</label>
                    </labels>
                <created>Fri, 20 Jul 2012 10:31:09 -0500</created>
                <updated>Wed, 12 Sep 2012 20:01:37 -0500</updated>
                    <resolved>Wed, 12 Sep 2012 20:01:37 -0500</resolved>
                                                                    <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="29016" author="seancorfield" created="Sat, 21 Jul 2012 01:30:19 -0500"  >&lt;p&gt;Can you provide a self-contained test case? Lots of people are using java.jdbc in production without running into this problem, and at World Singles we&apos;ve had this in production for a long time in a high traffic environment without seeing any problems with timezones. Dates go in and out of the database unchanged, which is exactly as expected - and we have databases running in three different timezones.&lt;/p&gt;</comment>
                    <comment id="29017" author="jestinepaul" created="Sat, 21 Jul 2012 05:29:05 -0500"  >&lt;p&gt;I have added a new test and it is failing with my Postgresql.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/jestinepaul/java.jdbc/commit/195397b1b2a0245d2439ab9963fe2138450a27f3&quot;&gt;https://github.com/jestinepaul/java.jdbc/commit/195397b1b2a0245d2439ab9963fe2138450a27f3&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="29020" author="seancorfield" created="Sat, 21 Jul 2012 13:03:48 -0500"  >&lt;p&gt;Looking at recommended practices out there, such as listed here: &lt;a href=&quot;http://stackoverflow.com/questions/2532729/daylight-saving-time-and-timezone-best-practices&quot;&gt;http://stackoverflow.com/questions/2532729/daylight-saving-time-and-timezone-best-practices&lt;/a&gt; one important thing is: &quot;On Servers, set hardware clocks and OS clocks to UTC. Use NTP services on all servers.&quot; The same advice is repeated here: &lt;a href=&quot;http://www.dbspecialists.com/blog/database-theory/intelligent-date-handling/&quot;&gt;http://www.dbspecialists.com/blog/database-theory/intelligent-date-handling/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looking further into PostgreSQL (a database I generally don&apos;t use), I see this: &lt;a href=&quot;http://stackoverflow.com/questions/6151084/which-timestamp-type-to-choose-in-a-postgresql-database&quot;&gt;http://stackoverflow.com/questions/6151084/which-timestamp-type-to-choose-in-a-postgresql-database&lt;/a&gt; which seems to contain a lot of PostgreSQL-specific stuff. However, that article makes it clear that you need to set the database timezone to UTC in order to SELECT timestamp columns correctly.&lt;/p&gt;

&lt;p&gt;In my opinion, the behavior you&apos;re seeing is not a bug (in java.jdbc) but an artifact of your environment being set up incorrectly. I&apos;ll leave this ticket open for a little while for more discussion but without a concrete patch that is shown to not affect other use cases, I will close this ticket by the end of August.&lt;/p&gt;</comment>
                    <comment id="29033" author="jestinepaul" created="Mon, 23 Jul 2012 13:26:04 -0500"  >&lt;p&gt;As mentioned earlier, the database server timezone is in UTC and the JDBC library runs on a client machine set to local time. If the database has a date value of 2012-7-23, it changes to 2012-7-22 on the client side (if the client is running at timezone greater than UTC) when coerced using &lt;tt&gt;to-date-time&lt;/tt&gt; in &lt;tt&gt;clj-time&lt;/tt&gt;. This is extremely dangerous and is not specific to any database. I noticed it first on Sybase Enterprise Server and I have now also replicated it in the test case with Postgresql.&lt;/p&gt;

&lt;p&gt;I have attached a patch which fixes this problem by passing in an optional parameter. The test case is also modified to use &lt;tt&gt;clj-time&lt;/tt&gt;, as it expresses the problem more clearly. Please let me know if you need any more clarification.&lt;/p&gt;

&lt;p&gt;p.s. I have already mailed the CA and should reach Durham in a few days.&lt;/p&gt;</comment>
                    <comment id="29431" author="seancorfield" created="Wed, 12 Sep 2012 20:01:26 -0500"  >&lt;p&gt;Since the proposed patch requires the user to pass in a list of columns to treat specially - and reorders columns in results and adds some performance overhead for all users, not just those wanting to adjust column values - I believe users who choose to run JDBC clients in timezones different to the database, against the widely-listed best practice recommendations, should bear the burden of adjusting the columns themselves in their own client code. Since they already know which columns to adjust and they know the difference between UTC and local time, they should be able to make the adjustments easily enough as part of post-processing the resultset-seq.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11394" name="resultset-timezone.diff" size="7215" author="jestinepaul" created="Mon, 23 Jul 2012 13:24:52 -0500" />
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                                                                            </customfields>
    </item>
</channel>
</rss>