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 java.sql.Timestamp 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
Fields Modifier and Type Field Description static long
EPICS_EPOCH_2_JAVA_EPOCH_OFFSET
EPICS epoch starts at January 1, 1990 UTC.static org.apache.log4j.Logger
logger
-
Constructor Summary
Constructors Constructor Description TimeUtils()
-
Method Summary
Modifier and Type Method Description static List<TimeSpan>
breakIntoIntervals(Timestamp start, Timestamp 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.static List<TimeSpan>
breakIntoYearlyTimeSpans(Timestamp start, Timestamp 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 short
computeYearForEpochSeconds(long epochseconds)
Determine year from java epoch seconds.static Timestamp
convertFromDateTimeStringWithOffset(String tsstr)
static Timestamp
convertFromEpochMillis(long epochMillis)
static Timestamp
convertFromEpochSeconds(long epochSeconds, int nanos)
static Timestamp
convertFromISO8601String(String tsstr)
static Timestamp
convertFromJCATimeStamp(gov.aps.jca.dbr.TimeStamp jcats)
static Timestamp
convertFromYearSecondTimestamp(YearSecondTimestamp ysts)
static long
convertToEpochMillis(Timestamp ts)
static long
convertToEpochSeconds(Timestamp ts)
static String
convertToHumanReadableString(long epochSeconds)
static String
convertToHumanReadableString(Timestamp ts)
static String
convertToISO8601String(long epochSeconds)
static String
convertToISO8601String(Timestamp ts)
static long
convertToLocalEpochMillis(long epochMillis)
static long
convertToTenthsOfASecond(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 YearSecondTimestamp
convertToYearSecondTimestamp(long epochSeconds)
static YearSecondTimestamp
convertToYearSecondTimestamp(gov.aps.jca.dbr.TimeStamp jcats)
static YearSecondTimestamp
convertToYearSecondTimestamp(Timestamp ts)
static long
getCurrentEpochMilliSeconds()
Gets the current epoch milli seconds in the UTC timezonestatic long
getCurrentEpochSeconds()
Gets the current epoch seconds in the UTC timezonestatic short
getCurrentYear()
Get the current year in the UTC timezonestatic Timestamp
getEndOfYear(int year)
static long
getNextPartitionFirstSecond(long epochSeconds, PartitionGranularity granularity)
Given an epoch seconds and a granularity, this method gives you the first second in the next partition as epoch seconds.static String
getPartitionName(long epochSeconds, PartitionGranularity granularity)
Returns a partition name for the given epoch second based on the partition granularity.static long
getPreviousPartitionLastSecond(long epochSeconds, PartitionGranularity granularity)
Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds.static int
getSecondsIntoYear(long epochseconds)
Convert Java EPOCH seconds to a seconds into yearstatic int
getSecondsIntoYear(long epochseconds, long startOfYearInSeconds)
Convert Java EPOCH seconds to a seconds into year given the start of the year in EPOCH secondsstatic long
getStartOfCurrentDayInEpochSeconds()
static long
getStartOfCurrentYearInSeconds()
static Timestamp
getStartOfYear(int year)
static long
getStartOfYearInSeconds(int year)
static long
getStartOfYearInSeconds(long epochseconds)
static long
getStartOfYearInSeconds(short year)
In the protocol buffer storage plugin, we send the year as a shortstatic boolean
isDST(Timestamp ts)
Whether we are in DST for a particular time in the servers default timezone.static Timestamp
minusDays(Timestamp ts, int days)
static Timestamp
minusHours(Timestamp ts, int hours)
static Timestamp
now()
Gets "now" as a Timestamp in the UTC timezonestatic YearSecondTimestamp
nowYTS()
Gets "now" as a YearSecondTimestamp in the UTC timezonestatic Timestamp
plusDays(Timestamp ts, int days)
static Timestamp
plusHours(Timestamp ts, int hours)
-
-
-
Method Detail
-
convertFromEpochSeconds
public static Timestamp convertFromEpochSeconds(long epochSeconds, int nanos)
-
convertFromEpochMillis
public static Timestamp convertFromEpochMillis(long epochMillis)
-
convertFromJCATimeStamp
public static Timestamp convertFromJCATimeStamp(gov.aps.jca.dbr.TimeStamp jcats)
-
convertFromYearSecondTimestamp
public static Timestamp convertFromYearSecondTimestamp(YearSecondTimestamp ysts)
-
convertFromDateTimeStringWithOffset
public static Timestamp convertFromDateTimeStringWithOffset(String tsstr)
-
convertToEpochSeconds
public static long convertToEpochSeconds(Timestamp ts)
-
convertToEpochMillis
public static long convertToEpochMillis(Timestamp ts)
-
convertToYearSecondTimestamp
public static YearSecondTimestamp convertToYearSecondTimestamp(Timestamp ts)
-
convertToYearSecondTimestamp
public static YearSecondTimestamp convertToYearSecondTimestamp(gov.aps.jca.dbr.TimeStamp jcats)
-
convertToYearSecondTimestamp
public static YearSecondTimestamp convertToYearSecondTimestamp(long epochSeconds)
-
convertToISO8601String
public static String convertToISO8601String(long epochSeconds)
-
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 Timestamp getStartOfYear(int year)
-
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 Timestamp getEndOfYear(int year)
-
getStartOfCurrentDayInEpochSeconds
public static long getStartOfCurrentDayInEpochSeconds()
-
getSecondsIntoYear
public static int getSecondsIntoYear(long epochseconds, long startOfYearInSeconds)
Convert Java EPOCH seconds to a seconds into year given the start of the year in EPOCH seconds- Parameters:
epochseconds
-startOfYearInSeconds
-- 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 Timestamp now()
Gets "now" as a Timestamp in the UTC timezone- Returns:
- now A Timestamp in the UTC timezone
-
nowYTS
public static YearSecondTimestamp nowYTS()
Gets "now" as a YearSecondTimestamp in the UTC timezone- Returns:
- now A YearSecondTimestamp in the UTC timezone
-
breakIntoYearlyTimeSpans
public static List<TimeSpan> breakIntoYearlyTimeSpans(Timestamp start, Timestamp 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 timeend
- The end time- Returns:
- breakIntoYearlyTimeSpans
-
getPartitionName
public static String getPartitionName(long epochSeconds, PartitionGranularity granularity)
Returns a partition name for the given epoch second based on the partition granularity.- Parameters:
epochSeconds
-granularity
- Partition granularity of the file.- Returns:
- PartitionName
-
getNextPartitionFirstSecond
public static long getNextPartitionFirstSecond(long epochSeconds, PartitionGranularity granularity)
Given an epoch seconds and a granularity, this method gives you the first second in the next partition as epoch seconds.- Parameters:
epochSeconds
-granularity
- Partition granularity of the file.- Returns:
- NextPartitionFirstSecond
-
getPreviousPartitionLastSecond
public static long getPreviousPartitionLastSecond(long epochSeconds, PartitionGranularity granularity)
Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds.- Parameters:
epochSeconds
-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(Timestamp ts)
Whether we are in DST for a particular time in the servers default timezone. Mostly used by Matlab.- Parameters:
ts
- Timestamp- Returns:
- boolean True or False
-
breakIntoIntervals
public static List<TimeSpan> breakIntoIntervals(Timestamp start, Timestamp 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
- Timestamp startend
- Timestamp endbinSizeInSeconds
-- Returns:
- TimeSpan The list of smaller time spans according to binSize
-
-