Class TimeUtil


  • public class TimeUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getDateTimeString​(java.time.OffsetDateTime time)
      Returns a prettier String-representation of a OffsetDateTime object
      static long getDiscordTimestamp​(long millisTimestamp)
      Converts the provided epoch millisecond timestamp to a Discord Snowflake.
      static java.time.OffsetDateTime getTimeCreated​(long entityId)
      Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
      static java.time.OffsetDateTime getTimeCreated​(ISnowflake entity)
      Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TimeUtil

        public TimeUtil()
    • Method Detail

      • getDiscordTimestamp

        public static long getDiscordTimestamp​(long millisTimestamp)
        Converts the provided epoch millisecond timestamp to a Discord Snowflake.
        This can be used as a marker/pivot for MessageHistory creation.
        Parameters:
        millisTimestamp - The epoch millis to convert
        Returns:
        Shifted epoch millis for Discord
      • getTimeCreated

        @Nonnull
        public static java.time.OffsetDateTime getTimeCreated​(long entityId)
        Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id. This returns the creation-time of the actual entity on Discords side, not inside JDA.
        Parameters:
        entityId - The id of the JDA entity where the creation-time should be determined for
        Returns:
        The creation time of the JDA entity as OffsetDateTime
      • getTimeCreated

        @Nonnull
        public static java.time.OffsetDateTime getTimeCreated​(@Nonnull
                                                              ISnowflake entity)
        Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id. This returns the creation-time of the actual entity on Discords side, not inside JDA.
        Parameters:
        entity - The JDA entity where the creation-time should be determined for
        Returns:
        The creation time of the JDA entity as OffsetDateTime
        Throws:
        java.lang.IllegalArgumentException - If the provided entity is null
      • getDateTimeString

        @Nonnull
        public static java.lang.String getDateTimeString​(@Nonnull
                                                         java.time.OffsetDateTime time)
        Returns a prettier String-representation of a OffsetDateTime object
        Parameters:
        time - The OffsetDateTime object to format
        Returns:
        The String of the formatted OffsetDateTime