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.int
difference
(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.double
Safely divides a timespan by another timespan.boolean
static @NotNull Timespan
fromDuration
(@NotNull Duration duration) static Timespan
fromTicks
(long ticks) Deprecated, for removal: This API element is subject to removal in a future version.static Timespan
fromTicks_i
(long ticks) Deprecated, for removal: This API element is subject to removal in a future version.UseTimespan(TimePeriod, long)
instead.long
get
(TemporalUnit unit) long
getAs
(Timespan.TimePeriod timePeriod) long
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)
instead.long
getTicks()
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)
instead.long
Deprecated, for removal: This API element is subject to removal in a future version.UsegetAs(TimePeriod)
instead.getUnits()
int
hashCode()
static @NotNull Timespan
infinite()
Creates aTimespan
that represents an infinite duration.boolean
multiply
(double scalar) Safely multiplies a timespan by a non-negative scalar value.static @Nullable Timespan
static @Nullable Timespan
parse
(String value, ParseContext context) Safely subtracts the specified timespan from this timespan, handling potential underflow.subtractFrom
(Temporal temporal) toString()
toString
(int flags) static String
toString
(long millis) static String
toString
(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 aTimespan
that 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:
get
in interfaceTemporalAmount
-
getUnits
- Specified by:
getUnits
in interfaceTemporalAmount
-
addTo
- Specified by:
addTo
in interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFrom
in interfaceTemporalAmount
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Timespan>
-
hashCode
public int hashCode() -
equals
-
toString
-
toString
-
Timespan(TimePeriod, long)
instead.