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.boolean
static Timespan
fromDuration
(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 @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
-
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. -
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
-
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.