1   /* Copyright 2022-2025 Thales Alenia Space
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.hipparchus.util.FastMath;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.BeforeEach;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.Utils;
26  import org.orekit.estimation.measurements.QuadraticClockModel;
27  import org.orekit.gnss.TimeSystem;
28  
29  public class ClockTimeScaleTest {
30  
31      @Test
32      public void testGalileo() {
33          final String name = "Galileo+offset";
34          final AbsoluteDate        t0    = new AbsoluteDate(2020, 4, 1,
35                                                             TimeScalesFactory.getUTC());
36          final QuadraticClockModel clock = new QuadraticClockModel(t0,
37                                                                    FastMath.scalb(1.0, -10),
38                                                                    FastMath.scalb(1.0, -11),
39                                                                    FastMath.scalb(1.0, -12));
40          final ClockTimeScale positive = new ClockTimeScale(name,
41                                                             TimeSystem.GALILEO.getTimeScale(TimeScalesFactory.getTimeScales()),
42                                                             clock);
43          Assertions.assertEquals(name, positive.getName());
44          Assertions.assertEquals(1.00 / 1024.0 - 19.0, positive.offsetFromTAI(t0).toDouble(),                   1.0e-15);
45          Assertions.assertEquals(1.75 / 1024.0 - 19.0, positive.offsetFromTAI(t0.shiftedBy(1.0)).toDouble(), 1.0e-15);
46          Assertions.assertEquals(3.00 / 1024.0 - 19.0, positive.offsetFromTAI(t0.shiftedBy(2.0)).toDouble(), 1.0e-15);
47  
48          FieldAbsoluteDate<Binary64> t064 = new FieldAbsoluteDate<>(Binary64Field.getInstance(), t0);
49          Assertions.assertEquals(1.00 / 1024.0 - 19.0, positive.offsetFromTAI(t064).getReal(),                   1.0e-15);
50          Assertions.assertEquals(1.75 / 1024.0 - 19.0, positive.offsetFromTAI(t064.shiftedBy(1.0)).getReal(), 1.0e-15);
51          Assertions.assertEquals(3.00 / 1024.0 - 19.0, positive.offsetFromTAI(t064.shiftedBy(2.0)).getReal(), 1.0e-15);
52  
53      }
54  
55      @Test
56      public void testUTC() {
57          final String name = "UTC+offset";
58          final AbsoluteDate        t0    = new AbsoluteDate(2020, 4, 1,
59                                                             TimeScalesFactory.getUTC());
60          final QuadraticClockModel clock = new QuadraticClockModel(t0,
61                                                                    FastMath.scalb(1.0, -10),
62                                                                    FastMath.scalb(1.0, -11),
63                                                                    FastMath.scalb(1.0, -12));
64          final ClockTimeScale positive = new ClockTimeScale(name,
65                                                             TimeScalesFactory.getUTC(),
66                                                             clock);
67          Assertions.assertEquals(name, positive.getName());
68          Assertions.assertEquals(1.00 / 1024.0 - 37.0, positive.offsetFromTAI(t0).toDouble(),                1.0e-15);
69          Assertions.assertEquals(1.75 / 1024.0 - 37.0, positive.offsetFromTAI(t0.shiftedBy(1.0)).toDouble(), 1.0e-15);
70          Assertions.assertEquals(3.00 / 1024.0 - 37.0, positive.offsetFromTAI(t0.shiftedBy(2.0)).toDouble(), 1.0e-15);
71  
72          FieldAbsoluteDate<Binary64> t064 = new FieldAbsoluteDate<>(Binary64Field.getInstance(), t0);
73          Assertions.assertEquals(1.00 / 1024.0 - 37.0, positive.offsetFromTAI(t064).getReal(),                1.0e-15);
74          Assertions.assertEquals(1.75 / 1024.0 - 37.0, positive.offsetFromTAI(t064.shiftedBy(1.0)).getReal(), 1.0e-15);
75          Assertions.assertEquals(3.00 / 1024.0 - 37.0, positive.offsetFromTAI(t064.shiftedBy(2.0)).getReal(), 1.0e-15);
76  
77      }
78  
79      @BeforeEach
80      public void setUp() throws Exception {
81          Utils.setDataRoot("regular-data");
82      }
83  
84  }