Class Timespan

java.lang.Object
ch.njol.skript.util.Timespan
All Implemented Interfaces:
YggdrasilSerializable, Comparable<Timespan>, TemporalAmount

public class Timespan extends Object implements YggdrasilSerializable, Comparable<Timespan>, TemporalAmount
Represents a duration of time, such as 2 days, similar to Duration.
  • Constructor Details

    • Timespan

      public Timespan()
    • Timespan

      public Timespan(long millis)
      Builds a Timespan from the given milliseconds.
      Parameters:
      millis - The milliseconds of Timespan
    • Timespan

      public Timespan(Timespan.TimePeriod timePeriod, long time)
      Builds a Timespan from the given long parameter of a specific Timespan.TimePeriod.
      Parameters:
      timePeriod - The requested TimePeriod
      time - The time of the requested TimePeriod
  • Method Details

    • parse

      @Nullable public static @Nullable Timespan parse(String value)
    • parse

      @Nullable public static @Nullable Timespan parse(String value, ParseContext context)
    • fromDuration

      @Contract("_ -> new") @NotNull public static @NotNull Timespan fromDuration(@NotNull @NotNull Duration duration)
      Creates a Timespan from the given Duration.
      Parameters:
      duration - The duration to convert to a Timespan.
      Returns:
      A new Timespan object representing the duration, based on its milliseconds.
    • infinite

      @Contract(value=" -> new", pure=true) @NotNull public static @NotNull Timespan infinite()
      Creates a Timespan that represents an infinite duration.
      Returns:
      A new Timespan object representing an infinite duration.
    • toString

      public static String toString(long millis)
    • toString

      public static String toString(long millis, int flags)
    • fromTicks

      @Deprecated(since="2.10.0", forRemoval=true) public static Timespan fromTicks(long ticks)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • fromTicks_i

      @Deprecated(since="2.10.0", forRemoval=true) public static Timespan fromTicks_i(long ticks)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getMilliSeconds

      @Deprecated(since="2.10.0", forRemoval=true) public long getMilliSeconds()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getAs(TimePeriod) instead.
    • getTicks

      @Deprecated(since="2.10.0", forRemoval=true) public long getTicks()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getAs(TimePeriod) instead.
    • getTicks_i

      @Deprecated(since="2.10.0", forRemoval=true) public long getTicks_i()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use getAs(TimePeriod) instead.
    • isInfinite

      public boolean isInfinite()
      Returns:
      Whether this timespan represents an infinite timespan.
    • getAs

      public long getAs(Timespan.TimePeriod timePeriod)
      Returns:
      the amount of TimePeriod this timespan represents.
    • getDuration

      public Duration getDuration()
      Returns:
      Converts this timespan to a Duration.
    • add

      @Contract(value="_ -> new", pure=true) public Timespan add(Timespan timespan)
      Safely adds the specified timespan to this timespan, handling potential overflow.
      Parameters:
      timespan - The timespan to add to this timespan
      Returns:
      a new Timespan object
    • subtract

      @Contract(value="_ -> new", pure=true) public Timespan subtract(Timespan timespan)
      Safely subtracts the specified timespan from this timespan, handling potential underflow.
      Parameters:
      timespan - The timespan to subtract from this timespan
      Returns:
      a new Timespan object
    • multiply

      @Contract(value="_ -> new", pure=true) public Timespan multiply(double scalar)
      Safely multiplies a timespan by a non-negative scalar value.
      Parameters:
      scalar - A non-negative (>=0) value to multiply by
      Returns:
      The multiplied timespan.
    • divide

      @Contract(value="_ -> new", pure=true) public Timespan divide(double scalar)
      Safely divides a timespan by a non-negative scalar value.
      Parameters:
      scalar - A non-negative (>=0) value to divide by
      Returns:
      The divided timespan.
    • divide

      @Contract(pure=true) public double divide(Timespan other)
      Safely divides a timespan by another timespan.
      Parameters:
      other - A timespan to divide by
      Returns:
      The result.
    • difference

      public Timespan difference(Timespan timespan)
      Calculates the difference between the specified timespan and this timespan.
      Parameters:
      timespan - The timespan to get the difference of
      Returns:
      a new Timespan object
    • get

      public long get(TemporalUnit unit)
      Specified by:
      get in interface TemporalAmount
    • getUnits

      public List<TemporalUnit> getUnits()
      Specified by:
      getUnits in interface TemporalAmount
    • addTo

      public Temporal addTo(Temporal temporal)
      Specified by:
      addTo in interface TemporalAmount
    • subtractFrom

      public Temporal subtractFrom(Temporal temporal)
      Specified by:
      subtractFrom in interface TemporalAmount
    • compareTo

      public int compareTo(@Nullable @Nullable Timespan time)
      Specified by:
      compareTo in interface Comparable<Timespan>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable @Nullable Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(int flags)