Package cern.nxcals.api.utils
Class TimeUtils
- java.lang.Object
-
- cern.nxcals.api.utils.TimeUtils
-
public final class TimeUtils extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTimeUtils.TimeSplitsRepresents various time splits used in NXCALS.
-
Field Summary
Fields Modifier and Type Field Description static longCONVERT_EPOCH_NANOS_TO_SECONDS_VALUEstatic longMILLIS_IN_HOURstatic longNANOS_IN_DAYstatic longSECONDS_IN_DAY
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.time.InstantgetInstantFromNanos(long timeInNanos)Converts a long with the number of nanoseconds since epoch into itsInstantcounterpart.static java.time.InstantgetInstantFromString(@NonNull java.lang.String timeString)Converts aStringinto itsInstantcounterpart.static longgetMilisFromStringDate(@NonNull java.lang.String timeString)static longgetNanosFromInstant(@NonNull java.time.Instant instantTime)Converts anInstantinto a long with the number of nanoseconds since epoch.static longgetNanosFromLocal(java.time.LocalDateTime localDateTime, java.time.ZoneId zoneId)static longgetNanosFromNow()Converts an current instant into a long with the number of nanoseconds since epoch.static longgetNanosFromString(@NonNull java.lang.String timeString)Converts aStringinto a long with the number of nanoseconds since epoch.static java.lang.StringgetStringDateFromInstant(@NonNull java.time.Instant instant)static java.lang.StringgetStringDateFromNano(long timestampInNano)Deprecated.- Typo here, please use TimeUtils.getStringDateFromNanos()static java.lang.StringgetStringDateFromNanos(long timestampInNanos)static java.lang.StringgetStringFromInstant(@NonNull java.time.Instant instant)Converts anInstantinto itsStringcounterpart.static java.lang.StringgetStringFromNanos(long timestampInNanos)static longgetTimePartition(long timestamp, TimeUtils.TimeSplits max)static java.sql.TimestampgetTimestampFromInstant(@NonNull java.time.Instant instant)static java.sql.TimestampgetTimestampFromNanos(long timeInNanos)Converts a long with the number of nanoseconds since epoch into Timestamp.static java.sql.TimestampgetTimestampFromString(@NonNull java.lang.String timeString)static longtruncateToHours(long timestamp)
-
-
-
Field Detail
-
CONVERT_EPOCH_NANOS_TO_SECONDS_VALUE
public static final long CONVERT_EPOCH_NANOS_TO_SECONDS_VALUE
- See Also:
- Constant Field Values
-
SECONDS_IN_DAY
public static final long SECONDS_IN_DAY
- See Also:
- Constant Field Values
-
NANOS_IN_DAY
public static final long NANOS_IN_DAY
- See Also:
- Constant Field Values
-
MILLIS_IN_HOUR
public static final long MILLIS_IN_HOUR
-
-
Method Detail
-
truncateToHours
public static long truncateToHours(long timestamp)
-
getTimePartition
public static long getTimePartition(long timestamp, TimeUtils.TimeSplits max)
-
getInstantFromNanos
public static java.time.Instant getInstantFromNanos(long timeInNanos)
Converts a long with the number of nanoseconds since epoch into itsInstantcounterpart.- Parameters:
timeInNanos- the number of seconds since epoch.- Returns:
- a new
Instant.
-
getTimestampFromNanos
public static java.sql.Timestamp getTimestampFromNanos(long timeInNanos)
Converts a long with the number of nanoseconds since epoch into Timestamp.- Parameters:
timeInNanos-- Returns:
- a new Timestamp
-
getNanosFromInstant
public static long getNanosFromInstant(@NonNull @NonNull java.time.Instant instantTime)Converts anInstantinto a long with the number of nanoseconds since epoch.- Parameters:
instantTime- theInstantto be converter.- Returns:
- a long with the number of nanoseconds since epoch.
-
getNanosFromString
public static long getNanosFromString(@NonNull @NonNull java.lang.String timeString)Converts aStringinto a long with the number of nanoseconds since epoch.- Parameters:
timeString- a string with the following format: yyyy-MM-dd HH:mm:ss.nnnnnnnnn- Returns:
- a long with the number of nanoseconds since epoch.
-
getNanosFromNow
public static long getNanosFromNow()
Converts an current instant into a long with the number of nanoseconds since epoch.- Returns:
- a long with the number of nanoseconds since epoch.
-
getTimestampFromInstant
public static java.sql.Timestamp getTimestampFromInstant(@NonNull @NonNull java.time.Instant instant)
-
getTimestampFromString
public static java.sql.Timestamp getTimestampFromString(@NonNull @NonNull java.lang.String timeString)
-
getInstantFromString
public static java.time.Instant getInstantFromString(@NonNull @NonNull java.lang.String timeString)Converts aStringinto itsInstantcounterpart.- Parameters:
timeString- a string with the following format: yyyy-MM-dd HH:mm:ss.nnnnnnnnn- Returns:
- a new instance of
Instant.
-
getStringFromInstant
public static java.lang.String getStringFromInstant(@NonNull @NonNull java.time.Instant instant)Converts anInstantinto itsStringcounterpart. It will use UTC timezone- Parameters:
instant- the instant to be converted.- Returns:
- a
Stringwith the following format: yyyy-MM-dd HH:mm:ss.nnnnnnnnn
-
getStringDateFromInstant
public static java.lang.String getStringDateFromInstant(@NonNull @NonNull java.time.Instant instant)
-
getStringDateFromNano
@Deprecated public static java.lang.String getStringDateFromNano(long timestampInNano)
Deprecated.- Typo here, please use TimeUtils.getStringDateFromNanos()
-
getStringDateFromNanos
public static java.lang.String getStringDateFromNanos(long timestampInNanos)
-
getStringFromNanos
public static java.lang.String getStringFromNanos(long timestampInNanos)
-
getMilisFromStringDate
public static long getMilisFromStringDate(@NonNull @NonNull java.lang.String timeString)
-
getNanosFromLocal
public static long getNanosFromLocal(java.time.LocalDateTime localDateTime, java.time.ZoneId zoneId)
-
-