Package org.yamcs.utils
Class TimeEncoding
java.lang.Object
org.yamcs.utils.TimeEncoding
This class provides times in terms of milliseconds since 1970TAI
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
static final long
static final long
static final long
static final long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
fromCalendar
(Calendar cal) Transforms aCalendar
from UNIX (millisec since 1970) to instantstatic long
Transforms aDate
from UNIX (millisec since 1970) to instantstatic long
fromGpsCcsdsTime
(int coarseTime, byte fineTime) we assume coarseTime to be always positive (corresponding to uint32_t in C)static long
fromGpsMillisec
(long gpstime) static long
fromGpsYearSecMillis
(int year, int secOfYear, int millis) static long
fromJ2000Millisec
(long j2000time) static long
fromJavaInstant
(Instant instant) Transforms aInstant
from UNIX (millisec since 1970) to instantstatic Instant
fromProtobufHresTimestamp
(com.google.protobuf.Timestamp ts) Transforms protobuf Timestamp to high resolution instant.static long
fromProtobufTimestamp
(com.google.protobuf.Timestamp ts) Transforms protobuf Timestamp to instant.static long
fromTaiMillisec
(long taitime) static long
fromUnixMillisec
(long milliseconds) Transforms UNIX time (milliseconds since 1970) to instantstatic Instant
fromUnixPicos
(long millis, int picos) Transforms UNIX time (milliseconds since 1970, picos in millisecond) to high resolution instantstatic 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)static long
static GpsCcsdsTime
Conversion from current instant to GPS time.static long
getInstantfromJavaGps
(long javagps) 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.static List<TaiUtcConverter.ValidityLine>
static Instant
Sane asgetWallclockTime()
but returns a high resolution instant.static long
Returns the current operating system time but converted to Yamcs instant.static boolean
isSetUp()
returns true if thesetUp()
method has been called to load the leap second table.static long
parses an ISO 8601 UTC date into an instantstatic Instant
static void
setUp()
static void
setUp
(InputStream in) static Calendar
toCalendar
(long instant) Transforms instant into aCalendar
containing milliseconds since 1970static String
toCombinedFormat
(long instant) static GpsCcsdsTime
toGpsTime
(long instant) Conversion from instant to GPS time.static long
toGpsTimeMillisec
(long instant) Conversion from instant to GPS time (milliseconds since the GPS epoch).static long
toJ2000Millisec
(long instant) static Instant
toJavaInstant
(long instant) Transforms instant into aInstant
containing milliseconds since 1970static String
toOrdinalDateTime
(long instant) Returns the instant formatted as UTC yyyy-DDDTHH:mm:ss.SSSstatic com.google.protobuf.Timestamp
toProtobufTimestamp
(long instant) Transforms the instant to protobuf timestamp performing the smearing around the leap seconds.static com.google.protobuf.Timestamp
toProtobufTimestamp
(Instant instant) Transforms the instant to protobuf timestamp performing the smearing around the leap seconds.static String
toString
(long instant) Returns the instant formatted as UTC yyyy-MM-DDTHH:mm:ss.SSSZstatic long
toTaiMillisec
(long instant) static long
toUnixMillisec
(long instant) Transforms instant to UNIX time expressed in milliseconds since 1970toUtc
(long instant) 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
-
Field Details
-
INVALID_INSTANT
public static final long INVALID_INSTANT- See Also:
-
MAX_INSTANT
public static final long MAX_INSTANT- See Also:
-
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- See Also:
-
-
Constructor Details
-
TimeEncoding
public TimeEncoding()
-
-
Method Details
-
setUp
public static void setUp() -
setUp
-
getWallclockTime
public static long getWallclockTime()Returns the current operating system time but converted to Yamcs instant.- Returns:
-
getWallclockHresTime
Sane asgetWallclockTime()
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
Returns the instant formatted as UTC yyyy-MM-DDTHH:mm:ss.SSSZIf the value is smalle than
MIN_INSTANT
it returns -inf If the value is larger thanMAX_INSTANT
it returns +inf- Parameters:
instant
-- Returns:
-
toOrdinalDateTime
Returns the instant formatted as UTC yyyy-DDDTHH:mm:ss.SSS- Parameters:
instant
-- Returns:
-
toWinCompatibleDateTime
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
-
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 epochfineTime
- number of 1/256 seconds- Returns:
-
toGpsTime
Conversion from instant to GPS time.- Parameters:
instant
- yamcs time- Returns:
- GPS time
-
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
-
fromUtc
-
getTaiUtcConversionTable
-
parse
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
-
fromUnixPicos
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
Transforms aCalendar
from UNIX (millisec since 1970) to instant -
fromDate
Transforms aDate
from UNIX (millisec since 1970) to instant -
fromJavaInstant
Transforms aInstant
from UNIX (millisec since 1970) to instant -
toCalendar
Transforms instant into aCalendar
containing milliseconds since 1970- Parameters:
instant
- Yamcs instant
-
toJavaInstant
Transforms instant into aInstant
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
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
Transforms the instant to protobuf timestamp performing the smearing around the leap seconds.- Parameters:
instant
- - the instant to be converted- Returns:
- See Also:
-
isSetUp
public static boolean isSetUp()returns true if thesetUp()
method has been called to load the leap second table.If this method returns false, any call to the UTC conversion functions will throw a NullPointerException
-