in reply to Converting to GPS time

local time = UTC + time offset, GPS = UTC without the correction for leap seconds.

So you can correct your local time for the time offset and forget about the leap seconds. Or even simpler use gmtime().

For example:

#!/usr/local/bin/perl use strict; use warnings; my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfW +eek, $dayOfYear) = gmtime(); my $year = 1900 + $yearOffset; my $GMTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$mo +nth] $dayOfMonth, $year"; print $GMTime;

I wonder why you're not interested in the leap second correction as accuracy is normally quite important?!

Cheers

Harry

Replies are listed 'Best First'.
Re^2: Converting to GPS time
by scitash (Initiate) on Mar 05, 2010 at 08:39 UTC
    Hi Harry,

    Thanks for the help.

    The reason the 15 seconds was not a burning issue is that I just needed a script to access particular directories (they had been set up by someone else in the distant past), which contained the gps data. The directories themselves were set up by GPS week, but then there was overlap between weeks anyway. There was lots of duplication as you can imagine.

      You can calculate the GPS leap second offset with DateTime::LeapSecond.

      perl -e 'use lib qw{lib}; use DateTime::LeapSecond; print DateTime::LeapSecond::leap_seconds( (DateTime->now->utc_rd_value +s)[0] ) - DateTime::LeapSecond::leap_seconds( (DateTime->new(qw{year 1980 +month 1 day 6 time_zone UTC})->utc_rd_values)[0]), "\n";'