<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 18 July 2013 15:11, Paul Norman <span dir="ltr"><<a href="mailto:penorman@mac.com" target="_blank">penorman@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I've been working on some API tests, and ran into a case where the<br>
timestamps of objects in a file are not reproduced after loading the file<br>
into the database and fetching it with API calls.<br>
<br>
The file contains this node:<br>
<br>
<node id="1001" version="1" changeset="1001" lat="1.001" lon="1.001"<br>
user="user_1001" uid="1001" timestamp="2012-10-01T00:00:00Z"/><br>
<br>
I load the file with osmosis into an apidb database and fetch it with the<br>
rails port and get back a node with timestamp="2012-09-30T17:00:00Z"<br>
<br>
If I go into the database and SELECT the timestamp column for the node I get<br>
<br>
<br>
2012-09-30 17:00:00<br>
<br>
It looks like osmosis is doing an incorrect time zone conversion.<br>
<br>
I'm not sure where to ticket this.<br>
<br>
Note: I am in Vancouver, in the PDT timezone.<br></blockquote><div><br></div><div>Timezones are my second favourite topic after character set encodings ;-)<br><br></div></div>I don't know if Osmosis is at fault here or not.  All of the apidb timestamp columns are defined as "timestamp without time zone".  Apparently this means that no timezone conversions are done during input and output [1] (ie. the database ignores any supplied timezone information, as opposed to "with time zone" which always stores in UTC).  I've checked the code and I can't see anywhere where Osmosis doing anything special with timezones.  Osmosis converts a standard Java java.util.Date into a java.sql.Timestamp for persistence.  Both of those types have an internal time field containing the number of milliseconds since 1970.  java.util.Date always stores this time field in UTC.  It is possible that the JDBC drivers are passing the timestamp to the database in a UTC timezone and the database is ignoring it.<br>
<br></div><div class="gmail_extra">In your example, your time is 7 hours off.  Are you in daylight savings time at the moment?  If that's the case it certainly seems like UTC/PDT confusion.<br><br></div><div class="gmail_extra">
My maths might be wrong, but I would have thought that if the JDBC drivers were passing in UTC times that the times would end up 7 hours ahead, not behind.  So my above explanation might be wrong.<br><br></div><div class="gmail_extra">
I'm not sure how to diagnose this one.  Perhaps trace queries against the database server and see what Osmosis is passing in?<br><br></div><div class="gmail_extra">I'm also not sure why the schema doesn't use "timestamp with time zone".  It should make things a lot easier and allow all components to do automatic timezone conversion as necessary.  I seem to recall having similar issues on the main OSM servers.  I can't remember what the final fix was there, but usually I aim to have everything running in UTC to avoid these issues.<br>
</div><div class="gmail_extra"><br>[1] <a href="http://www.postgresql.org/docs/9.2/static/datatype-datetime.html">http://www.postgresql.org/docs/9.2/static/datatype-datetime.html</a><br><br></div></div>