I wrote a Python script to shift times in a .gpx file by a certain amount. You need to install Python (I use 2.7.6) and BeautifulSoup. It's easiest to do with the pip
package manager.
When you have pip installed, use pip install beautifulsoup4
to use the package.
If the GPX files are in a slightly different format (I've only encountered the variety that works with the program below), then look up strftime formatting. Note that the output file will not be exactly the same as the input in terms of formatting irrelevant to the information contained in the XML tree, but it should still be readable.
import datetime
from bs4 import BeautifulSoup
import re
import os
import sys
directory = r'[replace this with whatever directory you have your gpx files in]'
#you can come up with your own implementation of how to select all the files
#file_list = []
file_list = os.listdir(directory)
#this omits gpx files with an underscore
#(to avoid affecting ones with the _modified prefix
file_list = [file for file in file_list if re.search('^[^_]*\.gpx',file)]
print file_list
#this can be any decimal number
hour_shift = 1
for file in file_list:
with open(file,'r') as f:
xml = f.read()
bx = BeautifulSoup(xml)
times = bx.find_all('time')
for stime in times:
timestr = stime.text
rawtime = datetime.datetime.strptime(timestr,'%Y-%m-%dT%H:%M:%SZ')
rawtime = rawtime + datetime.timedelta(hours = hour_shift)
stime.string.replace_with(rawtime.strftime('%Y-%m-%dT%H:%M:%SZ'))
new_filename = re.sub(r'(\..+)?$',r'_modified\1',file)
with open(new_filename,'w') as g:
g.write(bx.prettify())
print 'converted %s to %s' % (file,new_filename)
sys.stdout.flush()
print 'done converting'