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.hipparchus.util.Binary64;
20  import org.hipparchus.util.Binary64Field;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.Utils;
25  import org.orekit.utils.Constants;
26  
27  public class GalileoScaleTest {
28  
29      @Test
30      public void testT0() {
31          TimeScale scale = TimeScalesFactory.getGST();
32          Assertions.assertEquals("GST", scale.toString());
33          AbsoluteDate t0 =
34              new AbsoluteDate(new DateComponents(1999, 8, 22), TimeComponents.H00, scale);
35          Assertions.assertEquals(AbsoluteDate.GALILEO_EPOCH, t0);
36      }
37  
38      @Test
39      public void test2006() {
40          AbsoluteDate tGalileo =
41              new AbsoluteDate(new DateComponents(2006, 1, 2), TimeComponents.H00, TimeScalesFactory.getGST());
42          AbsoluteDate tUTC =
43              new AbsoluteDate(new DateComponents(2006, 1, 1), new TimeComponents(23, 59, 46),
44                               TimeScalesFactory.getUTC());
45          Assertions.assertEquals(tUTC, tGalileo);
46      }
47  
48      @Test
49      public void testDuringLeap() {
50          final TimeScale utc   = TimeScalesFactory.getUTC();
51          final TimeScale scale = TimeScalesFactory.getGST();
52          final AbsoluteDate before = new AbsoluteDate(new DateComponents(1983, 6, 30),
53                                                       new TimeComponents(23, 59, 59),
54                                                       utc);
55          final AbsoluteDate during = before.shiftedBy(1.25);
56          Assertions.assertEquals(61, utc.minuteDuration(during));
57          Assertions.assertEquals(1.0, utc.getLeap(during).toDouble(), 1.0e-10);
58          Assertions.assertEquals(60, scale.minuteDuration(during));
59          Assertions.assertEquals(0.0, scale.getLeap(during).toDouble(), 1.0e-10);
60      }
61  
62      @Test
63      public void testConstant() {
64          TimeScale scale = TimeScalesFactory.getGST();
65          double reference = scale.offsetFromTAI(AbsoluteDate.J2000_EPOCH).toDouble();
66          for (double dt = -10000; dt < 10000; dt += 123.456789) {
67              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
68              Assertions.assertEquals(reference, scale.offsetFromTAI(date).toDouble(), 1.0e-15);
69          }
70      }
71  
72      @Test
73      public void testField() {
74          TimeScale scale = TimeScalesFactory.getGST();
75          double reference = scale.offsetFromTAI(AbsoluteDate.J2000_EPOCH).toDouble();
76          final Binary64Field field = Binary64Field.getInstance();
77          for (double dt = -10000; dt < 10000; dt += 123.456789) {
78              FieldAbsoluteDate<Binary64> date = FieldAbsoluteDate.getJ2000Epoch(field).
79                                                 shiftedBy(dt * Constants.JULIAN_DAY);
80              Assertions.assertEquals(reference, scale.offsetFromTAI(date).getReal(), 1.0e-15);
81          }
82      }
83  
84      @Test
85      public void testSameAsGPS() {
86          TimeScale gst = TimeScalesFactory.getGST();
87          TimeScale gps = TimeScalesFactory.getGPS();
88          for (double dt = -10000; dt < 10000; dt += 123.456789) {
89              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
90              Assertions.assertEquals(gps.offsetFromTAI(date).toDouble(), gst.offsetFromTAI(date).toDouble(), 1.0e-15);
91          }
92      }
93  
94      @Test
95      public void testSymmetry() {
96          TimeScale scale = TimeScalesFactory.getGST();
97          for (double dt = -10000; dt < 10000; dt += 123.456789) {
98              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
99              double dt1 = scale.offsetFromTAI(date).toDouble();
100             DateTimeComponents components = date.getComponents(scale);
101             double dt2 = scale.offsetToTAI(components.getDate(), components.getTime()).toDouble();
102             Assertions.assertEquals( 0.0, dt1 + dt2, 1.0e-10);
103         }
104     }
105 
106     @BeforeEach
107     public void setUp() {
108         Utils.setDataRoot("regular-data");
109     }
110 
111 }