1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.time;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.BeforeEach;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.Utils;
23  import org.orekit.frames.ITRFVersion;
24  import org.orekit.utils.Constants;
25  import org.orekit.utils.IERSConventions;
26  
27  
28  public class TCBScaleTest {
29  
30      @Test
31      public void testReference() {
32          TimeScale tcb = TimeScalesFactory.getTCB();
33          TimeScale tdb = TimeScalesFactory.getTDB();
34          Assertions.assertEquals("TCB", tcb.toString());
35          AbsoluteDate refTCB = new AbsoluteDate("1977-01-01T00:00:32.184", tcb);
36          AbsoluteDate refTDB = new AbsoluteDate("1977-01-01T00:00:32.184", tdb);
37          Assertions.assertEquals(0.0, refTCB.durationFrom(refTDB), 1.0e-12);
38      }
39  
40      @Test
41      public void testRate() {
42          TimeScale tcb = TimeScalesFactory.getTCB();
43          TimeScale tdb = TimeScalesFactory.getTDB();
44          AbsoluteDate t0 = AbsoluteDate.J2000_EPOCH;
45          for (double deltaT = 1.0; deltaT < 10.0; deltaT += 0.3) {
46              AbsoluteDate t1 = t0.shiftedBy(deltaT);
47              double tdbRate = t1.offsetFrom(t0, tdb) / deltaT;
48              double tcbRate = t1.offsetFrom(t0, tcb) / deltaT;
49              Assertions.assertEquals(tdbRate + 1.550519768e-8, tcbRate, 1.0e-14);
50          }
51      }
52  
53      @Test
54      public void testSymmetry() {
55          TimeScale scale = TimeScalesFactory.getTCB();
56          for (double dt = -10000; dt < 10000; dt += 123.456789) {
57              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
58              double dt1 = scale.offsetFromTAI(date).toDouble();
59              DateTimeComponents components = date.getComponents(scale);
60              double dt2 = scale.offsetToTAI(components.getDate(), components.getTime()).toDouble();
61              Assertions.assertEquals( 0.0, dt1 + dt2, 1.0e-10);
62          }
63      }
64  
65      @Test
66      public void testDuringLeap() {
67          final TimeScale utc   = TimeScalesFactory.getUTC();
68          final TimeScale scale = TimeScalesFactory.getTCB();
69          final AbsoluteDate before = new AbsoluteDate(new DateComponents(1983, 6, 30),
70                                                       new TimeComponents(23, 59, 59),
71                                                       utc);
72          final AbsoluteDate during = before.shiftedBy(1.25);
73          Assertions.assertEquals(61, utc.minuteDuration(during));
74          Assertions.assertEquals(1.0, utc.getLeap(during).toDouble(), 1.0e-10);
75          Assertions.assertEquals(60, scale.minuteDuration(during));
76          Assertions.assertEquals(0.0, scale.getLeap(during).toDouble(), 1.0e-10);
77      }
78  
79      @Test
80      public void testAAS06134() {
81  
82          // this reference test has been extracted from the following paper:
83          // Implementation Issues Surrounding the New IAU Reference Systems for Astrodynamics
84          // David A. Vallado, John H. Seago, P. Kenneth Seidelmann
85          // http://www.centerforspace.com/downloads/files/pubs/AAS-06-134.pdf
86          // Note that the dUT1 here is -0.439962, whereas it is -0.4399619 in the book
87          Utils.setLoaders(IERSConventions.IERS_1996,
88                           Utils.buildEOPList(IERSConventions.IERS_1996, ITRFVersion.ITRF_2008, new double[][] {
89                               { 53098, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
90                               { 53099, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
91                               { 53100, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
92                               { 53101, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
93                               { 53102, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
94                               { 53103, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
95                               { 53104, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN },
96                               { 53105, -0.439962, 0.0015563, -0.140682, 0.333309, -0.052195, -0.003875, Double.NaN, Double.NaN }
97                           }));
98          AbsoluteDate date =
99                  new AbsoluteDate(2004, 4, 6, 7, 51, 28.386009, TimeScalesFactory.getUTC());
100         DateTimeComponents components = date.getComponents(TimeScalesFactory.getTCB());
101         Assertions.assertEquals(2004,            components.getDate().getYear());
102         Assertions.assertEquals(   4,            components.getDate().getMonth());
103         Assertions.assertEquals(   6,            components.getDate().getDay());
104         Assertions.assertEquals(   7,            components.getTime().getHour());
105         Assertions.assertEquals(  52,            components.getTime().getMinute());
106 
107         // the "large" threshold in this test is due to the fact TDB model from which
108         // TCB is derived is approximated both in Orekit and in the reference paper.
109         // The difference is however small as the model in the paper is announced as
110         // being accurate to 50 micro seconds, and the test here is far below this value
111         Assertions.assertEquals(  45.9109901113, components.getTime().getSecond(), 1.2e-8);
112 
113     }
114 
115     @BeforeEach
116     public void setUp() {
117         Utils.setDataRoot("regular-data");
118     }
119 
120 }