Class DateTimeUtils

java.lang.Object
rs.baselib.util.DateTimeUtils

public class DateTimeUtils extends Object
Utils for date and time.
Author:
ralph
  • Constructor Details

    • DateTimeUtils

      public DateTimeUtils()
  • Method Details

    • isBefore

      public static boolean isBefore(ZonedDateTime time, long millisBefore)
      Returns whether a given time is earlier than the given duration.
      Parameters:
      time - the time to compare
      millisBefore - ms before now
      Returns:
      true when time is before that time span
    • isBefore

      public static boolean isBefore(ZonedDateTime time, TemporalAmount amountBefore)
      Returns whether a given time is earlier than the given duration.
      Parameters:
      time - the time to compare
      amountBefore - the duration before now
      Returns:
      true when time is before that time span
    • isBefore

      public static boolean isBefore(ZonedDateTime time, ZonedDateTime other)
      Returns whether a given time is earlier than the given other time.
      Parameters:
      time - the time to compare
      other - the other time
      Returns:
      true when time is before that other time
    • isAfter

      public static boolean isAfter(ZonedDateTime time, long millisAfter)
      Returns whether a given time is later than the given duration.
      Parameters:
      time - the time to compare
      millisAfter - the duration after now
      Returns:
      true when time is after that duration from now
    • isAfter

      public static boolean isAfter(ZonedDateTime time, TemporalAmount amountAfter)
      Returns whether a given time is earlier than the given duration.
      Parameters:
      time - the time to compare
      amountAfter - the duration after now
      Returns:
      true when time is after that duration from now
    • isAfter

      public static boolean isAfter(ZonedDateTime time, ZonedDateTime other)
      Returns whether a given time is earlier than the other time.
      Parameters:
      time - the time to compare
      other - the other time
      Returns:
      true when time is after that other time
    • getStartOfDay

      public static ZonedDateTime getStartOfDay(ZonedDateTime time)
      Returns the timestamp at the start of the day (00:00:00.000).
      Parameters:
      time - time of a day
      Returns:
      beginning of that day
    • getEndOfDay

      public static ZonedDateTime getEndOfDay(ZonedDateTime time)
      Returns the timestamp at the start of the day (23:59:59.999).
      Parameters:
      time - time of a day
      Returns:
      end of that day
    • parseZonedDateTime

      public static ZonedDateTime parseZonedDateTime(String s)
      Tries to parse the string in order to retrieve a date/time with default ZoneId and default time 00:00:00.
      Parameters:
      s - - the string to be parsed
      Returns:
      the ZonedDateTime object or null if not successful.
    • parseZonedDateTime

      public static ZonedDateTime parseZonedDateTime(String s, ZoneId defaultZone)
      Tries to parse the string in order to retrieve a date/time default time 00:00:00.
      Parameters:
      s - - the string to be parsed
      defaultZone - - default zone ID to be used
      Returns:
      the ZonedDateTime object or null if not successful.
    • parseZonedDateTimeWithEndOfDay

      public static ZonedDateTime parseZonedDateTimeWithEndOfDay(String s)
      Tries to parse the string in order to retrieve a date/time with default ZoneId and default time 23:59:59.999999999.
      Parameters:
      s - - the string to be parsed
      Returns:
      the ZonedDateTime object or null if not successful.
    • parseZonedDateTimeWithEndOfDay

      public static ZonedDateTime parseZonedDateTimeWithEndOfDay(String s, ZoneId defaultZone)
      Tries to parse the string in order to retrieve a date/time with default time 23:59:59.999999999.
      Parameters:
      s - - the string to be parsed
      defaultZone - - default zone ID to be used
      Returns:
      the ZonedDateTime object or null if not successful.
    • parseZonedDateTime

      public static ZonedDateTime parseZonedDateTime(String s, LocalTime defaultTime)
      Tries to parse the string in order to retrieve a date/time with default ZoneId and given default time.
      Parameters:
      s - - the string to be parsed
      defaultTime - - default time to be used
      Returns:
      the ZonedDateTime object or null if not successful.
    • parseZonedDateTime

      public static ZonedDateTime parseZonedDateTime(String s, LocalTime defaultTime, ZoneId defaultZone)
      Tries to parse the string in order to retrieve a date/time with default ZoneId and given default time and zoneId.
      Parameters:
      s - - the string to be parsed
      defaultTime - - default time to be used
      defaultZone - - default zone ID to be used
      Returns:
      the ZonedDateTime object or null if not successful.