Would it be better to set timeZone to local?
jdleung opened this issue · 2 comments
In class GPXType, timezone is set to TimeZone(secondsFromGMT: 0)
, for my own need, I set it to NSTimeZone.local
.
I believe this is related to #19
(Except that was about parsing, and I believe yours is about generating, but the idea is still the same)
Particularly this part:
The GPX Schema here specifically states this:
<xsd:element name="time" type="xsd:dateTime" minOccurs="0"> <xsd:annotation> <xsd:documentation> Creation/modification timestamp for element. Date and time in are in Univeral Coordinated Time (UTC), not local time! Conforms to ISO 8601 specification for date/time representation. Fractional seconds are allowed for millisecond timing in tracklogs. </xsd:documentation> </xsd:annotation> </xsd:element>
As such, it should be in UTC Time, stored as , and seeming stored without UTC offset value.
Also, for speed, I did not use the defaultDateFormatter
for date parsing, instead, using the classISO8601DateParser
, which speeds things up.
Basically, I didn't use local time (and I think you shouldn't too), as the GPX schema (aka what GPX is designed to be) specifically states that date and time stored in the GPX should be in UTC time, not local time.
The GPX standard also does not appear to include any UTC offset to be logged in the file. I plan on created a open GPX extension in near future, where the GPX standard could be extended with additional features like UTC offsets.
The GPX schema can be read here: https://www.topografix.com/gpx/1/1/gpx.xsd
By making sure that time is recorded in UTC time, not local time, means that your generated GPX file will be compliant with the GPX file's official standards.
Hope this clarifies the issue. I will close this for now.
I'd tried several GPX viewers, they didn't show the correct time. Thanks the information.