Ejemplo n.º 1
0
        /// <summary>
        /// Returns the difference TAI - UTC as of the given date, in seconds.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns>The difference.</returns>
        public double GetTaiMinusUtc(JulianDate date)
        {
            date = date.ToTimeStandard(TimeStandard.CoordinatedUniversalTime);
            LeapSecond toFind = new LeapSecond(date, 0.0);

            // Start by assuming we're working with UTC, we'll check later if we're
            // off by one because we really have TAI.
            int index = m_leapSeconds.BinarySearch(toFind, s_leapSecondComparer);

            if (index < 0)
            {
                index = ~index;
                --index;
            }

            // Check if we're off by one because we're really working with TAI.
            // If the requested date minus the most recent previous leap second offset is less than the date
            // for the current leap second, then we haven't quite gotten to that leap second yet.
            // This gets a little tricky because JulianDate and its conversion mechanisms try to outsmart us.
            if (date.Standard == TimeStandard.InternationalAtomicTime)
            {
                JulianDate lastDate  = GetDateForIndex(index);
                JulianDate taiCutoff = new JulianDate(lastDate.Day, lastDate.SecondsOfDay, TimeStandard.InternationalAtomicTime);
                taiCutoff += Duration.FromSeconds(GetOffsetForIndex(index));
                if (date < taiCutoff)
                {
                    --index;
                }
            }

            return(GetOffsetForIndex(index));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the value expressed as a <code>currentTime</code>, which is the current time, specified in ISO8601 format.
        /// </summary>
        /// <param name="value">The time.</param>
        public void WriteCurrentTime(JulianDate value)
        {
            const string PropertyName = CurrentTimePropertyName;

            OpenIntervalIfNecessary();
            Output.WritePropertyName(PropertyName);
            CesiumWritingHelper.WriteDate(Output, value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The constructor taking an integer Julian day number assumes that the desired
        /// <see cref="YearMonthDay" /> should represent the Gregorian day corresponding to
        /// the beginning of the provided Julian day number. If the
        /// <see cref="JulianDate"/> is more than one half day later than that, the
        /// calculation will be wrong.
        ///
        /// So, if <paramref name="date"/> is more than 12 hours past the start of the
        /// Julian day, we instead use the  Julian date number of tomorrow.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns>The Julian day number that will produce the correct Gregorian day
        /// number.</returns>
        private static int GetAdjustedJulianDayNumber(JulianDate date)
        {
            int day = date.Day;

            if (date.SecondsOfDay >= 43200.0)
            {
                ++day;
            }
            return(day);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of a Leap Second.
        /// </summary>
        /// <param name="date">The date of the leap second.  This date must be in Coordinated Universal Time (UTC).</param>
        /// <param name="totalTaiOffsetFromUtc">The offset of TAI from UTC after this leap second.</param>
        /// <exception cref="ArgumentException">
        /// Thrown if the given date is not in UTC.
        /// </exception>
        public LeapSecond(JulianDate date, double totalTaiOffsetFromUtc)
        {
            if (date.Standard != TimeStandard.CoordinatedUniversalTime)
            {
                throw new ArgumentException(CesiumLocalization.DateMustBeUTC, "date");
            }

            m_date = date;
            m_totalTaiOffsetFromUtc = totalTaiOffsetFromUtc;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert <paramref name="date"/> from TAI to UTC, if possible.
        /// </summary>
        /// <param name="date">The date, which must be in the TAI
        /// <see cref="TimeStandard"/>.</param>
        /// <returns>The resulting UTC
        /// <see cref="JulianDate"/>, if it was possible to convert.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if the date could not be
        /// converted to UTC.</exception>
        internal JulianDate ConvertTaiToUtc(JulianDate date)
        {
            JulianDate result;

            if (TryConvertTaiToUtc(date, out result))
            {
                return(result);
            }

            throw new ArgumentOutOfRangeException(CesiumLocalization.CannotRepresentLeapSecondAsUTCJulianDate);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Determines if the interval contains a specified date.
        /// </summary>
        /// <param name="date">The date to test.</param>
        /// <returns>true if the interval contains the date, otherwise false.</returns>
        public bool Contains(JulianDate date)
        {
            if (IsEmpty)
            {
                return(false);
            }

            int startComparedToDate = m_start.CompareTo(date);
            int dateComparedToStop  = date.CompareTo(m_stop);

            // return start < date && date < stop
            return(startComparedToDate <= 0 && dateComparedToStop <= 0);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Try to convert <paramref name="date"/> from TAI to UTC, if possible.
        /// </summary>
        /// <param name="date">The date, which must be in the TAI
        /// <see cref="TimeStandard"/>.</param>
        /// <param name="result">Out parameter for returning the resulting UTC
        /// <see cref="JulianDate"/>, if it was possible to convert.</param>
        /// <returns><see langword="true"/> if <paramref name="date"/> could be converted
        /// to UTC, otherwise false.</returns>
        internal bool TryConvertTaiToUtc(JulianDate date, out JulianDate result)
        {
            //treat the request date as if it were UTC, and search for the most recent leap second.
            LeapSecond toFind = new LeapSecond(date, 0.0);
            int        index  = m_leapSeconds.BinarySearch(toFind, s_compareLeapSecondDate);

            if (index < 0)
            {
                index = ~index;
                --index;
            }

            //now we have the index of the most recent leap second that is after the requested date
            if (index >= 0)
            {
                double     mostRecentOffset = GetOffsetForIndex(index);
                JulianDate leapSecondDate   = GetDateForIndex(index);

                if (date.Day == leapSecondDate.Day)
                {
                    //if the requested date is on the day of the leap second, we may have to adjust
                    double secondsSinceLeapSecond = date.SecondsOfDay - leapSecondDate.SecondsOfDay;

                    if (secondsSinceLeapSecond >= mostRecentOffset - 1 &&
                        secondsSinceLeapSecond < mostRecentOffset)
                    {
                        //if the requested date is during the moment of a leap second, then we cannot convert to UTC.
                        result = JulianDate.MinValue;
                        return(false);
                    }

                    if (secondsSinceLeapSecond < mostRecentOffset)
                    {
                        //The leap second we found is actually after the desired date, as a result of simply treating the
                        //TAI date as if it were UTC.  So, use the next previous leap second instead.
                        --index;
                    }
                }
            }

            result = new JulianDate(date.Day, date.SecondsOfDay - GetOffsetForIndex(index), TimeStandard.CoordinatedUniversalTime);
            return(true);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new interval with the specified start date and stop date.
 /// The new interval is closed, meaning that both end points are included.
 /// </summary>
 /// <param name="start">The first date in the interval.</param>
 /// <param name="stop">The last date in the interval.</param>
 public TimeInterval(JulianDate start, JulianDate stop)
 {
     m_start = start;
     m_stop  = stop;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance from a <see cref="JulianDate"/>.
 /// </summary>
 /// <param name="date">The date.</param>
 public YearMonthDay(JulianDate date)
     : this(GetAdjustedJulianDayNumber(date))
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of a Leap Second.
 /// </summary>
 /// <param name="date">The date of the leap second.  This will be assumed to be Coordinated Universal Time (UTC) regardless of the actual time standard associated with the date.</param>
 /// <param name="totalTaiOffsetFromUtc">The offset of TAI from UTC after this leap second.</param>
 public LeapSecond(JulianDate date, double totalTaiOffsetFromUtc)
 {
     // Force the time standard to be UTC.
     m_date = new JulianDate(date.Day, date.SecondsOfDay, TimeStandard.CoordinatedUniversalTime);
     m_totalTaiOffsetFromUtc = totalTaiOffsetFromUtc;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Opens a writer to write information about a single interval.
 /// </summary>
 /// <param name="start">The start of the interval of time covered by this interval element.</param>
 /// <param name="stop">The end of the interval of time covered by this interval element.</param>
 /// <returns>The interval writer.</returns>
 public TPropertyWriter OpenInterval(JulianDate start, JulianDate stop)
 {
     return(m_propertyWriter.OpenInterval(start, stop));
 }
Ejemplo n.º 12
0
 ICesiumPropertyWriter ICesiumIntervalListWriter.OpenInterval(JulianDate start, JulianDate stop)
 {
     return(OpenInterval(start, stop));
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Writes the <code>availability</code> property.  The <code>availability</code> property specifies when data for an object is available. If data for an object is known to be available at the current animation time, but the client does not yet have that data (presumably because it will arrive in a later packet), the client will pause with a message like "Buffering..." while it waits to receive the data. The property can be a single string specifying a single interval, or an array of strings representing intervals.  A later Cesium packet can update this availability if it changes or is found to be incorrect. For example, an SGP4 propagator may report availability for all time, but then later the propagator throws an exception and the availability needs to be adjusted. If this optional property is not present, the object is assumed to be available for all time. Availability is scoped to a particular CZML stream, so two different streams can list different availability for a single object. Within a single stream, the last availability stated for an object is the one in effect and any availabilities in previous packets are ignored. If an object is available at a time, the client expects the object to have at least one property, and it expects all properties that it needs to be defined at that time. If the object doesn't have any properties, or a needed property is defined but not at the animation time, the client will pause animation and wait for more data.
 /// </summary>
 /// <param name="start">The earliest date of the interval.</param>
 /// <param name="stop">The latest date of the interval.</param>
 public void WriteAvailability(JulianDate start, JulianDate stop)
 {
     WriteAvailability(new TimeInterval(start, stop));
 }