GithubHelp home page GithubHelp logo

time parsing about gpxpy HOT 7 CLOSED

tkrajina avatar tkrajina commented on June 4, 2024
time parsing

from gpxpy.

Comments (7)

tkrajina avatar tkrajina commented on June 4, 2024

Hi Kai

Yes, I know the datetime parsing issues. I can add a list possible datetime formats and a 'strict' flag when parsing. If strict is False, only the strict GPX datetime format will be used (the one ending with Z) otherwise any of the list of available formats (you can then add yours if needed).

What do you think?

Regards,
tk

from gpxpy.

 avatar commented on June 4, 2024

GPX (1.1 at least) seems to specify dateTime as the format which can include the Z, but it doesn't seem to be required. I'd say that you should parse the dateTime with the Z, without the Z, and with the offset from UTC (+/- HH:MM) formats.

Anything other than those and I'd say you should pass in a callback function to handle any non-standard string to datetime conversions.

from gpxpy.

KaiVolland avatar KaiVolland commented on June 4, 2024

I like both ideas.

My problem was, that i downloaded my gpx-files from my http://www.sports-tracker.com/ account and these tracks seems to have invalid timestamps: "2013-07-06T14:29:46.52" --> No Z or offset

This problem would be fixed by both of your solutions.

I like the solution with the whitelist of dateformats. That would bring up an easy way to expand the supported date formats, even if they are not valid... You should decide if you would like to support incorrect gpx-files or not.

bj1s idea is also satisfying and probably more straight forward.

from gpxpy.

tkrajina avatar tkrajina commented on June 4, 2024

bj1 & Kai, you're both! right.

I was speaking from memory but my memory is obviously faulty :) The 'T' must be there, Z isn't important. (BTW, gpxpy still don't work for gpx 1.1, it is on my "to do" list, but lack of free time... ):

The valid/strict timestamp formats are here: http://books.xmlschemata.org/relaxng/ch19-77049.html

Is anybody willing to make a list of strict formats function and (maybe) some common-but-unstrict, change parse_time(), add few unit tests and make a pull request? Otherwise, I'll do it, but probably not until the end of this month.

from gpxpy.

tkrajina avatar tkrajina commented on June 4, 2024

Here's my first try:

680b513

Note that two use cases are not yet handled:

  • negative years (i suppose this isn't a big problem, ancient Greeks and Romans had a rather poor GPS devices ;)
  • UTC offsets (because %z for UTC offset don't work with strptime, and even if it worked it works for +0100 not +01:00)

If you want to try, use the timestamp-fix branch.

from gpxpy.

 avatar commented on June 4, 2024

As you said in an earlier post, the 'T' must be in the timestamp, but it
looks like the unit tests are testing version without the 'T' and are
considering them to have passed.

It all depends on how strict you want to be with the standard.

from gpxpy.

tkrajina avatar tkrajina commented on June 4, 2024

Right, I decided to accept timestamps without the T for this first try. I'll probably keep it this way. Anyway, if users try to get the GPS back with get_xml() they will get the right timestamp format.

from gpxpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.