[OSM-dev] OSM Date Formats

Brett Henderson brett at bretth.com
Mon Oct 1 14:58:26 BST 2007


This probably should go to Frederik but I'll post it here anyway in case 
others are interested or have issues/comments.

I've attached a patch to JOSM modifying its date handling.  This patch 
copies in most of the osmosis date handling code which I think is an 
improvement on the existing JOSM date handling code.

Firstly it modifies JOSM to write dates in UTC XML format.  I would have 
used XmlGregorianCalendar but it includes millisecond information and I 
can't find a way to remove it.  I've written a custom formatter 
instead.  It has a bug when writing dates before baby Jesus was visited 
by the wise men (ie. BC dates require a negative year in XML) but I 
haven't found any data that old in the OSM database so I didn't bother 
fixing it.

The existing date writer just wrote a date without timezone information 
so JOSM was always applying local timezone to dates.  This is okay for 
normal editing but not good if you load files written in another timezone.

It also fixes the date parser.  The existing parser wasn't making use of 
XmlGregorianCalendar which takes care of all xml date formats.  I've 
updated it to first try my custom parser used in osmosis and if that 
doesn't recognise the format to fallback to XmlGregorianCalendar and 
finally to fall back to the old JOSM parser (a slightly modified version 
of it).  Given that parse performance isn't an issue for JOSM sized 
files, the custom bit could probably be deleted but note that the 
XmlGregorianCalendar performance is atrocious on UTC dates (not so bad 
for dates with an offset) for reasons which I won't go into here.

The existing parser can't parse 2007-01-12T13:46:40Z properly, it loses 
10 hours when I run it in Australia because it loses the fact that it is 
GMT.  This is a fairly major bug which is now fixed.

I've done some basic testing and it "works for me".

I have no idea if it follows all the relevant JOSM coding styles and 
exception handling in particular isn't ideal but I've followed the lead 
of the existing JOSM code.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: josm_date_patch.patch
Type: text/x-patch
Size: 15354 bytes
Desc: not available
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20071001/9ded6857/attachment.bin>


More information about the dev mailing list