Package ch.njol.skript.util
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.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface ch.njol.yggdrasil.YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable -
Constructor Summary
ConstructorsConstructorDescriptionTimespan()Timespan(long millis) Builds a Timespan from the given milliseconds.Timespan(Timespan.TimePeriod timePeriod, long time) Builds a Timespan from the given long parameter of a specificTimespan.TimePeriod. -
Method Summary
Modifier and TypeMethodDescriptionSafely adds the specified timespan to this timespan, handling potential overflow.intdifference(Timespan timespan) Calculates the difference between the specified timespan and this timespan.divide(double scalar) Safely divides a timespan by a non-negative scalar value.doubleSafely divides a timespan by another timespan.booleanstatic @NotNull TimespanfromDuration(@NotNull Duration duration) static TimespanfromTicks(long ticks) Deprecated, for removal: This API element is subject to removal in a future version.static TimespanfromTicks_i(long ticks) Deprecated, for removal: This API element is subject to removal in a future version.UseTimespan(TimePeriod, long)instead.longget(TemporalUnit unit) longgetAs(Timespan.TimePeriod timePeriod) longDeprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)instead.longgetTicks()Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)instead.longDeprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)instead.getUnits()inthashCode()static @NotNull Timespaninfinite()Creates aTimespanthat represents an infinite duration.booleanmultiply(double scalar) Safely multiplies a timespan by a non-negative scalar value.static @Nullable Timespanstatic @Nullable Timespanparse(String value, ParseContext context) Safely subtracts the specified timespan from this timespan, handling potential underflow.subtractFrom(Temporal temporal) toString()toString(int flags) static StringtoString(long millis) static StringtoString(long millis, int flags)
-
Constructor Details
-
Timespan
public Timespan() -
Timespan
public Timespan(long millis) Builds a Timespan from the given milliseconds.- Parameters:
millis- The milliseconds of Timespan
-
Timespan
Builds a Timespan from the given long parameter of a specificTimespan.TimePeriod.- Parameters:
timePeriod- The requested TimePeriodtime- The time of the requested TimePeriod
-
-
Method Details
-
parse
-
parse
-
fromDuration
@Contract("_ -> new") @NotNull public static @NotNull Timespan fromDuration(@NotNull @NotNull Duration duration) - Parameters:
duration- The duration to convert to a Timespan.- Returns:
- A new Timespan object representing the duration, based on its milliseconds.
-
infinite
Creates aTimespanthat represents an infinite duration.- Returns:
- A new Timespan object representing an infinite duration.
-
toString
-
toString
-
fromTicks
Deprecated, for removal: This API element is subject to removal in a future version.UseTimespan(TimePeriod, long)instead. -
fromTicks_i
Deprecated, for removal: This API element is subject to removal in a future version.UseTimespan(TimePeriod, long)instead. -
getMilliSeconds
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)instead. -
getTicks
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)instead. -
getTicks_i
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)instead. -
isInfinite
public boolean isInfinite()- Returns:
- Whether this timespan represents an infinite timespan.
-
getAs
- Returns:
- the amount of TimePeriod this timespan represents.
-
getDuration
- Returns:
- Converts this timespan to a
Duration.
-
add
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
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
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
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
Safely divides a timespan by another timespan.- Parameters:
other- A timespan to divide by- Returns:
- The result.
-
difference
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
- Specified by:
getin interfaceTemporalAmount
-
getUnits
- Specified by:
getUnitsin interfaceTemporalAmount
-
addTo
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFromin interfaceTemporalAmount
-
compareTo
- Specified by:
compareToin interfaceComparable<Timespan>
-
hashCode
public int hashCode() -
equals
-
toString
-
toString
-
Timespan(TimePeriod, long)instead.