Class TimeUtils

java.lang.Object
org.epics.archiverappliance.common.TimeUtils

public class TimeUtils extends Object
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
  1. A long epoch seconds + optional nanos - The seconds part is the java epoch seconds, as returned by System.currentMillis()/1000
  2. A long epoch milliseconds - This is the java epoch milliseconds, as returned by System.currentMillis()
  3. A JCA timestamp - This is what comes out of JCA
  4. A year/secondsintoyear/nanos combination - This is what is used in the protocol buffer storage plugin.
  5. A ISO 8601 date time - We use JODA to convert from/to a ISO 8601 string
This class contains utilities to convert various forms of timestamps to/from the Instant.
Author:
mshankar
  • Field Details

    • EPICS_EPOCH_2_JAVA_EPOCH_OFFSET

      public static final long EPICS_EPOCH_2_JAVA_EPOCH_OFFSET
      EPICS 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

      public static Instant convertFromEpochSeconds(long epochSeconds, int nanos)
    • convertFromEpochMillis

      public static Instant convertFromEpochMillis(long epochMillis)
    • convertFromJCATimeStamp

      public static Instant convertFromJCATimeStamp(gov.aps.jca.dbr.TimeStamp jcats)
    • convertFromYearSecondTimestamp

      public static Instant convertFromYearSecondTimestamp(YearSecondTimestamp ysts)
    • convertFromISO8601String

      public static Instant convertFromISO8601String(String tsstr)
    • convertFromDateTimeStringWithOffset

      public static Instant convertFromDateTimeStringWithOffset(String tsstr)
    • convertToEpochSeconds

      public static long convertToEpochSeconds(Instant ts)
    • convertToEpochMillis

      public static long convertToEpochMillis(Instant ts)
    • convertToYearSecondTimestamp

      public static YearSecondTimestamp convertToYearSecondTimestamp(Instant ts)
    • convertToYearSecondTimestamp

      public static YearSecondTimestamp convertToYearSecondTimestamp(gov.aps.jca.dbr.TimeStamp jcats)
    • convertToYearSecondTimestamp

      public static YearSecondTimestamp convertToYearSecondTimestamp(long epochSeconds)
    • convertToISO8601String

      public static String convertToISO8601String(Instant ts)
    • convertToISO8601String

      public static String convertToISO8601String(long epochSeconds)
    • convertToHumanReadableString

      public static String convertToHumanReadableString(Instant ts)
    • convertToHumanReadableString

      public static String convertToHumanReadableString(long epochSeconds)
    • convertToLocalEpochMillis

      public static long convertToLocalEpochMillis(long epochMillis)
    • getStartOfCurrentYearInSeconds

      public static long getStartOfCurrentYearInSeconds()
    • getStartOfYearInSeconds

      public static long getStartOfYearInSeconds(int year)
    • getStartOfYear

      public static Instant getStartOfYear(int year)
    • getYear

      public static short getYear(Instant instant)
    • 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

      public static Instant getEndOfYear(int year)
    • getSecondsIntoYear

      public static int getSecondsIntoYear(Instant instant)
      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

      public static Instant now()
      Gets "now" as a Instant in the UTC timezone
      Returns:
      now A Instant in the UTC timezone
    • toSQLTimeStamp

      public static Timestamp toSQLTimeStamp(Instant instant)
    • fromSQLTimeStamp

      public static Instant fromSQLTimeStamp(Timestamp ts)
    • plusHours

      public static Instant plusHours(Instant ts, int hours)
    • minusHours

      public static Instant minusHours(Instant ts, int hours)
    • plusDays

      public static Instant plusDays(Instant ts, int days)
    • minusDays

      public static Instant minusDays(Instant ts, int days)
    • breakIntoYearlyTimeSpans

      public static List<TimeSpan> 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. Used where data is partitioned by year....
      Parameters:
      start - The start time
      end - The end time
      Returns:
      breakIntoYearlyTimeSpans  
    • getPartitionName

      public static String getPartitionName(Instant ts, PartitionGranularity granularity)
      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

      public static Instant getNextPartitionFirstSecond(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.
      Parameters:
      ts -  
      granularity - Partition granularity of the file.
      Returns:
      NextPartitionFirstSecond  
    • getPreviousPartitionLastSecond

      public static Instant getPreviousPartitionLastSecond(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.
      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

      public static boolean isDST(Instant ts)
      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

      public static List<TimeSpan> breakIntoIntervals(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. 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 start
      end - Instant end
      binSizeInSeconds -  
      Returns:
      TimeSpan The list of smaller time spans according to binSize
    • fromString

      public static Instant fromString(String timestampString, Instant defaultTime) throws IllegalArgumentException
      Throws:
      IllegalArgumentException