Class TimeEmojifier

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.util.TimeEmojifier

public class TimeEmojifier extends Object
Utility class that converts timestamps to emoji.
  • Field Details

    • quarterHour

      @NonNull private static final @NonNull Duration quarterHour
      A quarter of an hour (i.e. 15 minutes).
    • threeQuartersHour

      @NonNull private static final @NonNull Duration threeQuartersHour
      Three quarters of an hour (i.e. 45 minutes).
    • halfHour

      @NonNull private static final @NonNull Duration halfHour
      One half of an hour (i.e. 30 minutes).
    • emojiMap

      @NonNull private static final @NonNull Map<Integer, TimeEmojifier.HourEmoji> emojiMap
      All clock emoji in the Unicode standard.
  • Constructor Details

    • TimeEmojifier

      public TimeEmojifier()
  • Method Details

    • toClockEmoji

      @Contract(pure=true) @NonNull public static @NonNull String toClockEmoji(@NonNull @NonNull LocalTime time)

      Converts a given LocalTime to a fitting clock emoji.

      If the

      invalid reference
      LocalTime#minute
      part is closer to the hour, then the TimeEmojifier.HourEmoji.onHour() emoji for the specific hour

      is returned, otherwise the TimeEmojifier.HourEmoji.halfHour()].

      Parameters:
      time - The time that shall be converted to an emoji. Works for both 12-hour- and 24-hour-based clocks.
      Returns:
      A fitting clock emoji for the given time.
    • roundToHalfHour

      @Contract(pure=true) @NonNull private static @NonNull LocalTime roundToHalfHour(@NonNull @NonNull LocalTime time)

      Replaces the

      invalid reference
      LocalTime#minute
      part of the given LocalTime with either `00:00` or `00:30`, depending on

      whether the minute part is closer to the full hour or closer to the half hour. For example, 09:24 becomes 09:30, while 17:46 becomes 18:00.

      The given time is shifted at most by 15 minutes.

      Parameters:
      time - The time to be rounded.
      Returns:
      The same time, rounded to the closest full or half hour.