Class DateTimeUtil

java.lang.Object
com.bluebell.greenhouse.platform.util.datetime.DateTimeUtil

public final class DateTimeUtil extends Object
Handles manipulating dates & times.
Version:
1.0.12
Author:
Stephen Prizio
  • Method Details

    • getSupportedTimeZones

      public static SortedSet<String> getSupportedTimeZones()
      Returns a list of supported time zones in bluebell.
      Returns:
      TreeSet
    • isValidTimeZone

      public static boolean isValidTimeZone(String timeZone)
      Validates the given time zone string.
      Parameters:
      timeZone - timezone
      Returns:
      true if a ZoneId can be extracted
    • now

      public static LocalDateTime now()
      Returns the current date & time, offset to the system-configured time zone.
      Returns:
      LocalDateTime
    • now

      public static LocalDateTime now(ZoneId zoneId)
      Returns the current date & time, offset to the given timezone.
      Parameters:
      zoneId - ZoneId
      Returns:
      LocalDateTime
    • convertToUtc

      public static LocalDateTime convertToUtc(LocalDateTime localDateTime, ZoneId fromZoneId)
      Converts the given local date time to utc.
      Parameters:
      localDateTime - LocalDateTime
      fromZoneId - ZoneId
      Returns:
      local date time in utc
    • isDateWithinInterval

      public static boolean isDateWithinInterval(LocalDateTime compare, LocalDateTime start, LocalDateTime end)
      Returns true if the compare date is within the start and end date.
      Parameters:
      compare - compare date & time
      start - start interval
      end - end interval
      Returns:
      true if date is within the interval
    • getDateTimeInUtcForStringAndZone

      public static LocalDateTime getDateTimeInUtcForStringAndZone(String parse, String format, ZoneId fromZoneId)
      Converts an iso date time string into utc time.
      Parameters:
      parse - string to parse
      format - date time format
      fromZoneId - ZoneId
      Returns:
      LocalDateTime
    • getDateTimeInZoneForUtcDateTime

      public static LocalDateTime getDateTimeInZoneForUtcDateTime(LocalDateTime utcDateTime, ZoneId toZoneId)
      Converts a utc date time into the specified zone's date & time.
      Parameters:
      utcDateTime - the UTC date time
      toZoneId - ZoneId
      Returns:
      LocalDateTime
    • getDateTimeInUtcForZoneAwareString

      public static LocalDateTime getDateTimeInUtcForZoneAwareString(String parse)
      Takes a string with zone offset info and parses it into a utc date time.
      Parameters:
      parse - string to parse
      Returns:
      LocalDateTime
    • parseIsoDateOrDateTime

      public static LocalDateTime parseIsoDateOrDateTime(String parse)
      Parses an ISO-8601 date, local date-time, or offset-aware date-time into a LocalDateTime. Offset-aware values are normalized to UTC while date-only values are converted to the start of day.
      Parameters:
      parse - string to parse
      Returns:
      parsed LocalDateTime
    • toUnixTimestamp

      public static long toUnixTimestamp(LocalDate localDate)
      Converts the given LocalDate into a unix timestamp using UTC midnight.
      Parameters:
      localDate - LocalDate
      Returns:
      unix timestamp in seconds
    • toUnixTimestamp

      public static long toUnixTimestamp(LocalDate localDate, ZoneId zoneId)
      Converts the given LocalDate into a unix timestamp using the provided ZoneId.
      Parameters:
      localDate - LocalDate
      zoneId - ZoneId
      Returns:
      unix timestamp in seconds
    • toUnixTimestamp

      public static long toUnixTimestamp(LocalDateTime localDateTime)
      Converts the given LocalDateTime into a unix timestamp assuming UTC.
      Parameters:
      localDateTime - LocalDateTime
      Returns:
      unix timestamp in seconds
    • toUnixTimestamp

      public static long toUnixTimestamp(LocalDateTime localDateTime, ZoneId zoneId)
      Converts the given LocalDateTime into a unix timestamp using the provided ZoneId.
      Parameters:
      localDateTime - LocalDateTime
      zoneId - ZoneId
      Returns:
      unix timestamp in seconds
    • formatDuration

      public static String formatDuration(long totalSeconds)
      Formats a duration of time in seconds into a broken down format of Xd Xh Xm Xs.
      Parameters:
      totalSeconds - duration in seconds
      Returns:
      ex: 2d 4h 6m 8s