1   /* Copyright 2002-2022 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  
20  import org.junit.After;
21  import org.junit.Assert;
22  import org.junit.Before;
23  import org.junit.Test;
24  import org.orekit.Utils;
25  import org.orekit.utils.Constants;
26  import org.orekit.utils.IERSConventions;
27  
28  
29  public class GMSTScaleTest {
30  
31      @Test
32      // reference: http://www.astro.umd.edu/~jph/GST_eqn.pdf
33      public void testReference() {
34          Assert.assertEquals("GMST", gmst.toString());
35          AbsoluteDate date = new AbsoluteDate(2001, 10, 3, 6, 30, 0.0,
36                                               TimeScalesFactory.getUT1(IERSConventions.IERS_2010, true));
37          DateTimeComponents gmstComponents = date.getComponents(gmst);
38          Assert.assertEquals(2001,  gmstComponents.getDate().getYear());
39          Assert.assertEquals( 10,   gmstComponents.getDate().getMonth());
40          Assert.assertEquals(  3,   gmstComponents.getDate().getDay());
41          Assert.assertEquals(  7,   gmstComponents.getTime().getHour());
42          Assert.assertEquals( 18,   gmstComponents.getTime().getMinute());
43          Assert.assertEquals(8.329, gmstComponents.getTime().getSecond(), 4.0e-4);
44      }
45  
46      @Test
47      public void testSymmetry() {
48          for (double dt = -10000; dt < 10000; dt += 123.456789) {
49              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt * Constants.JULIAN_DAY);
50              double dt1 = gmst.offsetFromTAI(date);
51              DateTimeComponents components = date.getComponents(gmst);
52              double dt2 = gmst.offsetToTAI(components.getDate(), components.getTime());
53              Assert.assertEquals( 0.0, dt1 + dt2, 1.0e-10);
54          }
55      }
56  
57      @Test
58      public void testDuringLeap() {
59          final TimeScale utc   = TimeScalesFactory.getUTC();
60          final TimeScale scale = gmst;
61          final AbsoluteDate before = new AbsoluteDate(new DateComponents(1983, 06, 30),
62                                                       new TimeComponents(23, 59, 59),
63                                                       utc);
64          final AbsoluteDate during = before.shiftedBy(1.25);
65          Assert.assertEquals(61, utc.minuteDuration(during));
66          Assert.assertEquals(1.0, utc.getLeap(during), 1.0e-10);
67          Assert.assertEquals(60, scale.minuteDuration(during));
68          Assert.assertEquals(0.0, scale.getLeap(during), 1.0e-10);
69      }
70  
71      @Before
72      public void setUp() {
73          Utils.setDataRoot("regular-data");
74          gmst = TimeScalesFactory.getGMST(IERSConventions.IERS_2010, false);
75      }
76  
77      @After
78      public void tearDown() {
79          gmst = null;
80      }
81  
82      private TimeScale gmst;
83  
84  }