Created
November 6, 2014 08:30
-
-
Save roblillack/8e02fcc4e42469234999 to your computer and use it in GitHub Desktop.
Ruby script to adjust timestamps in Garmin Training Center XML files (TCX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.tcxand re-import into Garmin Training Center.https://twitter.com/megametre/status/530277305160335360