in reply to Re: Converting to GPS time
in thread Converting to GPS time

DateTime does not currently support GPS Week calculations. The only package that I could find on CPAN which does support GPS Week is DateTime::Precise. (Which is not a "DateTime" object!)

#Copyright (c) 2011 Michael R. Davis License BSD perl -e ' use DateTime; use Time::HiRes; use DateTime::Precise; my $dt=DateTime::Precise->new; printf "%s\n", $dt->asctime; my ($weeks, $seconds, $days)=$dt->gps_week_seconds_day; printf "Week: %s, Seconds: %s\n", $weeks, $seconds; print DateTime->new(qw{year 1980 month 1 day 6 time_zone UTC})->add(we +eks=>$weeks)->add(seconds=>$seconds), "\n"; '

All of the Math is in DateTime::Precise::gps_week_seconds_day

There is no license on DateTime::Precise. But, since the pre-fork is licensed "The Artistic License 2.0" this code should be as well. See RT 32186.

sub gps_week_seconds_day { my $self = shift; my $epoch_seconds = $self->gps_seconds_since_epoch; my $week = int($epoch_seconds/Secs_per_week); my $seconds = $epoch_seconds - $week*Secs_per_week; my $day = int($seconds/Secs_per_day); ($week, $seconds, $day); }