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.utils.Constants;
24  
25  public class QZSSScaleTest {
26  
27      @Test
28      public void testT0() {
29          TimeScale scale = TimeScalesFactory.getQZSS();
30          Assertions.assertEquals("QZSS", scale.toString());
31          AbsoluteDate t0 =
32              new AbsoluteDate(new DateComponents(1980, 1, 6), TimeComponents.H00, scale);
33          Assertions.assertEquals(AbsoluteDate.GPS_EPOCH, t0);
34      }
35  
36      @Test
37      public void testArbitrary() {
38          AbsoluteDate tQZSS =
39              new AbsoluteDate(new DateComponents(1999, 3, 4), TimeComponents.H00, TimeScalesFactory.getQZSS());
40          AbsoluteDate tUTC =
41              new AbsoluteDate(new DateComponents(1999, 3, 3), new TimeComponents(23, 59, 47),
42                               TimeScalesFactory.getUTC());
43          Assertions.assertEquals(tUTC, tQZSS);
44      }
45  
46      @Test
47      public void testConstant() {
48          TimeScale scale = TimeScalesFactory.getQZSS();
49          double reference = scale.offsetFromTAI(AbsoluteDate.J2000_EPOCH).toDouble();
50          for (double dt = -10000; dt < 10000; dt += 123.456789) {
51              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
52              Assertions.assertEquals(reference, scale.offsetFromTAI(date).toDouble(), 1.0e-15);
53          }
54      }
55  
56      @Test
57      public void testSymmetry() {
58          TimeScale scale = TimeScalesFactory.getQZSS();
59          for (double dt = -10000; dt < 10000; dt += 123.456789) {
60              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
61              double dt1 = scale.offsetFromTAI(date).toDouble();
62              DateTimeComponents components = date.getComponents(scale);
63              double dt2 = scale.offsetToTAI(components.getDate(), components.getTime()).toDouble();
64              Assertions.assertEquals( 0.0, dt1 + dt2, 1.0e-10);
65          }
66      }
67  
68      @Test
69      public void testDuringLeap() {
70          final TimeScale utc   = TimeScalesFactory.getUTC();
71          final TimeScale scale = TimeScalesFactory.getQZSS();
72          final AbsoluteDate before = new AbsoluteDate(new DateComponents(1983, 6, 30),
73                                                       new TimeComponents(23, 59, 59),
74                                                       utc);
75          final AbsoluteDate during = before.shiftedBy(1.25);
76          Assertions.assertEquals(61, utc.minuteDuration(during));
77          Assertions.assertEquals(1.0, utc.getLeap(during).toDouble(), 1.0e-10);
78          Assertions.assertEquals(60, scale.minuteDuration(during));
79          Assertions.assertEquals(0.0, scale.getLeap(during).toDouble(), 1.0e-10);
80      }
81  
82      @BeforeEach
83      public void setUp() {
84          Utils.setDataRoot("regular-data");
85      }
86  
87  }