Class TimeUtils

java.lang.Object
cern.nxcals.api.utils.TimeUtils

public final class TimeUtils extends Object
  • Field Details

    • CONVERT_EPOCH_NANOS_TO_SECONDS_VALUE

      public static final long CONVERT_EPOCH_NANOS_TO_SECONDS_VALUE
      See Also:
    • SECONDS_IN_DAY

      public static final long SECONDS_IN_DAY
      See Also:
    • NANOS_IN_DAY

      public static final long NANOS_IN_DAY
      See Also:
    • MILLIS_IN_HOUR

      public static final long MILLIS_IN_HOUR
  • Method Details

    • truncateToHours

      public static long truncateToHours(long timestamp)
    • getTimePartition

      public static long getTimePartition(long timestamp, TimeUtils.TimeSplits max)
    • getInstantFromNanos

      public static Instant getInstantFromNanos(long timeInNanos)
      Converts a long with the number of nanoseconds since epoch into its Instant counterpart.
      Parameters:
      timeInNanos - the number of seconds since epoch.
      Returns:
      a new Instant.
    • getTimestampFromNanos

      public static 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 Instant instantTime)
      Converts an Instant into a long with the number of nanoseconds since epoch.
      Parameters:
      instantTime - the Instant to be converter.
      Returns:
      a long with the number of nanoseconds since epoch.
    • getNanosFromString

      public static long getNanosFromString(@NonNull @NonNull String timeString)
      Converts a String into 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 Timestamp getTimestampFromInstant(@NonNull @NonNull Instant instant)
    • getTimestampFromString

      public static Timestamp getTimestampFromString(@NonNull @NonNull String timeString)
    • getInstantFromString

      public static Instant getInstantFromString(@NonNull @NonNull String timeString)
      Converts a String into its Instant counterpart.
      Parameters:
      timeString - a string with the following format: yyyy-MM-dd HH:mm:ss.nnnnnnnnn
      Returns:
      a new instance of Instant.
    • getStringFromInstant

      public static String getStringFromInstant(@NonNull @NonNull Instant instant)
      Converts an Instant into its String counterpart. It will use UTC timezone
      Parameters:
      instant - the instant to be converted.
      Returns:
      a String with the following format: yyyy-MM-dd HH:mm:ss.nnnnnnnnn
    • getStringDateFromInstant

      public static String getStringDateFromInstant(@NonNull @NonNull Instant instant)
    • getStringDateFromNano

      @Deprecated public static String getStringDateFromNano(long timestampInNano)
      Deprecated.
      - Typo here, please use TimeUtils.getStringDateFromNanos()
    • getStringDateFromNanos

      public static String getStringDateFromNanos(long timestampInNanos)
    • getStringFromNanos

      public static String getStringFromNanos(long timestampInNanos)
    • getMilisFromStringDate

      public static long getMilisFromStringDate(@NonNull @NonNull String timeString)
    • getNanosFromLocal

      public static long getNanosFromLocal(LocalDateTime localDateTime, ZoneId zoneId)