Skip to content

Instantly share code, notes, and snippets.

@roblillack
Created November 6, 2014 08:30
Show Gist options
  • Select an option

  • Save roblillack/8e02fcc4e42469234999 to your computer and use it in GitHub Desktop.

Select an option

Save roblillack/8e02fcc4e42469234999 to your computer and use it in GitHub Desktop.
Ruby script to adjust timestamps in Garmin Training Center XML files (TCX)
#!/usr/bin/env ruby
require 'time'
require 'rexml/document'
DELTA = -(24 * 3600 * 7 - 7 * 3600)
raw = IO.read(ARGV[0])
doc = REXML::Document.new(raw)
id_written = false
doc.elements.each('//Activity/Lap') do |lap|
lap.elements.each('Track/Trackpoint') do |ele|
t = Time.parse(ele.elements['Time'].text) + DELTA
ele.elements['Time'].text = t.iso8601
end
lapStart = (Time.parse(lap.attributes['StartTime']) + DELTA).iso8601
lap.attributes['StartTime'] = lapStart
if not id_written then
doc.elements['//Activity/Id'].text = lapStart
id_written = true
end
end
puts doc.to_s
@roblillack
Copy link
Copy Markdown
Author

Yesterday's run was about a week off (It's a GPS watch, goddammit!), the only way for me to fix this recording was to export it, adjust the timestamps using tcx_adjust_time BLA.tcx > NEW_BLA.tcx and re-import into Garmin Training Center.

https://twitter.com/megametre/status/530277305160335360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment