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); }

In reply to Re^2: Converting to GPS time by mrdvt92
in thread Converting to GPS time by scitash

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.