Skip to content

GPX: fix timestamp representation - #379

Merged
karussell merged 3 commits into
graphhopper:masterfrom
devemux86:gpx_timestamp
Mar 24, 2015
Merged

karussell merged 3 commits into
graphhopper:masterfrom
devemux86:gpx_timestamp

Conversation

@devemux86

Copy link
Copy Markdown
Contributor

Peter I think that in GPX the timestamps should be in UTC with ISO 8601 representation and end with the 'Z' suffix.
http://www.topografix.com/gpx_manual.asp#time

And to conform with spec, probably it's not necessary to provide the timezone as parameter to the createGPX method.

@karussell

Copy link
Copy Markdown
Member

Thanks, this would be really a nice cleanup :) ! Did you try some of the common GPX programs if they are okay with this? (basecamp, some online tools, josm, osm.org?)

@devemux86

Copy link
Copy Markdown
Contributor Author

Most readers (online, apps) are versatile enough to parse more than one timestamp patterns.
And I have found gpx files that don't follow the standard.

But going the other way, wherever I checked for official produced gpx files, I saw them following the spec.
(please inform us if someone has additional info)

@karussell

Copy link
Copy Markdown
Member

When we use 'Z' shouldn't we force +0? I.e.:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(formatter.format(new Date()));

Otherwise I'll get incorrect time when using default time zone here in Germany.

@devemux86

Copy link
Copy Markdown
Contributor Author

What do you mean, don't you get with the above code the UTC time ?

@karussell

Copy link
Copy Markdown
Member

It will correctly use the local or specified time zone but ignores the offset as we always write 'Z'. I think you can easily try on your own. It should give you different times (except you are in london :)) but it will give you identical times

@devemux86

Copy link
Copy Markdown
Contributor Author

Right now it gave me 2015-03-23T21:15:00Z

@devemux86

Copy link
Copy Markdown
Contributor Author

That's the correct UTC time, what do you get?
(or I'm missing something here)

@karussell

Copy link
Copy Markdown
Member

Strange, that you get it correctly. I get 2015-03-23T22:18:42Z
Also it makes sense to force UTC and avoid the default or a specific time zone when we always use +0

Just to be sure, did you try this:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
formatter.setTimeZone(TimeZone.getDefault());
System.out.println(formatter.format(new Date()));

@devemux86

Copy link
Copy Markdown
Contributor Author

The UTC timezone is needed or else as you said we'll get our current time.

I don't remember Java to have changes in that part (I'm in Linux with 7).

@karussell

Copy link
Copy Markdown
Member

Okay, but then this old code is wrong with your change:

TimeZone tz = TimeZone.getDefault();
if (!Helper.isEmpty(timeZoneId))
   tz = TimeZone.getTimeZone(timeZoneId);

formatter.setTimeZone(tz);

and we should always use UTC and remove the timeZone parameter, right?

@devemux86

Copy link
Copy Markdown
Contributor Author

Yes you are correct, to be with the spec we shouldn't provide the user any timezone option, but use internally only UTC.

@devemux86

Copy link
Copy Markdown
Contributor Author

Peter I pushed a new commit removing the timezone parameter and making the UTC default.

Also I think that in case of not provided startTimeMillis, the current date should be used and not the 0.

@karussell

Copy link
Copy Markdown
Member

Thanks & yes, you are right regarding the startTimeMillis

@devemux86

Copy link
Copy Markdown
Contributor Author

I pushed another commit regarding startTimeMillis.

karussell added a commit that referenced this pull request Mar 24, 2015
GPX export: avoid hack for timestamp representation, use current time instead of 0 if no start time provided
@karussell
karussell merged commit 7616e88 into graphhopper:master Mar 24, 2015
@karussell

Copy link
Copy Markdown
Member

Thanks!

@karussell karussell added this to the 0.5 milestone Mar 25, 2015
@devemux86
devemux86 deleted the gpx_timestamp branch May 29, 2015 08:07
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
* added translations

* added german translation for towerslope

* update german translations

* replaced questions marks with numbers and added custom icon option

* reformat code

* added batch numbers to prevent duplicate icons

* removed icon option in config; improved visabillity of batchNumbers

* moved icons to seperate files; optimization

* bug fix

* separate empty key from default profile name

* a little less code

* improved key selection while creating customProfiles Record

* separate empty key from default profile name (graphhopper#1)

* separate empty key from default profile name

* a little less code

---------

Co-authored-by: Peter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants