Class TimeUtils
java.lang.Object
org.epics.archiverappliance.common.TimeUtils
There are various versions of timestamps in the archiver appliance.
The most commonly used one is Instant and is the one exposed in the APIs.
The other versions are follows
- A long epoch seconds + optional nanos - The seconds part is the java epoch seconds, as returned by System.currentMillis()/1000
- A long epoch milliseconds - This is the java epoch milliseconds, as returned by System.currentMillis()
- A JCA timestamp - This is what comes out of JCA
- A year/secondsintoyear/nanos combination - This is what is used in the protocol buffer storage plugin.
- A ISO 8601 date time - We use JODA to convert from/to a ISO 8601 string
- Author:
- mshankar
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longEPICS epoch starts at January 1, 1990 UTC.static org.apache.logging.log4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbreakIntoIntervals(Instant start, Instant end, long binSizeInSeconds) Break a time span into smaller time spans according to binSize The first time span has the start time and the end of the first bin.breakIntoYearlyTimeSpans(Instant start, Instant end) Given a start time and an end time, this method breaks this span into a sequence of spans each of which fits within a year.static shortcomputeYearForEpochSeconds(long epochseconds) Determine year from java epoch seconds.static Instantstatic InstantconvertFromEpochMillis(long epochMillis) static InstantconvertFromEpochSeconds(long epochSeconds, int nanos) static InstantconvertFromISO8601String(String tsstr) static InstantconvertFromJCATimeStamp(gov.aps.jca.dbr.TimeStamp jcats) static YearSecondTimestampconvertFromPVTimeStamp(org.epics.pva.data.PVAStructure timeStampPVStructure) Convert the timeStamp from a pvAccess normative type to YearSecondTimestampstatic Instantstatic longstatic longstatic StringconvertToHumanReadableString(long epochSeconds) static Stringstatic StringconvertToISO8601String(long epochSeconds) static Stringstatic longconvertToLocalEpochMillis(long epochMillis) static longconvertToTenthsOfASecond(long epochSeconds, int nanos) Event rate rate limiting uses a tenths of a seconds units to cater to monitor intervals of 0.1 seconds, 0.5 seconds etc..static YearSecondTimestampconvertToYearSecondTimestamp(long epochSeconds) static YearSecondTimestampconvertToYearSecondTimestamp(gov.aps.jca.dbr.TimeStamp jcats) static YearSecondTimestampstatic Instantstatic InstantfromString(String timestampString, Instant defaultTime) static longGets the current epoch milli seconds in the UTC timezonestatic longGets the current epoch seconds in the UTC timezonestatic shortGet the current year in the UTC timezonestatic InstantgetEndOfYear(int year) static InstantgetNextPartitionFirstSecond(Instant ts, PartitionGranularity granularity) Given an epoch seconds and a granularity, this method gives you the first second in the next partition as epoch seconds.static StringgetPartitionName(Instant ts, PartitionGranularity granularity) Returns a partition name for the given epoch second based on the partition granularity.static InstantgetPreviousPartitionLastSecond(Instant ts, PartitionGranularity granularity) Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds.static intgetSecondsIntoYear(long epochseconds) Convert Java EPOCH seconds to a seconds into yearstatic intgetSecondsIntoYear(Instant instant) Convert Java EPOCH seconds to a seconds into yearstatic longstatic InstantgetStartOfYear(int year) static longgetStartOfYearInSeconds(int year) static longgetStartOfYearInSeconds(long epochseconds) static longgetStartOfYearInSeconds(short year) In the protocol buffer storage plugin, we send the year as a shortstatic shortstatic booleanWhether we are in DST for a particular time in the servers default timezone.static Instantstatic InstantminusHours(Instant ts, int hours) static Instantnow()Gets "now" as a Instant in the UTC timezonestatic Instantstatic Instantstatic TimestamptoSQLTimeStamp(Instant instant)
-
Field Details
-
EPICS_EPOCH_2_JAVA_EPOCH_OFFSET
public static final long EPICS_EPOCH_2_JAVA_EPOCH_OFFSETEPICS epoch starts at January 1, 1990 UTC. This constant contains the offset that must be added to epicstimestamps to generate java timestamps.- See Also:
-
logger
public static org.apache.logging.log4j.Logger logger
-
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
convertFromEpochSeconds
-
convertFromEpochMillis
-
convertFromJCATimeStamp
-
convertFromYearSecondTimestamp
-
convertFromISO8601String
-
convertFromDateTimeStringWithOffset
-
convertToEpochSeconds
-
convertToEpochMillis
-
convertToYearSecondTimestamp
-
convertToYearSecondTimestamp
-
convertToYearSecondTimestamp
-
convertToISO8601String
-
convertToISO8601String
-
convertToHumanReadableString
-
convertToHumanReadableString
-
convertToLocalEpochMillis
public static long convertToLocalEpochMillis(long epochMillis) -
getStartOfCurrentYearInSeconds
public static long getStartOfCurrentYearInSeconds() -
getStartOfYearInSeconds
public static long getStartOfYearInSeconds(int year) -
getStartOfYear
-
getYear
-
getStartOfYearInSeconds
public static long getStartOfYearInSeconds(long epochseconds) -
getStartOfYearInSeconds
public static long getStartOfYearInSeconds(short year) In the protocol buffer storage plugin, we send the year as a short- Parameters:
year- Year- Returns:
- startOfYearInEpochSeconds
-
getEndOfYear
-
getSecondsIntoYear
Convert Java EPOCH seconds to a seconds into year- Parameters:
instant-- Returns:
- SecondsIntoYear The difference in Seconds
-
getSecondsIntoYear
public static int getSecondsIntoYear(long epochseconds) Convert Java EPOCH seconds to a seconds into year- Parameters:
epochseconds-- Returns:
- SecondsIntoYear The difference in Seconds
-
computeYearForEpochSeconds
public static short computeYearForEpochSeconds(long epochseconds) Determine year from java epoch seconds.- Parameters:
epochseconds-- Returns:
- YearForEpochSeconds
-
getCurrentYear
public static short getCurrentYear()Get the current year in the UTC timezone- Returns:
- CurrentYear
-
getCurrentEpochSeconds
public static long getCurrentEpochSeconds()Gets the current epoch seconds in the UTC timezone- Returns:
- currentEpochSeconds
-
getCurrentEpochMilliSeconds
public static long getCurrentEpochMilliSeconds()Gets the current epoch milli seconds in the UTC timezone- Returns:
- currentEpochMilliSeconds
-
now
Gets "now" as a Instant in the UTC timezone- Returns:
- now A Instant in the UTC timezone
-
toSQLTimeStamp
-
fromSQLTimeStamp
-
plusHours
-
minusHours
-
plusDays
-
minusDays
-
breakIntoYearlyTimeSpans
Given a start time and an end time, this method breaks this span into a sequence of spans each of which fits within a year. Used where data is partitioned by year....- Parameters:
start- The start timeend- The end time- Returns:
- breakIntoYearlyTimeSpans
-
getPartitionName
Returns a partition name for the given epoch second based on the partition granularity.- Parameters:
ts-granularity- Partition granularity of the file.- Returns:
- PartitionName
-
getNextPartitionFirstSecond
Given an epoch seconds and a granularity, this method gives you the first second in the next partition as epoch seconds.- Parameters:
ts-granularity- Partition granularity of the file.- Returns:
- NextPartitionFirstSecond
-
getPreviousPartitionLastSecond
Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds.- Parameters:
ts-granularity- Partition granularity of the file.- Returns:
- PreviousPartitionLastSecond
-
convertToTenthsOfASecond
public static long convertToTenthsOfASecond(long epochSeconds, int nanos) throws NumberFormatException Event rate rate limiting uses a tenths of a seconds units to cater to monitor intervals of 0.1 seconds, 0.5 seconds etc.. This converts a epochSeconds+nanos to time in terms of tenths of a second.- Parameters:
epochSeconds-nanos-- Returns:
- TenthsOfASecond
- Throws:
NumberFormatException-
-
isDST
Whether we are in DST for a particular time in the servers default timezone. Mostly used by Matlab.- Parameters:
ts- Instant- Returns:
- boolean True or False
-
convertFromPVTimeStamp
public static YearSecondTimestamp convertFromPVTimeStamp(org.epics.pva.data.PVAStructure timeStampPVStructure) Convert the timeStamp from a pvAccess normative type to YearSecondTimestamp- Parameters:
timeStampPVStructure-- Returns:
- Timestamp
-
breakIntoIntervals
Break a time span into smaller time spans according to binSize The first time span has the start time and the end of the first bin. The next one has the end of the first bin and the start of the second bin. The last time span has the end as its end. This is sometimes used to try to speed up retrieval when using post processors over a large time span.- Parameters:
start- Instant startend- Instant endbinSizeInSeconds-- Returns:
- TimeSpan The list of smaller time spans according to binSize
-
fromString
public static Instant fromString(String timestampString, Instant defaultTime) throws IllegalArgumentException - Throws:
IllegalArgumentException
-