#!/usr/bin/perl -w

# $snafu: fixtrack,v 1.1 2001/06/19 04:36:46 marc Exp $

# Script to convert timestamps in tracklogs from the old style found
# in versions 1.0-1.2 [yymmddhhmss] to the new style in version 1.3
# [yyyy-mm-dd hh:mm:ss]

use strict;

my $type = "";
my $line;

print "; converted from old garmin-utils file\n";
while (defined ($line = <>)) {
    chomp ($line);
    if (index ($line, "[") == 0) {
        if (index ($line, "[tracks") == 0) {
            $type = "TRK";
        } else {
            $type = "";
        }
        print "$line\n";
    } elsif ($type eq "TRK") {
        if ($line =~ /^ ([\d\+\-\.]*) *([\d\+\-\.]*) (\d*)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d) *(start)*/) {
            printf "%14.10f %15.10f %4.4d-%2.2d-$5 $6:$7:$8", $1, $2,
                        $3 + 1900, $4 + 1;
            (defined ($9)) && print " start\n";		# start point
            (defined ($9)) || print "\n";		# otherwise
        } else {
            warn ("Bad input line: " . $line);
        }
    } else {
        print "$line\n";
    }
}
