File Coverage

blib/lib/Time/TCG.pm
Criterion Covered Total %
statement 32 36 88.8
branch n/a
condition n/a
subroutine 12 13 92.3
pod 5 5 100.0
total 49 54 90.7


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Time::TCG - Geocentric Coordinate Time and realisations
4              
5             =head1 SYNOPSIS
6              
7             use Time::TCG qw(tcg_instant_to_mjd tcg_mjd_to_instant);
8              
9             $mjd = tcg_instant_to_mjd($instant);
10             $instant = tcg_mjd_to_instant($mjd);
11              
12             use Time::TCG qw(tcg_to_tt tt_to_tcg);
13              
14             $tt_instant = tcg_to_tt($tcg_instant);
15             $tcg_instant = tt_to_tcg($tt_instant);
16              
17             use Time::TCG qw(tcg_realisation);
18              
19             $rln = tcg_realisation("bipm05");
20             $instant = $rln->from_tcg_tai($tcg_tai_instant);
21              
22             =head1 DESCRIPTION
23              
24             Geocentric Coordinate Time (TCG) is a coordinate time scale representing
25             time in the Terran system. Specifically, it is the proper time
26             experienced by a distant clock comoving with the geocentre. It is
27             linearly related to Terrestrial Time (TT), which is the proper time scale
28             underlying timekeeping on the Terran surface. TT is formally defined
29             in terms of TCG: TT ticks exactly 0.999_999_999_303_070_986_6 seconds
30             for each second of TCG.
31              
32             This module represents instants on the TCG and TT time scales as scalar
33             numbers of SI seconds since an epoch. This is an appropriate form for
34             all manner of calculations. Both scales are defined with a well-known
35             point at TAI instant 1977-01-01T00:00:00.0. This point is used as the
36             epoch for TCG, having the scalar value zero. The same instant on the
37             TT scale is assigned the scalar value 599_616_000 exactly, corresponding
38             to an epoch near the TAI epoch 1958-01-01T00:00:00.0. This matches the
39             convention used by C for instants on the TT scale. The use
40             of very different epochs for the two scales avoids confusion between them.
41              
42             There is also a conventional way to represent TCG instants using day-based
43             notations associated with planetary rotation `time' scales. The `day'
44             of TCG is a nominal period of exactly 86400 SI seconds, which is slightly
45             shorter than an actual Terran day. The well-known point at TAI instant
46             1977-01-01T00:00:00.0 is assigned the label 1977-01-01T00:00:32.184
47             (MJD 43144.0003725). Because TCG is not connected to Terran rotation,
48             and so has no inherent concept of a day, it is somewhat misleading to use
49             such day-based notations. Conversion between this notation and the linear
50             count of seconds is supported by this module. The day-based notations for
51             TT and TCG instants yield very similar values for corresponding instants,
52             so care must be taken to avoid confusion.
53              
54             Because TCG is a theoretical time scale, not directly accessible for
55             practical use, it must be realised using atomic clocks. In fact, it is TT
56             that is directly so realised, but the linear relationship between TT and
57             TCG means that any realisation of TT is effectively also realising TCG.
58             This module supports conversion of times between different realisations of
59             TCG, by making use of the facility in C for realisations of TT.
60              
61             =cut
62              
63             package Time::TCG;
64              
65 2     2   47631 { use 5.006; }
  2         8  
  2         90  
66 2     2   11 use warnings;
  2         3  
  2         72  
67 2     2   23 use strict;
  2         8  
  2         80  
68              
69 2     2   2311 use Math::BigRat 0.13;
  2         153266  
  2         12  
70              
71             our $VERSION = "0.002";
72              
73 2     2   4061 use parent "Exporter";
  2         543  
  2         10  
74             our @EXPORT_OK = qw(
75             tcg_instant_to_mjd tcg_mjd_to_instant
76             tcg_to_tt tt_to_tcg
77             tcg_realisation
78             );
79              
80             =head1 FUNCTIONS
81              
82             =over
83              
84             =item tcg_instant_to_mjd(INSTANT)
85              
86             Converts from a count of seconds to a Modified Julian Date in the manner
87             conventional for TCG. The MJD can be further converted to other forms of
88             day-based date using other modules. The input must be a C
89             object, and the result is the same type.
90              
91             =cut
92              
93 2     2   154 use constant TCG_EPOCH_MJD => Math::BigRat->new("43144.0003725");
  2         4  
  2         12  
94              
95             sub tcg_instant_to_mjd($) {
96 4     4 1 4835 my($instant) = @_;
97 4         14 return TCG_EPOCH_MJD + ($instant / 86400);
98             }
99              
100             =item tcg_mjd_to_instant(MJD)
101              
102             Converts from a Modified Julian Date, interpreted in the manner
103             conventional for TCG, to a count of seconds. The input must be a
104             C object, and the result is the same type.
105              
106             =cut
107              
108             sub tcg_mjd_to_instant($) {
109 4     4 1 4252 my($mjd) = @_;
110 4         14 return ($mjd - TCG_EPOCH_MJD) * 86400;
111             }
112              
113             =item tcg_to_tt(TCG_INSTANT)
114              
115             Converts from a TCG instant (as a count of seconds from the TCG epoch) to
116             the corresponding TT instant (as a count of seconds from the TT epoch).
117             The input must be a C object, and the result is the
118             same type.
119              
120             =cut
121              
122 2     2   1809 use constant TCG_EPOCH_TT => Math::BigRat->new(599616000);
  2         3  
  2         7  
123 2     2   286 use constant TT_TICK_RATE => Math::BigRat->new("0.9999999993030709866");
  2         4  
  2         11  
124              
125             sub tcg_to_tt($) {
126 3     3 1 11424 my($tcg) = @_;
127 3         15 return TCG_EPOCH_TT + TT_TICK_RATE * $tcg;
128             }
129              
130             =item tt_to_tcg(TT_INSTANT)
131              
132             Converts from a TT instant (as a count of seconds from the TT epoch)
133             to the corresponding TCG instant (as a count of seconds from the TCG
134             epoch). The input must be a C object, and the result is
135             the same type.
136              
137             =cut
138              
139             sub tt_to_tcg($) {
140 3     3 1 6052 my($tt) = @_;
141 3         13 return ($tt - TCG_EPOCH_TT) / TT_TICK_RATE;
142             }
143              
144             =item tcg_realisation(NAME)
145              
146             Looks up and returns an object representing a named realisation of TCG.
147             The object returned is of the class C; see the
148             documentation of that class for its interface. Each TCG realisation
149             corresponds precisely to a realisation of TT. The realisation names
150             that are understood are exactly the same as those understood by
151             C in L.
152              
153             The C module is required in order to do this.
154              
155             =cut
156              
157             sub tcg_realisation($) {
158 0     0 1   my($name) = @_;
159 0           require Time::TT;
160 0           require Time::TCG::Realisation;
161 0           return Time::TCG::Realisation->new(Time::TT::tt_realisation($name));
162             }
163              
164             =back
165              
166             =head1 SEE ALSO
167              
168             L,
169             L,
170             L,
171             L
172              
173             =head1 AUTHOR
174              
175             Andrew Main (Zefram)
176              
177             =head1 COPYRIGHT
178              
179             Copyright (C) 2006, 2010, 2012 Andrew Main (Zefram)
180              
181             =head1 LICENSE
182              
183             This module is free software; you can redistribute it and/or modify it
184             under the same terms as Perl itself.
185              
186             =cut
187              
188             1;