AbsoluteDate.java

  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. import java.io.Serializable;
  19. import java.time.Instant;
  20. import java.util.Date;
  21. import java.util.TimeZone;

  22. import org.hipparchus.util.FastMath;
  23. import org.hipparchus.util.MathUtils;
  24. import org.hipparchus.util.MathUtils.SumAndResidual;
  25. import org.orekit.annotation.DefaultDataContext;
  26. import org.orekit.data.DataContext;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitIllegalArgumentException;
  29. import org.orekit.errors.OrekitMessages;
  30. import org.orekit.utils.Constants;


  31. /** This class represents a specific instant in time.

  32.  * <p>Instances of this class are considered to be absolute in the sense
  33.  * that each one represent the occurrence of some event and can be compared
  34.  * to other instances or located in <em>any</em> {@link TimeScale time scale}. In
  35.  * other words the different locations of an event with respect to two different
  36.  * time scales (say {@link TAIScale TAI} and {@link UTCScale UTC} for example) are
  37.  * simply different perspective related to a single object. Only one
  38.  * <code>AbsoluteDate</code> instance is needed, both representations being available
  39.  * from this single instance by specifying the time scales as parameter when calling
  40.  * the ad-hoc methods.</p>
  41.  *
  42.  * <p>Since an instance is not bound to a specific time-scale, all methods related
  43.  * to the location of the date within some time scale require to provide the time
  44.  * scale as an argument. It is therefore possible to define a date in one time scale
  45.  * and to use it in another one. An example of such use is to read a date from a file
  46.  * in UTC and write it in another file in TAI. This can be done as follows:</p>
  47.  * <pre>
  48.  *   DateTimeComponents utcComponents = readNextDate();
  49.  *   AbsoluteDate date = new AbsoluteDate(utcComponents, TimeScalesFactory.getUTC());
  50.  *   writeNextDate(date.getComponents(TimeScalesFactory.getTAI()));
  51.  * </pre>
  52.  *
  53.  * <p>Two complementary views are available:</p>
  54.  * <ul>
  55.  *   <li><p>location view (mainly for input/output or conversions)</p>
  56.  *   <p>locations represent the coordinate of one event with respect to a
  57.  *   {@link TimeScale time scale}. The related methods are {@link
  58.  *   #AbsoluteDate(DateComponents, TimeComponents, TimeScale)}, {@link
  59.  *   #AbsoluteDate(int, int, int, int, int, double, TimeScale)}, {@link
  60.  *   #AbsoluteDate(int, int, int, TimeScale)}, {@link #AbsoluteDate(Date,
  61.  *   TimeScale)}, {@link #parseCCSDSCalendarSegmentedTimeCode(byte, byte[])},
  62.  *   {@link #toDate(TimeScale)}, {@link #toString(TimeScale) toString(timeScale)},
  63.  *   {@link #toString()}, and {@link #timeScalesOffset}.</p>
  64.  *   </li>
  65.  *   <li><p>offset view (mainly for physical computation)</p>
  66.  *   <p>offsets represent either the flow of time between two events
  67.  *   (two instances of the class) or durations. They are counted in seconds,
  68.  *   are continuous and could be measured using only a virtually perfect stopwatch.
  69.  *   The related methods are {@link #AbsoluteDate(AbsoluteDate, double)},
  70.  *   {@link #parseCCSDSUnsegmentedTimeCode(byte, byte, byte[], AbsoluteDate)},
  71.  *   {@link #parseCCSDSDaySegmentedTimeCode(byte, byte[], DateComponents)},
  72.  *   {@link #durationFrom(AbsoluteDate)}, {@link #compareTo(AbsoluteDate)}, {@link #equals(Object)}
  73.  *   and {@link #hashCode()}.</p>
  74.  *   </li>
  75.  * </ul>
  76.  * <p>
  77.  * A few reference epochs which are commonly used in space systems have been defined. These
  78.  * epochs can be used as the basis for offset computation. The supported epochs are:
  79.  * {@link #JULIAN_EPOCH}, {@link #MODIFIED_JULIAN_EPOCH}, {@link #FIFTIES_EPOCH},
  80.  * {@link #CCSDS_EPOCH}, {@link #GALILEO_EPOCH}, {@link #GPS_EPOCH}, {@link #QZSS_EPOCH}
  81.  * {@link #J2000_EPOCH}, {@link #JAVA_EPOCH}.
  82.  * There are also two factory methods {@link #createJulianEpoch(double)}
  83.  * and {@link #createBesselianEpoch(double)} that can be used to compute other reference
  84.  * epochs like J1900.0 or B1950.0.
  85.  * In addition to these reference epochs, two other constants are defined for convenience:
  86.  * {@link #PAST_INFINITY} and {@link #FUTURE_INFINITY}, which can be used either as dummy
  87.  * dates when a date is not yet initialized, or for initialization of loops searching for
  88.  * a min or max date.
  89.  * </p>
  90.  * <p>
  91.  * Instances of the <code>AbsoluteDate</code> class are guaranteed to be immutable.
  92.  * </p>
  93.  * @author Luc Maisonobe
  94.  * @author Evan Ward
  95.  * @see TimeScale
  96.  * @see TimeStamped
  97.  * @see ChronologicalComparator
  98.  */
  99. public class AbsoluteDate
  100.     implements TimeStamped, TimeShiftable<AbsoluteDate>, Comparable<AbsoluteDate>, Serializable {

  101.     /** Reference epoch for julian dates: -4712-01-01T12:00:00 Terrestrial Time.
  102.      * <p>Both <code>java.util.Date</code> and {@link DateComponents} classes
  103.      * follow the astronomical conventions and consider a year 0 between
  104.      * years -1 and +1, hence this reference date lies in year -4712 and not
  105.      * in year -4713 as can be seen in other documents or programs that obey
  106.      * a different convention (for example the <code>convcal</code> utility).</p>
  107.      *
  108.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  109.      *
  110.      * @see TimeScales#getJulianEpoch()
  111.      */
  112.     @DefaultDataContext
  113.     public static final AbsoluteDate JULIAN_EPOCH =
  114.             DataContext.getDefault().getTimeScales().getJulianEpoch();

  115.     /** Reference epoch for modified julian dates: 1858-11-17T00:00:00 Terrestrial Time.
  116.      *
  117.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  118.      *
  119.      * @see TimeScales#getModifiedJulianEpoch()
  120.      */
  121.     @DefaultDataContext
  122.     public static final AbsoluteDate MODIFIED_JULIAN_EPOCH =
  123.             DataContext.getDefault().getTimeScales().getModifiedJulianEpoch();

  124.     /** Reference epoch for 1950 dates: 1950-01-01T00:00:00 Terrestrial Time.
  125.      *
  126.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  127.      *
  128.      * @see TimeScales#getFiftiesEpoch()
  129.      */
  130.     @DefaultDataContext
  131.     public static final AbsoluteDate FIFTIES_EPOCH =
  132.             DataContext.getDefault().getTimeScales().getFiftiesEpoch();

  133.     /** Reference epoch for CCSDS Time Code Format (CCSDS 301.0-B-4):
  134.      * 1958-01-01T00:00:00 International Atomic Time (<em>not</em> UTC).
  135.      *
  136.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  137.      *
  138.      * @see TimeScales#getCcsdsEpoch()
  139.      */
  140.     @DefaultDataContext
  141.     public static final AbsoluteDate CCSDS_EPOCH =
  142.             DataContext.getDefault().getTimeScales().getCcsdsEpoch();

  143.     /** Reference epoch for Galileo System Time: 1999-08-22T00:00:00 GST.
  144.      *
  145.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  146.      *
  147.      * @see TimeScales#getGalileoEpoch()
  148.      */
  149.     @DefaultDataContext
  150.     public static final AbsoluteDate GALILEO_EPOCH =
  151.             DataContext.getDefault().getTimeScales().getGalileoEpoch();

  152.     /** Reference epoch for GPS weeks: 1980-01-06T00:00:00 GPS time.
  153.      *
  154.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  155.      *
  156.      * @see TimeScales#getGpsEpoch()
  157.      */
  158.     @DefaultDataContext
  159.     public static final AbsoluteDate GPS_EPOCH =
  160.             DataContext.getDefault().getTimeScales().getGpsEpoch();

  161.     /** Reference epoch for QZSS weeks: 1980-01-06T00:00:00 QZSS time.
  162.      *
  163.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  164.      *
  165.      * @see TimeScales#getQzssEpoch()
  166.      */
  167.     @DefaultDataContext
  168.     public static final AbsoluteDate QZSS_EPOCH =
  169.             DataContext.getDefault().getTimeScales().getQzssEpoch();

  170.     /** Reference epoch for IRNSS weeks: 1999-08-22T00:00:00 IRNSS time.
  171.      *
  172.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  173.      *
  174.      * @see TimeScales#getIrnssEpoch()
  175.      */
  176.     @DefaultDataContext
  177.     public static final AbsoluteDate IRNSS_EPOCH =
  178.             DataContext.getDefault().getTimeScales().getIrnssEpoch();

  179.     /** Reference epoch for BeiDou weeks: 2006-01-01T00:00:00 UTC.
  180.      *
  181.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  182.      *
  183.      * @see TimeScales#getBeidouEpoch()
  184.      */
  185.     @DefaultDataContext
  186.     public static final AbsoluteDate BEIDOU_EPOCH =
  187.             DataContext.getDefault().getTimeScales().getBeidouEpoch();

  188.     /** Reference epoch for GLONASS four-year interval number: 1996-01-01T00:00:00 GLONASS time.
  189.      * <p>By convention, TGLONASS = UTC + 3 hours.</p>
  190.      *
  191.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  192.      *
  193.      * @see TimeScales#getGlonassEpoch()
  194.      */
  195.     @DefaultDataContext
  196.     public static final AbsoluteDate GLONASS_EPOCH =
  197.             DataContext.getDefault().getTimeScales().getGlonassEpoch();

  198.     /** J2000.0 Reference epoch: 2000-01-01T12:00:00 Terrestrial Time (<em>not</em> UTC).
  199.      *
  200.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  201.      *
  202.      * @see #createJulianEpoch(double)
  203.      * @see #createBesselianEpoch(double)
  204.      * @see TimeScales#getJ2000Epoch()
  205.      */
  206.     @DefaultDataContext
  207.     public static final AbsoluteDate J2000_EPOCH = // TODO
  208.             DataContext.getDefault().getTimeScales().getJ2000Epoch();

  209.     /** Java Reference epoch: 1970-01-01T00:00:00 Universal Time Coordinate.
  210.      * <p>
  211.      * Between 1968-02-01 and 1972-01-01, UTC-TAI = 4.213 170 0s + (MJD - 39 126) x 0.002 592s.
  212.      * As on 1970-01-01 MJD = 40587, UTC-TAI = 8.000082s
  213.      * </p>
  214.      *
  215.      * <p>This constant uses the {@link DataContext#getDefault() default data context}.
  216.      *
  217.      * @see TimeScales#getJavaEpoch()
  218.      */
  219.     @DefaultDataContext
  220.     public static final AbsoluteDate JAVA_EPOCH =
  221.             DataContext.getDefault().getTimeScales().getJavaEpoch();

  222.     /**
  223.      * An arbitrary finite date. Uses when a non-null date is needed but its value doesn't
  224.      * matter.
  225.      */
  226.     public static final AbsoluteDate ARBITRARY_EPOCH = new AbsoluteDate(0, 0);

  227.     /** Dummy date at infinity in the past direction.
  228.      * @see TimeScales#getPastInfinity()
  229.      */
  230.     public static final AbsoluteDate PAST_INFINITY = ARBITRARY_EPOCH.shiftedBy(Double.NEGATIVE_INFINITY);

  231.     /** Dummy date at infinity in the future direction.
  232.      * @see TimeScales#getFutureInfinity()
  233.      */
  234.     public static final AbsoluteDate FUTURE_INFINITY = ARBITRARY_EPOCH.shiftedBy(Double.POSITIVE_INFINITY);

  235.     /** Serializable UID. */
  236.     private static final long serialVersionUID = 617061803741806846L;

  237.     /** Reference epoch in seconds from 2000-01-01T12:00:00 TAI.
  238.      * <p>Beware, it is not {@link #J2000_EPOCH} since it is in TAI and not in TT.</p> */
  239.     private final long epoch;

  240.     /** Offset from the reference epoch in seconds. */
  241.     private final double offset;

  242.     /** Create an instance with a default value ({@link #J2000_EPOCH}).
  243.      *
  244.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  245.      *
  246.      * @see #AbsoluteDate(DateTimeComponents, TimeScale)
  247.      */
  248.     @DefaultDataContext
  249.     public AbsoluteDate() {
  250.         epoch  = J2000_EPOCH.epoch;
  251.         offset = J2000_EPOCH.offset;
  252.     }

  253.     /** Build an instance from a location (parsed from a string) in a {@link TimeScale time scale}.
  254.      * <p>
  255.      * The supported formats for location are mainly the ones defined in ISO-8601 standard,
  256.      * the exact subset is explained in {@link DateTimeComponents#parseDateTime(String)},
  257.      * {@link DateComponents#parseDate(String)} and {@link TimeComponents#parseTime(String)}.
  258.      * </p>
  259.      * <p>
  260.      * As CCSDS ASCII calendar segmented time code is a trimmed down version of ISO-8601,
  261.      * it is also supported by this constructor.
  262.      * </p>
  263.      * @param location location in the time scale, must be in a supported format
  264.      * @param timeScale time scale
  265.      * @exception IllegalArgumentException if location string is not in a supported format
  266.      */
  267.     public AbsoluteDate(final String location, final TimeScale timeScale) {
  268.         this(DateTimeComponents.parseDateTime(location), timeScale);
  269.     }

  270.     /** Build an instance from a location in a {@link TimeScale time scale}.
  271.      * @param location location in the time scale
  272.      * @param timeScale time scale
  273.      */
  274.     public AbsoluteDate(final DateTimeComponents location, final TimeScale timeScale) {
  275.         this(location.getDate(), location.getTime(), timeScale);
  276.     }

  277.     /** Build an instance from a location in a {@link TimeScale time scale}.
  278.      * @param date date location in the time scale
  279.      * @param time time location in the time scale
  280.      * @param timeScale time scale
  281.      */
  282.     public AbsoluteDate(final DateComponents date, final TimeComponents time,
  283.                         final TimeScale timeScale) {

  284.         final double seconds  = time.getSecond();
  285.         final double tsOffset = timeScale.offsetToTAI(date, time);

  286.         // Use 2Sum for high precision.
  287.         final SumAndResidual sumAndResidual = MathUtils.twoSum(seconds, tsOffset);
  288.         final long dl = (long) FastMath.floor(sumAndResidual.getSum());
  289.         final double regularOffset = (sumAndResidual.getSum() - dl) + sumAndResidual.getResidual();

  290.         if (regularOffset >= 0) {
  291.             // regular case, the offset is between 0.0 and 1.0
  292.             offset = regularOffset;
  293.             epoch  = 60l * ((date.getJ2000Day() * 24l + time.getHour()) * 60l +
  294.                             time.getMinute() - time.getMinutesFromUTC() - 720l) + dl;
  295.         } else {
  296.             // very rare case, the offset is just before a whole second
  297.             // we will loose some bits of accuracy when adding 1 second
  298.             // but this will ensure the offset remains in the [0.0; 1.0] interval
  299.             offset = 1.0 + regularOffset;
  300.             epoch  = 60l * ((date.getJ2000Day() * 24l + time.getHour()) * 60l +
  301.                             time.getMinute() - time.getMinutesFromUTC() - 720l) + dl - 1;
  302.         }

  303.     }

  304.     /** Build an instance from a location in a {@link TimeScale time scale}.
  305.      * @param year year number (may be 0 or negative for BC years)
  306.      * @param month month number from 1 to 12
  307.      * @param day day number from 1 to 31
  308.      * @param hour hour number from 0 to 23
  309.      * @param minute minute number from 0 to 59
  310.      * @param second second number from 0.0 to 60.0 (excluded)
  311.      * @param timeScale time scale
  312.      * @exception IllegalArgumentException if inconsistent arguments
  313.      * are given (parameters out of range)
  314.      */
  315.     public AbsoluteDate(final int year, final int month, final int day,
  316.                         final int hour, final int minute, final double second,
  317.                         final TimeScale timeScale) throws IllegalArgumentException {
  318.         this(new DateComponents(year, month, day), new TimeComponents(hour, minute, second), timeScale);
  319.     }

  320.     /** Build an instance from a location in a {@link TimeScale time scale}.
  321.      * @param year year number (may be 0 or negative for BC years)
  322.      * @param month month enumerate
  323.      * @param day day number from 1 to 31
  324.      * @param hour hour number from 0 to 23
  325.      * @param minute minute number from 0 to 59
  326.      * @param second second number from 0.0 to 60.0 (excluded)
  327.      * @param timeScale time scale
  328.      * @exception IllegalArgumentException if inconsistent arguments
  329.      * are given (parameters out of range)
  330.      */
  331.     public AbsoluteDate(final int year, final Month month, final int day,
  332.                         final int hour, final int minute, final double second,
  333.                         final TimeScale timeScale) throws IllegalArgumentException {
  334.         this(new DateComponents(year, month, day), new TimeComponents(hour, minute, second), timeScale);
  335.     }

  336.     /** Build an instance from a location in a {@link TimeScale time scale}.
  337.      * <p>The hour is set to 00:00:00.000.</p>
  338.      * @param date date location in the time scale
  339.      * @param timeScale time scale
  340.      * @exception IllegalArgumentException if inconsistent arguments
  341.      * are given (parameters out of range)
  342.      */
  343.     public AbsoluteDate(final DateComponents date, final TimeScale timeScale)
  344.         throws IllegalArgumentException {
  345.         this(date, TimeComponents.H00, timeScale);
  346.     }

  347.     /** Build an instance from a location in a {@link TimeScale time scale}.
  348.      * <p>The hour is set to 00:00:00.000.</p>
  349.      * @param year year number (may be 0 or negative for BC years)
  350.      * @param month month number from 1 to 12
  351.      * @param day day number from 1 to 31
  352.      * @param timeScale time scale
  353.      * @exception IllegalArgumentException if inconsistent arguments
  354.      * are given (parameters out of range)
  355.      */
  356.     public AbsoluteDate(final int year, final int month, final int day,
  357.                         final TimeScale timeScale) throws IllegalArgumentException {
  358.         this(new DateComponents(year, month, day), TimeComponents.H00, timeScale);
  359.     }

  360.     /** Build an instance from a location in a {@link TimeScale time scale}.
  361.      * <p>The hour is set to 00:00:00.000.</p>
  362.      * @param year year number (may be 0 or negative for BC years)
  363.      * @param month month enumerate
  364.      * @param day day number from 1 to 31
  365.      * @param timeScale time scale
  366.      * @exception IllegalArgumentException if inconsistent arguments
  367.      * are given (parameters out of range)
  368.      */
  369.     public AbsoluteDate(final int year, final Month month, final int day,
  370.                         final TimeScale timeScale) throws IllegalArgumentException {
  371.         this(new DateComponents(year, month, day), TimeComponents.H00, timeScale);
  372.     }

  373.     /** Build an instance from a location in a {@link TimeScale time scale}.
  374.      * @param location location in the time scale
  375.      * @param timeScale time scale
  376.      */
  377.     public AbsoluteDate(final Date location, final TimeScale timeScale) {
  378.         this(new DateComponents(DateComponents.JAVA_EPOCH,
  379.                                 (int) (location.getTime() / 86400000l)),
  380.                                  millisToTimeComponents((int) (location.getTime() % 86400000l)),
  381.              timeScale);
  382.     }

  383.     /** Build an instance from an {@link Instant instant} in a {@link TimeScale time scale}.
  384.      * @param instant instant in the time scale
  385.      * @param timeScale time scale
  386.      * @since 12.0
  387.      */
  388.     public AbsoluteDate(final Instant instant, final TimeScale timeScale) {
  389.         this(new DateComponents(DateComponents.JAVA_EPOCH,
  390.                                 (int) (instant.getEpochSecond() / 86400l)),
  391.              instantToTimeComponents(instant),
  392.              timeScale);
  393.     }

  394.     /** Build an instance from an elapsed duration since to another instant.
  395.      * <p>It is important to note that the elapsed duration is <em>not</em>
  396.      * the difference between two readings on a time scale. As an example,
  397.      * the duration between the two instants leading to the readings
  398.      * 2005-12-31T23:59:59 and 2006-01-01T00:00:00 in the {@link UTCScale UTC}
  399.      * time scale is <em>not</em> 1 second, but a stop watch would have measured
  400.      * an elapsed duration of 2 seconds between these two instances because a leap
  401.      * second was introduced at the end of 2005 in this time scale.</p>
  402.      * <p>This constructor is the reverse of the {@link #durationFrom(AbsoluteDate)}
  403.      * method.</p>
  404.      * @param since start instant of the measured duration
  405.      * @param elapsedDuration physically elapsed duration from the <code>since</code>
  406.      * instant, as measured in a regular time scale
  407.      * @see #durationFrom(AbsoluteDate)
  408.      */
  409.     public AbsoluteDate(final AbsoluteDate since, final double elapsedDuration) {
  410.         // Use 2Sum for high precision.
  411.         final SumAndResidual sumAndResidual = MathUtils.twoSum(since.offset, elapsedDuration);
  412.         if (Double.isInfinite(sumAndResidual.getSum())) {
  413.             offset = sumAndResidual.getSum();
  414.             epoch  = (sumAndResidual.getSum() < 0) ? Long.MIN_VALUE : Long.MAX_VALUE;
  415.         } else {
  416.             final long dl = (long) FastMath.floor(sumAndResidual.getSum());
  417.             final double regularOffset = (sumAndResidual.getSum() - dl) + sumAndResidual.getResidual();
  418.             if (regularOffset >= 0) {
  419.                 // regular case, the offset is between 0.0 and 1.0
  420.                 offset = regularOffset;
  421.                 epoch  = since.epoch + dl;
  422.             } else {
  423.                 // very rare case, the offset is just before a whole second
  424.                 // we will loose some bits of accuracy when adding 1 second
  425.                 // but this will ensure the offset remains in the [0.0; 1.0] interval
  426.                 offset = 1.0 + regularOffset;
  427.                 epoch  = since.epoch + dl - 1;
  428.             }
  429.         }
  430.     }

  431.     /** Build an instance from an apparent clock offset with respect to another
  432.      * instant <em>in the perspective of a specific {@link TimeScale time scale}</em>.
  433.      * <p>It is important to note that the apparent clock offset <em>is</em> the
  434.      * difference between two readings on a time scale and <em>not</em> an elapsed
  435.      * duration. As an example, the apparent clock offset between the two instants
  436.      * leading to the readings 2005-12-31T23:59:59 and 2006-01-01T00:00:00 in the
  437.      * {@link UTCScale UTC} time scale is 1 second, but the elapsed duration is 2
  438.      * seconds because a leap second has been introduced at the end of 2005 in this
  439.      * time scale.</p>
  440.      * <p>This constructor is the reverse of the {@link #offsetFrom(AbsoluteDate,
  441.      * TimeScale)} method.</p>
  442.      * @param reference reference instant
  443.      * @param apparentOffset apparent clock offset from the reference instant
  444.      * (difference between two readings in the specified time scale)
  445.      * @param timeScale time scale with respect to which the offset is defined
  446.      * @see #offsetFrom(AbsoluteDate, TimeScale)
  447.      */
  448.     public AbsoluteDate(final AbsoluteDate reference, final double apparentOffset,
  449.                         final TimeScale timeScale) {
  450.         this(new DateTimeComponents(reference.getComponents(timeScale), apparentOffset),
  451.              timeScale);
  452.     }

  453.     /** Build a date from its internal components.
  454.      * <p>
  455.      * This method is reserved for internal used (for example by {@link FieldAbsoluteDate}).
  456.      * </p>
  457.      * @param epoch reference epoch in seconds from 2000-01-01T12:00:00 TAI.
  458.      * (beware, it is not {@link #J2000_EPOCH} since it is in TAI and not in TT)
  459.      * @param offset offset from the reference epoch in seconds (must be
  460.      * between 0.0 included and 1.0 excluded)
  461.      * @since 9.0
  462.      */
  463.     AbsoluteDate(final long epoch, final double offset) {
  464.         this.epoch  = epoch;
  465.         this.offset = offset;
  466.     }

  467.     /** Extract time components from a number of milliseconds within the day.
  468.      * @param millisInDay number of milliseconds within the day
  469.      * @return time components
  470.      */
  471.     private static TimeComponents millisToTimeComponents(final int millisInDay) {
  472.         return new TimeComponents(millisInDay / 1000, 0.001 * (millisInDay % 1000));
  473.     }

  474.     /** Extract time components from an instant within the day.
  475.      * @param instant instant to extract the number of seconds within the day
  476.      * @return time components
  477.      */
  478.     private static TimeComponents instantToTimeComponents(final Instant instant) {
  479.         final int secInDay = (int) (instant.getEpochSecond() % 86400l);
  480.         return new TimeComponents(secInDay, 1.0e-9 * instant.getNano());
  481.     }

  482.     /** Get the reference epoch in seconds from 2000-01-01T12:00:00 TAI.
  483.      * <p>
  484.      * This method is reserved for internal used (for example by {@link FieldAbsoluteDate}).
  485.      * </p>
  486.      * <p>
  487.      * Beware, it is not {@link #J2000_EPOCH} since it is in TAI and not in TT.
  488.      * </p>
  489.      * @return reference epoch in seconds from 2000-01-01T12:00:00 TAI
  490.      * @since 9.0
  491.      */
  492.     long getEpoch() {
  493.         return epoch;
  494.     }

  495.     /** Get the offset from the reference epoch in seconds.
  496.      * <p>
  497.      * This method is reserved for internal used (for example by {@link FieldAbsoluteDate}).
  498.      * </p>
  499.      * @return offset from the reference epoch in seconds
  500.      * @since 9.0
  501.      */
  502.     double getOffset() {
  503.         return offset;
  504.     }

  505.     /** Build an instance from a CCSDS Unsegmented Time Code (CUC).
  506.      * <p>
  507.      * CCSDS Unsegmented Time Code is defined in the blue book:
  508.      * CCSDS Time Code Format (CCSDS 301.0-B-4) published in November 2010
  509.      * </p>
  510.      * <p>
  511.      * If the date to be parsed is formatted using version 3 of the standard
  512.      * (CCSDS 301.0-B-3 published in 2002) or if the extension of the preamble
  513.      * field introduced in version 4 of the standard is not used, then the
  514.      * {@code preambleField2} parameter can be set to 0.
  515.      * </p>
  516.      *
  517.      * <p>This method uses the {@link DataContext#getDefault() default data context} if
  518.      * the CCSDS epoch is used.
  519.      *
  520.      * @param preambleField1 first byte of the field specifying the format, often
  521.      * not transmitted in data interfaces, as it is constant for a given data interface
  522.      * @param preambleField2 second byte of the field specifying the format
  523.      * (added in revision 4 of the CCSDS standard in 2010), often not transmitted in data
  524.      * interfaces, as it is constant for a given data interface (value ignored if presence
  525.      * not signaled in {@code preambleField1})
  526.      * @param timeField byte array containing the time code
  527.      * @param agencyDefinedEpoch reference epoch, ignored if the preamble field
  528.      * specifies the {@link #CCSDS_EPOCH CCSDS reference epoch} is used (and hence
  529.      * may be null in this case)
  530.      * @return an instance corresponding to the specified date
  531.      * @see #parseCCSDSUnsegmentedTimeCode(byte, byte, byte[], AbsoluteDate, AbsoluteDate)
  532.      */
  533.     @DefaultDataContext
  534.     public static AbsoluteDate parseCCSDSUnsegmentedTimeCode(final byte preambleField1,
  535.                                                              final byte preambleField2,
  536.                                                              final byte[] timeField,
  537.                                                              final AbsoluteDate agencyDefinedEpoch) {
  538.         return parseCCSDSUnsegmentedTimeCode(preambleField1, preambleField2, timeField,
  539.                 agencyDefinedEpoch,
  540.                 DataContext.getDefault().getTimeScales().getCcsdsEpoch());
  541.     }

  542.     /**
  543.      * Build an instance from a CCSDS Unsegmented Time Code (CUC).
  544.      * <p>
  545.      * CCSDS Unsegmented Time Code is defined in the blue book: CCSDS Time Code Format
  546.      * (CCSDS 301.0-B-4) published in November 2010
  547.      * </p>
  548.      * <p>
  549.      * If the date to be parsed is formatted using version 3 of the standard (CCSDS
  550.      * 301.0-B-3 published in 2002) or if the extension of the preamble field introduced
  551.      * in version 4 of the standard is not used, then the {@code preambleField2} parameter
  552.      * can be set to 0.
  553.      * </p>
  554.      *
  555.      * @param preambleField1     first byte of the field specifying the format, often not
  556.      *                           transmitted in data interfaces, as it is constant for a
  557.      *                           given data interface
  558.      * @param preambleField2     second byte of the field specifying the format (added in
  559.      *                           revision 4 of the CCSDS standard in 2010), often not
  560.      *                           transmitted in data interfaces, as it is constant for a
  561.      *                           given data interface (value ignored if presence not
  562.      *                           signaled in {@code preambleField1})
  563.      * @param timeField          byte array containing the time code
  564.      * @param agencyDefinedEpoch reference epoch, ignored if the preamble field specifies
  565.      *                           the {@link #CCSDS_EPOCH CCSDS reference epoch} is used
  566.      *                           (and hence may be null in this case)
  567.      * @param ccsdsEpoch         reference epoch, ignored if the preamble field specifies
  568.      *                           the agency epoch is used.
  569.      * @return an instance corresponding to the specified date
  570.      * @since 10.1
  571.      */
  572.     public static AbsoluteDate parseCCSDSUnsegmentedTimeCode(
  573.             final byte preambleField1,
  574.             final byte preambleField2,
  575.             final byte[] timeField,
  576.             final AbsoluteDate agencyDefinedEpoch,
  577.             final AbsoluteDate ccsdsEpoch) {

  578.         // time code identification and reference epoch
  579.         final AbsoluteDate epoch;
  580.         switch (preambleField1 & 0x70) {
  581.             case 0x10:
  582.                 // the reference epoch is CCSDS epoch 1958-01-01T00:00:00 TAI
  583.                 epoch = ccsdsEpoch;
  584.                 break;
  585.             case 0x20:
  586.                 // the reference epoch is agency defined
  587.                 if (agencyDefinedEpoch == null) {
  588.                     throw new OrekitException(OrekitMessages.CCSDS_DATE_MISSING_AGENCY_EPOCH);
  589.                 }
  590.                 epoch = agencyDefinedEpoch;
  591.                 break;
  592.             default :
  593.                 throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD,
  594.                                           formatByte(preambleField1));
  595.         }

  596.         // time field lengths
  597.         int coarseTimeLength = 1 + ((preambleField1 & 0x0C) >>> 2);
  598.         int fineTimeLength   = preambleField1 & 0x03;

  599.         if ((preambleField1 & 0x80) != 0x0) {
  600.             // there is an additional octet in preamble field
  601.             coarseTimeLength += (preambleField2 & 0x60) >>> 5;
  602.             fineTimeLength   += (preambleField2 & 0x1C) >>> 2;
  603.         }

  604.         if (timeField.length != coarseTimeLength + fineTimeLength) {
  605.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_LENGTH_TIME_FIELD,
  606.                                       timeField.length, coarseTimeLength + fineTimeLength);
  607.         }

  608.         double seconds = 0;
  609.         for (int i = 0; i < coarseTimeLength; ++i) {
  610.             seconds = seconds * 256 + toUnsigned(timeField[i]);
  611.         }
  612.         double subseconds = 0;
  613.         for (int i = timeField.length - 1; i >= coarseTimeLength; --i) {
  614.             subseconds = (subseconds + toUnsigned(timeField[i])) / 256;
  615.         }

  616.         return new AbsoluteDate(epoch, seconds).shiftedBy(subseconds);

  617.     }

  618.     /** Build an instance from a CCSDS Day Segmented Time Code (CDS).
  619.      * <p>
  620.      * CCSDS Day Segmented Time Code is defined in the blue book:
  621.      * CCSDS Time Code Format (CCSDS 301.0-B-4) published in November 2010
  622.      * </p>
  623.      *
  624.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  625.      *
  626.      * @param preambleField field specifying the format, often not transmitted in
  627.      * data interfaces, as it is constant for a given data interface
  628.      * @param timeField byte array containing the time code
  629.      * @param agencyDefinedEpoch reference epoch, ignored if the preamble field
  630.      * specifies the {@link #CCSDS_EPOCH CCSDS reference epoch} is used (and hence
  631.      * may be null in this case)
  632.      * @return an instance corresponding to the specified date
  633.      * @see #parseCCSDSDaySegmentedTimeCode(byte, byte[], DateComponents, TimeScale)
  634.      */
  635.     @DefaultDataContext
  636.     public static AbsoluteDate parseCCSDSDaySegmentedTimeCode(final byte preambleField, final byte[] timeField,
  637.                                                               final DateComponents agencyDefinedEpoch) {
  638.         return parseCCSDSDaySegmentedTimeCode(preambleField, timeField,
  639.                 agencyDefinedEpoch, DataContext.getDefault().getTimeScales().getUTC());
  640.     }

  641.     /** Build an instance from a CCSDS Day Segmented Time Code (CDS).
  642.      * <p>
  643.      * CCSDS Day Segmented Time Code is defined in the blue book:
  644.      * CCSDS Time Code Format (CCSDS 301.0-B-4) published in November 2010
  645.      * </p>
  646.      * @param preambleField field specifying the format, often not transmitted in
  647.      * data interfaces, as it is constant for a given data interface
  648.      * @param timeField byte array containing the time code
  649.      * @param agencyDefinedEpoch reference epoch, ignored if the preamble field
  650.      * specifies the {@link #CCSDS_EPOCH CCSDS reference epoch} is used (and hence
  651.      * may be null in this case)
  652.      * @param utc      time scale used to compute date and time components.
  653.      * @return an instance corresponding to the specified date
  654.      * @since 10.1
  655.      */
  656.     public static AbsoluteDate parseCCSDSDaySegmentedTimeCode(
  657.             final byte preambleField,
  658.             final byte[] timeField,
  659.             final DateComponents agencyDefinedEpoch,
  660.             final TimeScale utc) {

  661.         // time code identification
  662.         if ((preambleField & 0xF0) != 0x40) {
  663.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD,
  664.                                       formatByte(preambleField));
  665.         }

  666.         // reference epoch
  667.         final DateComponents epoch;
  668.         if ((preambleField & 0x08) == 0x00) {
  669.             // the reference epoch is CCSDS epoch 1958-01-01T00:00:00 TAI
  670.             epoch = DateComponents.CCSDS_EPOCH;
  671.         } else {
  672.             // the reference epoch is agency defined
  673.             if (agencyDefinedEpoch == null) {
  674.                 throw new OrekitException(OrekitMessages.CCSDS_DATE_MISSING_AGENCY_EPOCH);
  675.             }
  676.             epoch = agencyDefinedEpoch;
  677.         }

  678.         // time field lengths
  679.         final int daySegmentLength = ((preambleField & 0x04) == 0x0) ? 2 : 3;
  680.         final int subMillisecondLength = (preambleField & 0x03) << 1;
  681.         if (subMillisecondLength == 6) {
  682.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD,
  683.                                       formatByte(preambleField));
  684.         }
  685.         if (timeField.length != daySegmentLength + 4 + subMillisecondLength) {
  686.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_LENGTH_TIME_FIELD,
  687.                                       timeField.length, daySegmentLength + 4 + subMillisecondLength);
  688.         }


  689.         int i   = 0;
  690.         int day = 0;
  691.         while (i < daySegmentLength) {
  692.             day = day * 256 + toUnsigned(timeField[i++]);
  693.         }

  694.         long milliInDay = 0l;
  695.         while (i < daySegmentLength + 4) {
  696.             milliInDay = milliInDay * 256 + toUnsigned(timeField[i++]);
  697.         }
  698.         final int milli   = (int) (milliInDay % 1000l);
  699.         final int seconds = (int) ((milliInDay - milli) / 1000l);

  700.         double subMilli = 0;
  701.         double divisor  = 1;
  702.         while (i < timeField.length) {
  703.             subMilli = subMilli * 256 + toUnsigned(timeField[i++]);
  704.             divisor *= 1000;
  705.         }

  706.         final DateComponents date = new DateComponents(epoch, day);
  707.         final TimeComponents time = new TimeComponents(seconds);
  708.         return new AbsoluteDate(date, time, utc).shiftedBy(milli * 1.0e-3 + subMilli / divisor);

  709.     }

  710.     /** Build an instance from a CCSDS Calendar Segmented Time Code (CCS).
  711.      * <p>
  712.      * CCSDS Calendar Segmented Time Code is defined in the blue book:
  713.      * CCSDS Time Code Format (CCSDS 301.0-B-4) published in November 2010
  714.      * </p>
  715.      *
  716.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  717.      *
  718.      * @param preambleField field specifying the format, often not transmitted in
  719.      * data interfaces, as it is constant for a given data interface
  720.      * @param timeField byte array containing the time code
  721.      * @return an instance corresponding to the specified date
  722.      * @see #parseCCSDSCalendarSegmentedTimeCode(byte, byte[], TimeScale)
  723.      */
  724.     @DefaultDataContext
  725.     public static AbsoluteDate parseCCSDSCalendarSegmentedTimeCode(final byte preambleField, final byte[] timeField) {
  726.         return parseCCSDSCalendarSegmentedTimeCode(preambleField, timeField,
  727.                 DataContext.getDefault().getTimeScales().getUTC());
  728.     }

  729.     /** Build an instance from a CCSDS Calendar Segmented Time Code (CCS).
  730.      * <p>
  731.      * CCSDS Calendar Segmented Time Code is defined in the blue book:
  732.      * CCSDS Time Code Format (CCSDS 301.0-B-4) published in November 2010
  733.      * </p>
  734.      * @param preambleField field specifying the format, often not transmitted in
  735.      * data interfaces, as it is constant for a given data interface
  736.      * @param timeField byte array containing the time code
  737.      * @param utc      time scale used to compute date and time components.
  738.      * @return an instance corresponding to the specified date
  739.      * @since 10.1
  740.      */
  741.     public static AbsoluteDate parseCCSDSCalendarSegmentedTimeCode(
  742.             final byte preambleField,
  743.             final byte[] timeField,
  744.             final TimeScale utc) {

  745.         // time code identification
  746.         if ((preambleField & 0xF0) != 0x50) {
  747.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD,
  748.                                       formatByte(preambleField));
  749.         }

  750.         // time field length
  751.         final int length = 7 + (preambleField & 0x07);
  752.         if (length == 14) {
  753.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD,
  754.                                       formatByte(preambleField));
  755.         }
  756.         if (timeField.length != length) {
  757.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_LENGTH_TIME_FIELD,
  758.                                       timeField.length, length);
  759.         }

  760.         // date part in the first four bytes
  761.         final DateComponents date;
  762.         if ((preambleField & 0x08) == 0x00) {
  763.             // month of year and day of month variation
  764.             date = new DateComponents(toUnsigned(timeField[0]) * 256 + toUnsigned(timeField[1]),
  765.                                       toUnsigned(timeField[2]),
  766.                                       toUnsigned(timeField[3]));
  767.         } else {
  768.             // day of year variation
  769.             date = new DateComponents(toUnsigned(timeField[0]) * 256 + toUnsigned(timeField[1]),
  770.                                       toUnsigned(timeField[2]) * 256 + toUnsigned(timeField[3]));
  771.         }

  772.         // time part from bytes 5 to last (between 7 and 13 depending on precision)
  773.         final TimeComponents time = new TimeComponents(toUnsigned(timeField[4]),
  774.                                                        toUnsigned(timeField[5]),
  775.                                                        toUnsigned(timeField[6]));
  776.         double subSecond = 0;
  777.         double divisor   = 1;
  778.         for (int i = 7; i < length; ++i) {
  779.             subSecond = subSecond * 100 + toUnsigned(timeField[i]);
  780.             divisor *= 100;
  781.         }

  782.         return new AbsoluteDate(date, time, utc).shiftedBy(subSecond / divisor);

  783.     }

  784.     /** Decode a signed byte as an unsigned int value.
  785.      * @param b byte to decode
  786.      * @return an unsigned int value
  787.      */
  788.     private static int toUnsigned(final byte b) {
  789.         final int i = (int) b;
  790.         return (i < 0) ? 256 + i : i;
  791.     }

  792.     /** Format a byte as an hex string for error messages.
  793.      * @param data byte to format
  794.      * @return a formatted string
  795.      */
  796.     private static String formatByte(final byte data) {
  797.         return "0x" + Integer.toHexString(data).toUpperCase();
  798.     }

  799.     /** Build an instance corresponding to a Julian Day date.
  800.      * @param jd Julian day
  801.      * @param secondsSinceNoon seconds in the Julian day
  802.      * (BEWARE, Julian days start at noon, so 0.0 is noon)
  803.      * @param timeScale time scale in which the seconds in day are defined
  804.      * @return a new instant
  805.      */
  806.     public static AbsoluteDate createJDDate(final int jd, final double secondsSinceNoon,
  807.                                              final TimeScale timeScale) {
  808.         return new AbsoluteDate(new DateComponents(DateComponents.JULIAN_EPOCH, jd),
  809.                                 TimeComponents.H12, timeScale).shiftedBy(secondsSinceNoon);
  810.     }

  811.     /** Build an instance corresponding to a Modified Julian Day date.
  812.      * @param mjd modified Julian day
  813.      * @param secondsInDay seconds in the day
  814.      * @param timeScale time scale in which the seconds in day are defined
  815.      * @return a new instant
  816.      * @exception OrekitIllegalArgumentException if seconds number is out of range
  817.      */
  818.     public static AbsoluteDate createMJDDate(final int mjd, final double secondsInDay,
  819.                                              final TimeScale timeScale)
  820.         throws OrekitIllegalArgumentException {
  821.         final DateComponents dc = new DateComponents(DateComponents.MODIFIED_JULIAN_EPOCH, mjd);
  822.         final TimeComponents tc;
  823.         if (secondsInDay >= Constants.JULIAN_DAY) {
  824.             // check we are really allowed to use this number of seconds
  825.             final int    secondsA = 86399; // 23:59:59, i.e. 59s in the last minute of the day
  826.             final double secondsB = secondsInDay - secondsA;
  827.             final TimeComponents safeTC = new TimeComponents(secondsA, 0.0);
  828.             final AbsoluteDate safeDate = new AbsoluteDate(dc, safeTC, timeScale);
  829.             if (timeScale.minuteDuration(safeDate) > 59 + secondsB) {
  830.                 // we are within the last minute of the day, the number of seconds is OK
  831.                 return safeDate.shiftedBy(secondsB);
  832.             } else {
  833.                 // let TimeComponents trigger an OrekitIllegalArgumentException
  834.                 // for the wrong number of seconds
  835.                 tc = new TimeComponents(secondsA, secondsB);
  836.             }
  837.         } else {
  838.             tc = new TimeComponents(secondsInDay);
  839.         }

  840.         // create the date
  841.         return new AbsoluteDate(dc, tc, timeScale);

  842.     }


  843.     /** Build an instance corresponding to a Julian Epoch (JE).
  844.      * <p>According to Lieske paper: <a
  845.      * href="http://articles.adsabs.harvard.edu/cgi-bin/nph-iarticle_query?1979A%26A....73..282L&amp;defaultprint=YES&amp;filetype=.pdf.">
  846.      * Precession Matrix Based on IAU (1976) System of Astronomical Constants</a>, Astronomy and Astrophysics,
  847.      * vol. 73, no. 3, Mar. 1979, p. 282-284, Julian Epoch is related to Julian Ephemeris Date as:</p>
  848.      * <pre>
  849.      * JE = 2000.0 + (JED - 2451545.0) / 365.25
  850.      * </pre>
  851.      * <p>
  852.      * This method reverts the formula above and computes an {@code AbsoluteDate} from the Julian Epoch.
  853.      * </p>
  854.      *
  855.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  856.      *
  857.      * @param julianEpoch Julian epoch, like 2000.0 for defining the classical reference J2000.0
  858.      * @return a new instant
  859.      * @see #J2000_EPOCH
  860.      * @see #createBesselianEpoch(double)
  861.      * @see TimeScales#createJulianEpoch(double)
  862.      */
  863.     @DefaultDataContext
  864.     public static AbsoluteDate createJulianEpoch(final double julianEpoch) {
  865.         return DataContext.getDefault().getTimeScales().createJulianEpoch(julianEpoch);
  866.     }

  867.     /** Build an instance corresponding to a Besselian Epoch (BE).
  868.      * <p>According to Lieske paper: <a
  869.      * href="http://articles.adsabs.harvard.edu/cgi-bin/nph-iarticle_query?1979A%26A....73..282L&amp;defaultprint=YES&amp;filetype=.pdf.">
  870.      * Precession Matrix Based on IAU (1976) System of Astronomical Constants</a>, Astronomy and Astrophysics,
  871.      * vol. 73, no. 3, Mar. 1979, p. 282-284, Besselian Epoch is related to Julian Ephemeris Date as:</p>
  872.      * <pre>
  873.      * BE = 1900.0 + (JED - 2415020.31352) / 365.242198781
  874.      * </pre>
  875.      * <p>
  876.      * This method reverts the formula above and computes an {@code AbsoluteDate} from the Besselian Epoch.
  877.      * </p>
  878.      *
  879.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  880.      *
  881.      * @param besselianEpoch Besselian epoch, like 1950 for defining the classical reference B1950.0
  882.      * @return a new instant
  883.      * @see #createJulianEpoch(double)
  884.      * @see TimeScales#createBesselianEpoch(double)
  885.      */
  886.     @DefaultDataContext
  887.     public static AbsoluteDate createBesselianEpoch(final double besselianEpoch) {
  888.         return DataContext.getDefault().getTimeScales()
  889.                 .createBesselianEpoch(besselianEpoch);
  890.     }

  891.     /** Get a time-shifted date.
  892.      * <p>
  893.      * Calling this method is equivalent to call <code>new AbsoluteDate(this, dt)</code>.
  894.      * </p>
  895.      * @param dt time shift in seconds
  896.      * @return a new date, shifted with respect to instance (which is immutable)
  897.      * @see org.orekit.utils.PVCoordinates#shiftedBy(double)
  898.      * @see org.orekit.attitudes.Attitude#shiftedBy(double)
  899.      * @see org.orekit.orbits.Orbit#shiftedBy(double)
  900.      * @see org.orekit.propagation.SpacecraftState#shiftedBy(double)
  901.      */
  902.     public AbsoluteDate shiftedBy(final double dt) {
  903.         return new AbsoluteDate(this, dt);
  904.     }

  905.     /** Compute the physically elapsed duration between two instants.
  906.      * <p>The returned duration is the number of seconds physically
  907.      * elapsed between the two instants, measured in a regular time
  908.      * scale with respect to surface of the Earth (i.e either the {@link
  909.      * TAIScale TAI scale}, the {@link TTScale TT scale} or the {@link
  910.      * GPSScale GPS scale}). It is the only method that gives a
  911.      * duration with a physical meaning.</p>
  912.      * <p>This method gives the same result (with less computation)
  913.      * as calling {@link #offsetFrom(AbsoluteDate, TimeScale)}
  914.      * with a second argument set to one of the regular scales cited
  915.      * above.</p>
  916.      * <p>This method is the reverse of the {@link #AbsoluteDate(AbsoluteDate,
  917.      * double)} constructor.</p>
  918.      * @param instant instant to subtract from the instance
  919.      * @return offset in seconds between the two instants (positive
  920.      * if the instance is posterior to the argument)
  921.      * @see #offsetFrom(AbsoluteDate, TimeScale)
  922.      * @see #AbsoluteDate(AbsoluteDate, double)
  923.      */
  924.     public double durationFrom(final AbsoluteDate instant) {
  925.         return (epoch - instant.epoch) + (offset - instant.offset);
  926.     }

  927.     /** Compute the apparent clock offset between two instant <em>in the
  928.      * perspective of a specific {@link TimeScale time scale}</em>.
  929.      * <p>The offset is the number of seconds counted in the given
  930.      * time scale between the locations of the two instants, with
  931.      * all time scale irregularities removed (i.e. considering all
  932.      * days are exactly 86400 seconds long). This method will give
  933.      * a result that may not have a physical meaning if the time scale
  934.      * is irregular. For example since a leap second was introduced at
  935.      * the end of 2005, the apparent offset between 2005-12-31T23:59:59
  936.      * and 2006-01-01T00:00:00 is 1 second, but the physical duration
  937.      * of the corresponding time interval as returned by the {@link
  938.      * #durationFrom(AbsoluteDate)} method is 2 seconds.</p>
  939.      * <p>This method is the reverse of the {@link #AbsoluteDate(AbsoluteDate,
  940.      * double, TimeScale)} constructor.</p>
  941.      * @param instant instant to subtract from the instance
  942.      * @param timeScale time scale with respect to which the offset should
  943.      * be computed
  944.      * @return apparent clock offset in seconds between the two instants
  945.      * (positive if the instance is posterior to the argument)
  946.      * @see #durationFrom(AbsoluteDate)
  947.      * @see #AbsoluteDate(AbsoluteDate, double, TimeScale)
  948.      */
  949.     public double offsetFrom(final AbsoluteDate instant, final TimeScale timeScale) {
  950.         final long   elapsedDurationA = epoch - instant.epoch;
  951.         final double elapsedDurationB = (offset         + timeScale.offsetFromTAI(this)) -
  952.                                         (instant.offset + timeScale.offsetFromTAI(instant));
  953.         return  elapsedDurationA + elapsedDurationB;
  954.     }

  955.     /** Compute the offset between two time scales at the current instant.
  956.      * <p>The offset is defined as <i>l₁-l₂</i>
  957.      * where <i>l₁</i> is the location of the instant in
  958.      * the <code>scale1</code> time scale and <i>l₂</i> is the
  959.      * location of the instant in the <code>scale2</code> time scale.</p>
  960.      * @param scale1 first time scale
  961.      * @param scale2 second time scale
  962.      * @return offset in seconds between the two time scales at the
  963.      * current instant
  964.      */
  965.     public double timeScalesOffset(final TimeScale scale1, final TimeScale scale2) {
  966.         return scale1.offsetFromTAI(this) - scale2.offsetFromTAI(this);
  967.     }

  968.     /** Convert the instance to a Java {@link java.util.Date Date}.
  969.      * <p>Conversion to the Date class induces a loss of precision because
  970.      * the Date class does not provide sub-millisecond information. Java Dates
  971.      * are considered to be locations in some times scales.</p>
  972.      * @param timeScale time scale to use
  973.      * @return a {@link java.util.Date Date} instance representing the location
  974.      * of the instant in the time scale
  975.      */
  976.     public Date toDate(final TimeScale timeScale) {
  977.         final double time = epoch + (offset + timeScale.offsetFromTAI(this));
  978.         return new Date(FastMath.round((time + 10957.5 * 86400.0) * 1000));
  979.     }

  980.     /** Split the instance into date/time components.
  981.      * @param timeScale time scale to use
  982.      * @return date/time components
  983.      */
  984.     public DateTimeComponents getComponents(final TimeScale timeScale) {

  985.         if (Double.isInfinite(offset)) {
  986.             // special handling for past and future infinity
  987.             if (offset < 0) {
  988.                 return new DateTimeComponents(DateComponents.MIN_EPOCH, TimeComponents.H00);
  989.             } else {
  990.                 return new DateTimeComponents(DateComponents.MAX_EPOCH,
  991.                                               new TimeComponents(23, 59, 59.999));
  992.             }
  993.         }

  994.         // Compute offset from 2000-01-01T00:00:00 in specified time scale.
  995.         // Use 2Sum for high precision.
  996.         final double taiOffset = timeScale.offsetFromTAI(this);
  997.         final SumAndResidual sumAndResidual = MathUtils.twoSum(offset, taiOffset);

  998.         // split date and time
  999.         final long   carry = (long) FastMath.floor(sumAndResidual.getSum());
  1000.         double offset2000B = (sumAndResidual.getSum() - carry) + sumAndResidual.getResidual();
  1001.         long   offset2000A = epoch + carry + 43200l;
  1002.         if (offset2000B < 0) {
  1003.             offset2000A -= 1;
  1004.             offset2000B += 1;
  1005.         }
  1006.         long time = offset2000A % 86400l;
  1007.         if (time < 0l) {
  1008.             time += 86400l;
  1009.         }
  1010.         final int date = (int) ((offset2000A - time) / 86400l);

  1011.         // extract calendar elements
  1012.         final DateComponents dateComponents = new DateComponents(DateComponents.J2000_EPOCH, date);

  1013.         // extract time element, accounting for leap seconds
  1014.         final double leap = timeScale.insideLeap(this) ? timeScale.getLeap(this) : 0;
  1015.         final int minuteDuration = timeScale.minuteDuration(this);
  1016.         final TimeComponents timeComponents =
  1017.                 TimeComponents.fromSeconds((int) time, offset2000B, leap, minuteDuration);

  1018.         // build the components
  1019.         return new DateTimeComponents(dateComponents, timeComponents);

  1020.     }

  1021.     /** Split the instance into date/time components for a local time.
  1022.      *
  1023.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  1024.      *
  1025.      * @param minutesFromUTC offset in <em>minutes</em> from UTC (positive Eastwards UTC,
  1026.      * negative Westward UTC)
  1027.      * @return date/time components
  1028.      * @since 7.2
  1029.      * @see #getComponents(int, TimeScale)
  1030.      */
  1031.     @DefaultDataContext
  1032.     public DateTimeComponents getComponents(final int minutesFromUTC) {
  1033.         return getComponents(minutesFromUTC,
  1034.                 DataContext.getDefault().getTimeScales().getUTC());
  1035.     }

  1036.     /**
  1037.      * Split the instance into date/time components for a local time.
  1038.      *
  1039.      * @param minutesFromUTC offset in <em>minutes</em> from UTC (positive Eastwards UTC,
  1040.      *                       negative Westward UTC)
  1041.      * @param utc            time scale used to compute date and time components.
  1042.      * @return date/time components
  1043.      * @since 10.1
  1044.      */
  1045.     public DateTimeComponents getComponents(final int minutesFromUTC,
  1046.                                             final TimeScale utc) {

  1047.         final DateTimeComponents utcComponents = getComponents(utc);

  1048.         // shift the date according to UTC offset, but WITHOUT touching the seconds,
  1049.         // as they may exceed 60.0 during a leap seconds introduction,
  1050.         // and we want to preserve these special cases
  1051.         final double seconds = utcComponents.getTime().getSecond();

  1052.         int minute = utcComponents.getTime().getMinute() + minutesFromUTC;
  1053.         final int hourShift;
  1054.         if (minute < 0) {
  1055.             hourShift = (minute - 59) / 60;
  1056.         } else if (minute > 59) {
  1057.             hourShift = minute / 60;
  1058.         } else {
  1059.             hourShift = 0;
  1060.         }
  1061.         minute -= 60 * hourShift;

  1062.         int hour = utcComponents.getTime().getHour() + hourShift;
  1063.         final int dayShift;
  1064.         if (hour < 0) {
  1065.             dayShift = (hour - 23) / 24;
  1066.         } else if (hour > 23) {
  1067.             dayShift = hour / 24;
  1068.         } else {
  1069.             dayShift = 0;
  1070.         }
  1071.         hour -= 24 * dayShift;

  1072.         return new DateTimeComponents(new DateComponents(utcComponents.getDate(), dayShift),
  1073.                                       new TimeComponents(hour, minute, seconds, minutesFromUTC));

  1074.     }

  1075.     /** Split the instance into date/time components for a time zone.
  1076.      *
  1077.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  1078.      *
  1079.      * @param timeZone time zone
  1080.      * @return date/time components
  1081.      * @since 7.2
  1082.      * @see #getComponents(TimeZone, TimeScale)
  1083.      */
  1084.     @DefaultDataContext
  1085.     public DateTimeComponents getComponents(final TimeZone timeZone) {
  1086.         return getComponents(timeZone, DataContext.getDefault().getTimeScales().getUTC());
  1087.     }

  1088.     /**
  1089.      * Split the instance into date/time components for a time zone.
  1090.      *
  1091.      * @param timeZone time zone
  1092.      * @param utc      time scale used to computed date and time components.
  1093.      * @return date/time components
  1094.      * @since 10.1
  1095.      */
  1096.     public DateTimeComponents getComponents(final TimeZone timeZone,
  1097.                                             final TimeScale utc) {
  1098.         final AbsoluteDate javaEpoch = new AbsoluteDate(DateComponents.JAVA_EPOCH, utc);
  1099.         final long milliseconds = FastMath.round(1000 * offsetFrom(javaEpoch, utc));
  1100.         return getComponents(timeZone.getOffset(milliseconds) / 60000, utc);
  1101.     }

  1102.     /** Compare the instance with another date.
  1103.      * @param date other date to compare the instance to
  1104.      * @return a negative integer, zero, or a positive integer as this date
  1105.      * is before, simultaneous, or after the specified date.
  1106.      */
  1107.     public int compareTo(final AbsoluteDate date) {
  1108.         final double duration = durationFrom(date);
  1109.         if (!Double.isNaN(duration)) {
  1110.             return Double.compare(duration, 0.0);
  1111.         }
  1112.         // both dates are infinity or one is NaN or both are NaN
  1113.         return Double.compare(offset, date.offset);
  1114.     }

  1115.     /** {@inheritDoc} */
  1116.     public AbsoluteDate getDate() {
  1117.         return this;
  1118.     }

  1119.     /** Check if the instance represents the same time as another instance.
  1120.      * @param date other date
  1121.      * @return true if the instance and the other date refer to the same instant
  1122.      */
  1123.     public boolean equals(final Object date) {

  1124.         if (date == this) {
  1125.             // first fast check
  1126.             return true;
  1127.         }

  1128.         if (date instanceof AbsoluteDate) {

  1129.             // Improve robustness against positive/negative infinity dates
  1130.             if ( this.offset == Double.NEGATIVE_INFINITY && ((AbsoluteDate) date).offset == Double.NEGATIVE_INFINITY ||
  1131.                     this.offset == Double.POSITIVE_INFINITY && ((AbsoluteDate) date).offset == Double.POSITIVE_INFINITY ) {
  1132.                 return true;
  1133.             } else {
  1134.                 return durationFrom((AbsoluteDate) date) == 0;
  1135.             }
  1136.         }

  1137.         return false;
  1138.     }

  1139.     /** Check if the instance represents the same time as another.
  1140.      * @param other the instant to compare this date to
  1141.      * @return true if the instance and the argument refer to the same instant
  1142.      * @see #isCloseTo(TimeStamped, double)
  1143.      * @since 10.1
  1144.      */
  1145.     public boolean isEqualTo(final TimeStamped other) {
  1146.         return this.equals(other.getDate());
  1147.     }

  1148.     /** Check if the instance time is close to another.
  1149.      * @param other the instant to compare this date to
  1150.      * @param tolerance the separation, in seconds, under which the two instants will be considered close to each other
  1151.      * @return true if the duration between the instance and the argument is strictly below the tolerance
  1152.      * @see #isEqualTo(TimeStamped)
  1153.      * @since 10.1
  1154.      */
  1155.     public boolean isCloseTo(final TimeStamped other, final double tolerance) {
  1156.         return FastMath.abs(this.durationFrom(other.getDate())) < tolerance;
  1157.     }

  1158.     /** Check if the instance represents a time that is strictly before another.
  1159.      * @param other the instant to compare this date to
  1160.      * @return true if the instance is strictly before the argument when ordering chronologically
  1161.      * @see #isBeforeOrEqualTo(TimeStamped)
  1162.      * @since 10.1
  1163.      */
  1164.     public boolean isBefore(final TimeStamped other) {
  1165.         return this.compareTo(other.getDate()) < 0;
  1166.     }

  1167.     /** Check if the instance represents a time that is strictly after another.
  1168.      * @param other the instant to compare this date to
  1169.      * @return true if the instance is strictly after the argument when ordering chronologically
  1170.      * @see #isAfterOrEqualTo(TimeStamped)
  1171.      * @since 10.1
  1172.      */
  1173.     public boolean isAfter(final TimeStamped other) {
  1174.         return this.compareTo(other.getDate()) > 0;
  1175.     }

  1176.     /** Check if the instance represents a time that is before or equal to another.
  1177.      * @param other the instant to compare this date to
  1178.      * @return true if the instance is before (or equal to) the argument when ordering chronologically
  1179.      * @see #isBefore(TimeStamped)
  1180.      * @since 10.1
  1181.      */
  1182.     public boolean isBeforeOrEqualTo(final TimeStamped other) {
  1183.         return this.isEqualTo(other) || this.isBefore(other);
  1184.     }

  1185.     /** Check if the instance represents a time that is after or equal to another.
  1186.      * @param other the instant to compare this date to
  1187.      * @return true if the instance is after (or equal to) the argument when ordering chronologically
  1188.      * @see #isAfterOrEqualTo(TimeStamped)
  1189.      * @since 10.1
  1190.      */
  1191.     public boolean isAfterOrEqualTo(final TimeStamped other) {
  1192.         return this.isEqualTo(other) || this.isAfter(other);
  1193.     }

  1194.     /** Check if the instance represents a time that is strictly between two others representing
  1195.      * the boundaries of a time span. The two boundaries can be provided in any order: in other words,
  1196.      * whether <code>boundary</code> represents a time that is before or after <code>otherBoundary</code> will
  1197.      * not change the result of this method.
  1198.      * @param boundary one end of the time span
  1199.      * @param otherBoundary the other end of the time span
  1200.      * @return true if the instance is strictly between the two arguments when ordering chronologically
  1201.      * @see #isBetweenOrEqualTo(TimeStamped, TimeStamped)
  1202.      * @since 10.1
  1203.      */
  1204.     public boolean isBetween(final TimeStamped boundary, final TimeStamped otherBoundary) {
  1205.         final TimeStamped beginning;
  1206.         final TimeStamped end;
  1207.         if (boundary.getDate().isBefore(otherBoundary)) {
  1208.             beginning = boundary;
  1209.             end = otherBoundary;
  1210.         } else {
  1211.             beginning = otherBoundary;
  1212.             end = boundary;
  1213.         }
  1214.         return this.isAfter(beginning) && this.isBefore(end);
  1215.     }

  1216.     /** Check if the instance represents a time that is between two others representing
  1217.      * the boundaries of a time span, or equal to one of them. The two boundaries can be provided in any order:
  1218.      * in other words, whether <code>boundary</code> represents a time that is before or after
  1219.      * <code>otherBoundary</code> will not change the result of this method.
  1220.      * @param boundary one end of the time span
  1221.      * @param otherBoundary the other end of the time span
  1222.      * @return true if the instance is between the two arguments (or equal to at least one of them)
  1223.      * when ordering chronologically
  1224.      * @see #isBetween(TimeStamped, TimeStamped)
  1225.      * @since 10.1
  1226.      */
  1227.     public boolean isBetweenOrEqualTo(final TimeStamped boundary, final TimeStamped otherBoundary) {
  1228.         return this.isEqualTo(boundary) || this.isEqualTo(otherBoundary) || this.isBetween(boundary, otherBoundary);
  1229.     }

  1230.     /** Get a hashcode for this date.
  1231.      * @return hashcode
  1232.      */
  1233.     public int hashCode() {
  1234.         final long l = Double.doubleToLongBits(durationFrom(ARBITRARY_EPOCH));
  1235.         return (int) (l ^ (l >>> 32));
  1236.     }

  1237.     /**
  1238.      * Get a String representation of the instant location with up to 16 digits of
  1239.      * precision for the seconds value.
  1240.      *
  1241.      * <p> Since this method is used in exception messages and error handling every
  1242.      * effort is made to return some representation of the instant. If UTC is available
  1243.      * from the default data context then it is used to format the string in UTC. If not
  1244.      * then TAI is used. Finally if the prior attempts fail this method falls back to
  1245.      * converting this class's internal representation to a string.
  1246.      *
  1247.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  1248.      *
  1249.      * @return a string representation of the instance, in ISO-8601 format if UTC is
  1250.      * available from the default data context.
  1251.      * @see #toString(TimeScale)
  1252.      * @see #toStringRfc3339(TimeScale)
  1253.      * @see DateTimeComponents#toString(int, int)
  1254.      */
  1255.     @DefaultDataContext
  1256.     public String toString() {
  1257.         // CHECKSTYLE: stop IllegalCatch check
  1258.         try {
  1259.             // try to use UTC first at that is likely most familiar to the user.
  1260.             return toString(DataContext.getDefault().getTimeScales().getUTC()) + "Z";
  1261.         } catch (RuntimeException e1) {
  1262.             // catch OrekitException, OrekitIllegalStateException, etc.
  1263.             try {
  1264.                 // UTC failed, try to use TAI
  1265.                 return toString(new TAIScale()) + " TAI";
  1266.             } catch (RuntimeException e2) {
  1267.                 // catch OrekitException, OrekitIllegalStateException, etc.
  1268.                 // Likely failed to convert to ymdhms.
  1269.                 // Give user some indication of what time it is.
  1270.                 try {
  1271.                     return "(" + this.epoch + " + " + this.offset + ") seconds past epoch";
  1272.                 } catch (RuntimeException e3) {
  1273.                     // give up and throw an exception
  1274.                     e2.addSuppressed(e3);
  1275.                     e1.addSuppressed(e2);
  1276.                     throw e1;
  1277.                 }
  1278.             }
  1279.         }
  1280.         // CHECKSTYLE: resume IllegalCatch check
  1281.     }

  1282.     /**
  1283.      * Get a String representation of the instant location in ISO-8601 format without the
  1284.      * UTC offset and with up to 16 digits of precision for the seconds value.
  1285.      *
  1286.      * @param timeScale time scale to use
  1287.      * @return a string representation of the instance.
  1288.      * @see #toStringRfc3339(TimeScale)
  1289.      * @see DateTimeComponents#toString(int, int)
  1290.      */
  1291.     public String toString(final TimeScale timeScale) {
  1292.         return getComponents(timeScale).toStringWithoutUtcOffset();
  1293.     }

  1294.     /** Get a String representation of the instant location for a local time.
  1295.      *
  1296.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  1297.      *
  1298.      * @param minutesFromUTC offset in <em>minutes</em> from UTC (positive Eastwards UTC,
  1299.      * negative Westward UTC).
  1300.      * @return string representation of the instance,
  1301.      * in ISO-8601 format with milliseconds accuracy
  1302.      * @since 7.2
  1303.      * @see #toString(int, TimeScale)
  1304.      */
  1305.     @DefaultDataContext
  1306.     public String toString(final int minutesFromUTC) {
  1307.         return toString(minutesFromUTC,
  1308.                 DataContext.getDefault().getTimeScales().getUTC());
  1309.     }

  1310.     /**
  1311.      * Get a String representation of the instant location for a local time.
  1312.      *
  1313.      * @param minutesFromUTC offset in <em>minutes</em> from UTC (positive Eastwards UTC,
  1314.      *                       negative Westward UTC).
  1315.      * @param utc            time scale used to compute date and time components.
  1316.      * @return string representation of the instance, in ISO-8601 format with milliseconds
  1317.      * accuracy
  1318.      * @since 10.1
  1319.      * @see #getComponents(int, TimeScale)
  1320.      * @see DateTimeComponents#toString(int, int)
  1321.      */
  1322.     public String toString(final int minutesFromUTC, final TimeScale utc) {
  1323.         final int minuteDuration = utc.minuteDuration(this);
  1324.         return getComponents(minutesFromUTC, utc).toString(minuteDuration);
  1325.     }

  1326.     /** Get a String representation of the instant location for a time zone.
  1327.      *
  1328.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  1329.      *
  1330.      * @param timeZone time zone
  1331.      * @return string representation of the instance,
  1332.      * in ISO-8601 format with milliseconds accuracy
  1333.      * @since 7.2
  1334.      * @see #toString(TimeZone, TimeScale)
  1335.      */
  1336.     @DefaultDataContext
  1337.     public String toString(final TimeZone timeZone) {
  1338.         return toString(timeZone, DataContext.getDefault().getTimeScales().getUTC());
  1339.     }

  1340.     /**
  1341.      * Get a String representation of the instant location for a time zone.
  1342.      *
  1343.      * @param timeZone time zone
  1344.      * @param utc      time scale used to compute date and time components.
  1345.      * @return string representation of the instance, in ISO-8601 format with milliseconds
  1346.      * accuracy
  1347.      * @since 10.1
  1348.      * @see #getComponents(TimeZone, TimeScale)
  1349.      * @see DateTimeComponents#toString(int, int)
  1350.      */
  1351.     public String toString(final TimeZone timeZone, final TimeScale utc) {
  1352.         final int minuteDuration = utc.minuteDuration(this);
  1353.         return getComponents(timeZone, utc).toString(minuteDuration);
  1354.     }

  1355.     /**
  1356.      * Represent the given date as a string according to the format in RFC 3339. RFC3339
  1357.      * is a restricted subset of ISO 8601 with a well defined grammar. Enough digits are
  1358.      * included in the seconds value to avoid rounding up to the next minute.
  1359.      *
  1360.      * <p>This method is different than {@link AbsoluteDate#toString(TimeScale)} in that
  1361.      * it includes a {@code "Z"} at the end to indicate the time zone and enough precision
  1362.      * to represent the point in time without rounding up to the next minute.
  1363.      *
  1364.      * <p>RFC3339 is unable to represent BC years, years of 10000 or more, time zone
  1365.      * offsets of 100 hours or more, or NaN. In these cases the value returned from this
  1366.      * method will not be valid RFC3339 format.
  1367.      *
  1368.      * @param utc time scale.
  1369.      * @return RFC 3339 format string.
  1370.      * @see <a href="https://tools.ietf.org/html/rfc3339#page-8">RFC 3339</a>
  1371.      * @see DateTimeComponents#toStringRfc3339()
  1372.      * @see #toString(TimeScale)
  1373.      * @see #getComponents(TimeScale)
  1374.      */
  1375.     public String toStringRfc3339(final TimeScale utc) {
  1376.         return this.getComponents(utc).toStringRfc3339();
  1377.     }

  1378.     /**
  1379.      * Return a string representation of this date-time, rounded to the given precision.
  1380.      *
  1381.      * <p>The format used is ISO8601 without the UTC offset.</p>
  1382.      *
  1383.      * <p>Calling {@code toStringWithoutUtcOffset(DataContext.getDefault().getTimeScales().getUTC(),
  1384.      * 3)} will emulate the behavior of {@link #toString()} in Orekit 10 and earlier. Note
  1385.      * this method is more accurate as it correctly handles rounding during leap seconds.
  1386.      *
  1387.      * @param timeScale      to use to compute components.
  1388.      * @param fractionDigits the number of digits to include after the decimal point in
  1389.      *                       the string representation of the seconds. The date and time
  1390.      *                       is first rounded as necessary. {@code fractionDigits} must be
  1391.      *                       greater than or equal to {@code 0}.
  1392.      * @return string representation of this date, time, and UTC offset
  1393.      * @see #toString(TimeScale)
  1394.      * @see #toStringRfc3339(TimeScale)
  1395.      * @see DateTimeComponents#toString(int, int)
  1396.      * @see DateTimeComponents#toStringWithoutUtcOffset(int, int)
  1397.      * @since 11.1
  1398.      */
  1399.     public String toStringWithoutUtcOffset(final TimeScale timeScale,
  1400.                                            final int fractionDigits) {
  1401.         return this.getComponents(timeScale)
  1402.                 .toStringWithoutUtcOffset(timeScale.minuteDuration(this), fractionDigits);
  1403.     }

  1404. }