Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Converting to GPS time

by mrdvt92 (Acolyte)
on Mar 05, 2011 at 23:46 UTC ( [id://891619]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://891619]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found