1 /* Copyright 2002-2024 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.CalculusFieldElement;
20
21 /** GLONASS time scale.
22 * <p>By convention, TGLONASS = UTC + 3 hours.</p>
23 * <p>The time scale is defined in <a
24 * href="http://www.spacecorp.ru/upload/iblock/1c4/cgs-aaixymyt%205.1%20ENG%20v%202014.02.18w.pdf">
25 * Global Navigation Sattelite System GLONASS - Interface Control document</a>, version 5.1 2008
26 * (the typo in the title is in the original document title).
27 * </p>
28 * <p>This is intended to be accessed thanks to {@link TimeScales},
29 * so there is no public constructor.</p>
30 * @author Luc Maisonobe
31 * @see AbsoluteDate
32 */
33 public class GLONASSScale implements TimeScale {
34
35 /** Serializable UID. */
36 private static final long serialVersionUID = 20240720L;
37
38 /** Constant offset with respect to UTC (3 hours). */
39 private static final TimeOffset OFFSET = new TimeOffset(3, TimeOffset.HOUR);
40
41 /** Constant negative offset with respect to UTC (-3 hours). */
42 private static final TimeOffset NEGATIVE_OFFSET = OFFSET.negate();
43
44 /** UTC time scale. */
45 private final UTCScale utc;
46
47 /** Package private constructor for the factory.
48 * @param utc underlying UTC scale
49 */
50 GLONASSScale(final UTCScale utc) {
51 this.utc = utc;
52 }
53
54 /** {@inheritDoc} */
55 @Override
56 public TimeOffset offsetFromTAI(final AbsoluteDate date) {
57 return OFFSET.add(utc.offsetFromTAI(date));
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 public <T extends CalculusFieldElement<T>> T offsetFromTAI(final FieldAbsoluteDate<T> date) {
63 return utc.offsetFromTAI(date).add(OFFSET.toDouble());
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 public TimeOffset offsetToTAI(final DateComponents date, final TimeComponents time) {
69 final DateTimeComponents utcComponents =
70 new DateTimeComponents(new DateTimeComponents(date, time), NEGATIVE_OFFSET);
71 return utc.offsetToTAI(utcComponents.getDate(), utcComponents.getTime()).add(NEGATIVE_OFFSET);
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public boolean insideLeap(final AbsoluteDate date) {
77 return utc.insideLeap(date);
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public <T extends CalculusFieldElement<T>> boolean insideLeap(final FieldAbsoluteDate<T> date) {
83 return utc.insideLeap(date);
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public int minuteDuration(final AbsoluteDate date) {
89 return utc.minuteDuration(date);
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public <T extends CalculusFieldElement<T>> int minuteDuration(final FieldAbsoluteDate<T> date) {
95 return utc.minuteDuration(date);
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public TimeOffset getLeap(final AbsoluteDate date) {
101 return utc.getLeap(date);
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 public <T extends CalculusFieldElement<T>> T getLeap(final FieldAbsoluteDate<T> date) {
107 return utc.getLeap(date);
108 }
109
110 /** {@inheritDoc} */
111 public String getName() {
112 return "GLONASS";
113 }
114
115 /** {@inheritDoc} */
116 public String toString() {
117 return getName();
118 }
119
120 }