GLONASSScale.java

  1. /* Copyright 2002-2021 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. import org.hipparchus.CalculusFieldElement;

  19. /** GLONASS time scale.
  20.  * <p>By convention, TGLONASS = UTC + 3 hours.</p>
  21.  * <p>The time scale is defined in <a
  22.  * href="http://www.spacecorp.ru/upload/iblock/1c4/cgs-aaixymyt%205.1%20ENG%20v%202014.02.18w.pdf">
  23.  * Global Navigation Sattelite System GLONASS - Interface Control document</a>, version 5.1 2008
  24.  * (the typo in the title is in the original document title).
  25.  * </p>
  26.  * <p>This is intended to be accessed thanks to {@link TimeScales},
  27.  * so there is no public constructor.</p>
  28.  * @author Luc Maisonobe
  29.  * @see AbsoluteDate
  30.  */
  31. public class GLONASSScale implements TimeScale {

  32.     /** Serializable UID. */
  33.     private static final long serialVersionUID = 20160331L;

  34.     /** Constant offset with respect to UTC (3 hours). */
  35.     private static final double OFFSET = 10800;

  36.     /** UTC time scale. */
  37.     private final UTCScale utc;

  38.     /** Package private constructor for the factory.
  39.      * @param utc underlying UTC scale
  40.      */
  41.     GLONASSScale(final UTCScale utc) {
  42.         this.utc = utc;
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public double offsetFromTAI(final AbsoluteDate date) {
  47.         return OFFSET + utc.offsetFromTAI(date);
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     public <T extends CalculusFieldElement<T>> T offsetFromTAI(final FieldAbsoluteDate<T> date) {
  52.         return utc.offsetFromTAI(date).add(OFFSET);
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public double offsetToTAI(final DateComponents date, final TimeComponents time) {
  57.         final DateTimeComponents utcComponents =
  58.                         new DateTimeComponents(new DateTimeComponents(date, time), -OFFSET);
  59.         return utc.offsetToTAI(utcComponents.getDate(), utcComponents.getTime()) - OFFSET;
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public boolean insideLeap(final AbsoluteDate date) {
  64.         return utc.insideLeap(date);
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public <T extends CalculusFieldElement<T>> boolean insideLeap(final FieldAbsoluteDate<T> date) {
  69.         return utc.insideLeap(date);
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public int minuteDuration(final AbsoluteDate date) {
  74.         return utc.minuteDuration(date);
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public <T extends CalculusFieldElement<T>> int minuteDuration(final FieldAbsoluteDate<T> date) {
  79.         return utc.minuteDuration(date);
  80.     }

  81.     /** {@inheritDoc} */
  82.     @Override
  83.     public double getLeap(final AbsoluteDate date) {
  84.         return utc.getLeap(date);
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public <T extends CalculusFieldElement<T>> T getLeap(final FieldAbsoluteDate<T> date) {
  89.         return utc.getLeap(date);
  90.     }

  91.     /** {@inheritDoc} */
  92.     public String getName() {
  93.         return "GLONASS";
  94.     }

  95.     /** {@inheritDoc} */
  96.     public String toString() {
  97.         return getName();
  98.     }

  99. }