astanin/gpxplot

Parse time formats better

Opened this issue · 2 comments

Some gpx files use the time format <time>2010-07-18T15:21:41+01:00</time> which 
breaks your script at the moment.

You might consider using the parser from the python dateutil module which will 
handle virtually any time format. 

e.g.:

from dateutil import parser

def prettify_time(time):
    time = parser.parse(time)
    if tzname:
        time=time.replace(tzinfo=pytz.utc)
        time=time.astimezone(pytz.timezone(tzname))
    return time

Original issue reported on code.google.com by mark.opu...@googlemail.com on 23 Jul 2010 at 5:13

Sample file

Original comment by mark.opu...@googlemail.com on 23 Jul 2010 at 5:14

Attachments:

I have the same issue. That is my solution to avoid importing dateutil and six 
modules:


            def prettify_time(time):
                if 'Z' in time:
                    time=sub(r'\.\d+Z$','Z',time)
                elif '+' in time:
                    time=sub(r'\+.*$','Z',time)
                time=strptime(time,dateformat)
                if tzname:
                    time=time.replace(tzinfo=pytz.utc)
                    time=time.astimezone(pytz.timezone(tzname))
                return time

Original comment by danimorelo@gmail.com on 14 Nov 2014 at 1:24