Class TimeEncoding

java.lang.Object
org.yamcs.utils.TimeEncoding

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

    • INVALID_INSTANT

      public static final long INVALID_INSTANT
      See Also:
    • MAX_INSTANT

      public static long MAX_INSTANT
    • MIN_INSTANT

      public static final long MIN_INSTANT
      See Also:
    • NEGATIVE_INFINITY

      public static final long NEGATIVE_INFINITY
      See Also:
    • POSITIVE_INFINITY

      public static final long POSITIVE_INFINITY
  • Constructor Details

    • TimeEncoding

      public TimeEncoding()
  • Method Details

    • setUp

      public static void setUp()
    • setUp

      public static void setUp(InputStream in)
    • 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

      If the value is smalle than MIN_INSTANT it returns -inf If the value is larger than MAX_INSTANT it returns +inf

      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)
    • toUtc

      public static TaiUtcConverter.DateTimeComponents toUtc(long instant)
    • getTaiUtcConversionTable

      public static List<TaiUtcConverter.ValidityLine> getTaiUtcConversionTable()
    • parse

      public static long parse(String s)
      parses an ISO 8601 UTC date into an instant
      Parameters:
      s - - string to be parsed
      Returns:
      - internal Yamcs timestamp
      Throws:
      IllegalArgumentException - if the time cannot be parsed
    • parseHres

      public static Instant parseHres(String s)
    • fromUnixPicos

      public static Instant fromUnixPicos(long millis, int picos)
      Transforms UNIX time (milliseconds since 1970, picos in millisecond) to high resolution instant
      Parameters:
      millis - milliseconds since 1970 (without leap seconds)
      picos - picoseconds in milliseconds - can be negative or larger than 10^9 (but has to fit into a 32 bit signed integer).
      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 a Calendar from UNIX (millisec since 1970) to instant
    • fromDate

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

      public static long fromJavaInstant(Instant instant)
      Transforms a Instant from UNIX (millisec since 1970) to instant
    • toCalendar

      public static Calendar toCalendar(long instant)
      Transforms instant into a Calendar containing milliseconds since 1970
      Parameters:
      instant - Yamcs instant
    • toJavaInstant

      public static Instant toJavaInstant(long instant)
      Transforms instant into a Instant containing milliseconds since 1970
      Parameters:
      instant - Yamcs instant
    • 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:
    • 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:
    • 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:
    • 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: