Class TimeEncoding


  • public class TimeEncoding
    extends Object
    This class provides times in terms of milliseconds since 1970TAI
    • Field Detail

      • MAX_INSTANT

        public static long MAX_INSTANT
    • Constructor Detail

      • TimeEncoding

        public TimeEncoding()
    • Method Detail

      • setUp

        public static void setUp()
      • currentInstant

        @Deprecated
        public static long currentInstant()
        Deprecated.
        Returns the current wall clock time. Is the same with getWallclockTime Should use instead timeService.getMissionTime()
        Returns:
      • getWallclockTime

        public static long getWallclockTime()
        Returns the current operating system time but converted to Yamcs instant.
        Returns:
      • getWallclockHresTime

        public static Instant getWallclockHresTime()
        Sane as getWallclockTime() but returns a high resolution instant.

        Currently java does not make it easy to get a high resolution time so the returned object has always the picosecond field set to 0.

        Returns:
      • toString

        public static String toString​(long instant)
        Returns the instant formatted as UTC yyyy-MM-DDTHH:mm:ss.SSSZ
        Parameters:
        instant -
        Returns:
      • toOrdinalDateTime

        public static String toOrdinalDateTime​(long instant)
        Returns the instant formatted as UTC yyyy-DDDTHH:mm:ss.SSS
        Parameters:
        instant -
        Returns:
      • toWinCompatibleDateTime

        public static String toWinCompatibleDateTime​(long instant)
        Returns the instant in UTC time scale formatted as YYYY-DDDTHHhMMmSSsSSS so that is leads to an MS Windows compatible filename
        Parameters:
        instant -
        Returns:
      • toCombinedFormat

        public static String toCombinedFormat​(long instant)
      • fromGpsCcsdsTime

        public static long fromGpsCcsdsTime​(int coarseTime,
                                            byte fineTime)
        we assume coarseTime to be always positive (corresponding to uint32_t in C)
        Parameters:
        coarseTime - number of seconds from GPS epoch
        fineTime - number of 1/256 seconds
        Returns:
      • toGpsTime

        public static GpsCcsdsTime toGpsTime​(long instant)
        Conversion from instant to GPS time.
        Parameters:
        instant - yamcs time
        Returns:
        GPS time
      • getCurrentGpsTime

        public static GpsCcsdsTime getCurrentGpsTime()
        Conversion from current instant to GPS time. Current time is the *nix time this function is called.
        Returns:
        GPS time
      • toGpsTimeMillisec

        public static long toGpsTimeMillisec​(long instant)
        Conversion from instant to GPS time (milliseconds since the GPS epoch).
        Parameters:
        instant - TimeEncoding instant
        Returns:
        GPS time
      • fromGpsYearSecMillis

        public static long fromGpsYearSecMillis​(int year,
                                                int secOfYear,
                                                int millis)
      • parse

        public static long parse​(String s)
        parses an ISO 8601 UTC date into an instant
        Parameters:
        s -
        Returns:
      • fromUnixTime

        @Deprecated
        public static long fromUnixTime​(long milliseconds)
        Deprecated.
        Transforms UNIX time (milliseconds since 1970) to instant
        Parameters:
        milliseconds -
        Returns:
      • fromUnixMillisec

        public static long fromUnixMillisec​(long milliseconds)
        Transforms UNIX time (milliseconds since 1970) to instant
        Parameters:
        milliseconds -
        Returns:
      • fromUnixTime

        public static long fromUnixTime​(long seconds,
                                        int microseconds)
        Transforms UNIX time expressed in seconds and microseconds since 1970 to instant WARNING: this conversion will lose precision (microsecond to millisecond)
        Parameters:
        seconds -
        microseconds -
        Returns:
      • toUnixMillisec

        public static long toUnixMillisec​(long instant)
        Transforms instant to UNIX time expressed in milliseconds since 1970
        Parameters:
        instant -
        Returns:
      • fromCalendar

        public static long fromCalendar​(Calendar cal)
        Transforms the cal from UNIX (millisec since 1970) to instant
        Parameters:
        cal -
        Returns:
      • fromDate

        public static long fromDate​(Date date)
        Transforms a Date from UNIX (millisec since 1970) to instant
      • toCalendar

        public static Calendar toCalendar​(long instant)
        transforms instant into a java cal containing milliseconds since 1970
        Parameters:
        instant -
        Returns:
      • getJavaGpsFromInstant

        public static long getJavaGpsFromInstant​(long instant)
        JavaGps is number of milliseconds since 1970 that assumes no leap seconds from 1970 to GPS Epoch, and then continues with the leap seconds.
        Parameters:
        instant -
        Returns:
      • getInstantfromJavaGps

        public static long getInstantfromJavaGps​(long javagps)
      • fromGpsMillisec

        public static long fromGpsMillisec​(long gpstime)
        Parameters:
        gpstime - number of millisec from GPS epoch
        Returns:
      • fromTaiMillisec

        public static long fromTaiMillisec​(long taitime)
      • toTaiMillisec

        public static long toTaiMillisec​(long instant)
      • fromJ2000Millisec

        public static long fromJ2000Millisec​(long j2000time)
      • toJ2000Millisec

        public static long toJ2000Millisec​(long instant)
      • fromProtobufTimestamp

        public static long fromProtobufTimestamp​(com.google.protobuf.Timestamp ts)
        Transforms protobuf Timestamp to instant. The conversion will do the "unsmearing" around the leap seconds and will also lose precision (nanoseconds to milliseconds).
        Parameters:
        ts - - the timestamp to be converted
        Returns:
        See Also:
        https://developers.google.com/time/smear
      • fromProtobufHresTimestamp

        public static Instant fromProtobufHresTimestamp​(com.google.protobuf.Timestamp ts)
        Transforms protobuf Timestamp to high resolution instant. The conversion will do the "unsmearing" around the leap seconds.
        Parameters:
        ts - - the timestamp to be converted
        Returns:
        See Also:
        https://developers.google.com/time/smear
      • toProtobufTimestamp

        public static com.google.protobuf.Timestamp toProtobufTimestamp​(long instant)
        Transforms the instant to protobuf timestamp performing the smearing around the leap seconds.
        Parameters:
        instant - - the instant to be converted
        Returns:
        See Also:
        https://developers.google.com/time/smear
      • toProtobufTimestamp

        public static com.google.protobuf.Timestamp toProtobufTimestamp​(Instant instant)
        Transforms the instant to protobuf timestamp performing the smearing around the leap seconds.
        Parameters:
        instant - - the instant to be converted
        Returns:
        See Also:
        https://developers.google.com/time/smear