Class Time

java.lang.Object
io.github.syst3ms.skriptparser.util.Time
All Implemented Interfaces:
Comparable<Time>

public class Time extends Object implements Comparable<Time>
Represents a time, as one could see on a clock.
  • Field Details

    • TIME_FORMAT

      public static final String TIME_FORMAT
      See Also:
    • TIME_LOCALE

      public static final Locale TIME_LOCALE
    • LATEST

      public static final Time LATEST
      Returns the latest possible time, being 23:59:59.999.
    • MIDNIGHT

      public static final Time MIDNIGHT
      Represents midnight, at 12 PM.
    • NOON

      public static final Time NOON
      Represents noon, at 12 AM.
  • Method Details

    • now

      public static Time now()
      The current time, as it would be visible on a clock.
      Returns:
      the current time
    • of

      public static Time of(int hours, int minutes, int seconds, int millis)
      A time instance from given values.
      Parameters:
      hours - the hours, between 0 and 23
      minutes - the minutes, between 0 and 59
      seconds - the seconds, between 0 and 59
      millis - the milliseconds, between 0 and 999
      Returns:
      a new time instance
    • of

      public static Time of(LocalTime time)
      A time instance from a given LocalTime instance.
      Parameters:
      time - the time
      Returns:
      a new time instance
    • of

      public static Time of(SkriptDate date)
      A time instance from a given date.
      Parameters:
      date - the date
      Returns:
      a new time instance
    • parse

      public static Optional<Time> parse(String toParse)
      Parses a given string as a time, using one of the three patterns.
      Parameters:
      toParse - the string to parse
      Returns:
      an Optional describing the parsed Time instance, empty if no match was found.
      See Also:
      • DEFAULT_TIME_PATTERN
      • BRITISH_TIME_PATTERN
      • DETAILED_TIME_PATTERN
    • getHour

      public int getHour()
    • getMinute

      public int getMinute()
    • getSecond

      public int getSecond()
    • getMillis

      public int getMillis()
    • getTime

      public LocalTime getTime()
    • toMillis

      public int toMillis()
      Returns:
      the amount of milliseconds that passed since the start of the day
    • difference

      public Duration difference(Time other)
      The duration between two given time instances
      Parameters:
      other - the time instance to compare
      Returns:
      the duration between the instances, or ZERO if one instance is invalid
    • add

      public void add(Duration span)
      Add a Duration to this time.
      Parameters:
      span - Duration to add
    • subtract

      public void subtract(Duration span)
      Subtract a Duration from this time.
      Parameters:
      span - Duration to subtract
    • plus

      public Time plus(Duration span)
      Get a new instance of this time with the added Duration.
      Parameters:
      span - Duration to add to this Time
      Returns:
      new Time with the added Duration
    • minus

      public Time minus(Duration span)
      Get a new instance of this time with the subtracted Duration.
      Parameters:
      span - Duration to subtract from this Time
      Returns:
      new Time with the subtracted Duration
    • compareTo

      public int compareTo(Time other)
      Specified by:
      compareTo in interface Comparable<Time>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object