blib/lib/Time/GPS.pm

filter: Statementstmt 84.8% 28 / 33 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 83.3% 40 / 48 CC 2 SCAR 6.5
CC
2
Cov
80%
gps_realisation
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 =head1 NAME
2  
3 Time::GPS - Global Positioning System time
4  
5 =head1 SYNOPSIS
6  
7 use Time::GPS qw(gps_instant_to_mjd gps_mjd_to_instant);
8  
9 $mjd = gps_instant_to_mjd($instant);
10 $instant = gps_mjd_to_instant($mjd);
11  
12 use Time::GPS qw(gps_realisation);
13  
14 $rln = gps_realisation("");
15 $instant = $rln->to_tai($gps_instant);
16  
17 =head1 DESCRIPTION
18  
19 The Global Positioning System (GPS) includes as an integral feature the
20 dissemination of a very precise time scale. This time scale is produced
21 by atomic clocks on the satellites, and is steered to keep in step with
22 International Atomic Time (TAI). The GPS time scale is thus indirectly
23 a realisation of Terrestrial Time (TT). GPS time is one of the most
24 accurate and the most accessible realisations of TAI.
25  
26 This module represents instants on the TAI time scale as a scalar
27 number of TAI seconds since an epoch. This is an appropriate form
28 for all manner of calculations. The epoch used is that of TAI, at
29 UT2 instant 1958-01-01T00:00:00.0 as calculated by the United States
30 Naval Observatory, even though GPS did not exist then. This matches
31 the convention used by C<Time::TAI> for instants on the TAI scale and
32 by C<Time::TT> for instants on the TT scale.
33  
34 There is also a conventional way to represent GPS time instants using
35 day-based notations associated with planetary rotation `time' scales.
36 The `day' of GPS is a nominal period of exactly 86400 GPS seconds,
37 which is slightly shorter than an actual Terran day. The start of
38 the GPS time scale, at UTC instant 1980-01-06T00:00:00.0 (TAI instant
39 1980-01-06T00:00:19.0) is assigned the label 1980-01-06T00:00:00.0
40 (MJD 44244.0). Because GPS time is not connected to Terran rotation,
41 and so has no inherent concept of a day, it is somewhat misleading to
42 use such day-based notations. Conversion between this notation and the
43 linear count of seconds is supported by this module. This notation does
44 not match the similar day-based notations used for TAI and TT.
45  
46 =cut
47  
48 package Time::GPS;
49  
50 2 ▶{ use 5.006; }
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
55 2 ▶use Math::BigRat 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 2 our $VERSION = "0.003";
58  
59 2 ▶use parent "Exporter";
Subroutine BEGIN: called CC=1 SCAR=0.0
60 2 our @EXPORT_OK = qw(gps_instant_to_mjd gps_mjd_to_instant gps_realisation);
61  
62 =head1 FUNCTIONS
63  
64 =over
65  
66 =item gps_instant_to_mjd(INSTANT)
67  
68 Converts from a count of seconds to a Modified Julian Date in the
69 manner conventional for GPS time. The MJD can be further converted to
70 other forms of day-based date using other modules. The input must be
71 a C<Math::BigRat> object, and the result is the same type.
72  
73 =cut
74  
75 2 ▶use constant GPS_EPOCH_MJD => Math::BigRat->new((36204*86400-19)."/86400");
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 4 ▶sub gps_instant_to_mjd($) {
Subroutine gps_instant_to_mjd: called CC=1 SCAR=0.0
Pod documented
78 4 my($gps) = @_;
79 4 return GPS_EPOCH_MJD + ($gps / 86400);
80 }
81  
82 =item gps_mjd_to_instant(MJD)
83  
84 Converts from a Modified Julian Date, interpreted in the manner
85 conventional for GPS time, to a count of seconds. The input must be a
86 C<Math::BigRat> object, and the result is the same type.
87  
88 =cut
89  
90 4 ▶sub gps_mjd_to_instant($) {
Subroutine gps_mjd_to_instant: called CC=1 SCAR=0.0
Pod documented
91 4 my($mjd) = @_;
92 4 return ($mjd - GPS_EPOCH_MJD) * 86400;
93 }
94  
95 =item gps_realisation(NAME)
96  
97 Looks up and returns an object representing a named realisation of
98 GPS time. The object returned is of the class C<Time::TT::Realisation>;
99 see the documentation of that class for its interface.
100  
101 Presently the only name recognised is the empty string, representing
102 GPS time itself. Other names may be recognised in the future.
103  
104 The C<Time::TAI> module is required in order to do this.
105  
106 =cut
107  
108 0 ▶sub gps_realisation($) {
Subroutine gps_realisation: not called CC=2 SCAR=17.9
Pod documented
109 0 my($k) = @_;
110 0 ▶ if($k eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq '') { } 0 0 0
111 0 require Time::TAI;
112 0 return Time::TAI::tai_realisation("gps");
113 } else {
114 0 croak "no realisation TT(TAI(GPS(".uc($k)."))) known";
115 }
116 }
117  
118 =back
119  
120 =head1 SEE ALSO
121  
122 L<Date::JD>,
123 L<Time::TAI>,
124 L<Time::TT>,
125 L<Time::TT::Realisation>
126  
127 =head1 AUTHOR
128  
129 Andrew Main (Zefram) <zefram@fysh.org>
130  
131 =head1 COPYRIGHT
132  
133 Copyright (C) 2006, 2009, 2010, 2012
134 Andrew Main (Zefram) <zefram@fysh.org>
135  
136 =head1 LICENSE
137  
138 This module is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
140  
141 =cut
142  
143 2 1;
↑ Summary