Package org.apache.cassandra.cql3
Class Duration
- java.lang.Object
-
- org.apache.cassandra.cql3.Duration
-
public final class Duration extends java.lang.ObjectRepresents a duration. A durations store separately months, days, and seconds due to the fact that the number of days in a month varies, and a day can have 23 or 25 hours if a daylight saving is involved.
-
-
Field Summary
Fields Modifier and Type Field Description static intDAYS_PER_WEEKstatic intMONTHS_PER_YEARstatic longNANOS_PER_HOURstatic longNANOS_PER_MICROstatic longNANOS_PER_MILLIstatic longNANOS_PER_MINUTEstatic longNANOS_PER_SECOND
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddTo(long timeInMillis)Adds this duration to the specified time in milliseconds.booleanequals(java.lang.Object obj)static longfloorTime(long timeInNanos, Duration duration)Rounds a time down to the closest multiple of a duration.static longfloorTimestamp(long timeInMillis, Duration duration, long startingTimeInMillis)Rounds a timestamp down to the closest multiple of a duration.static Durationfrom(java.lang.String input)Converts aStringinto a duration.intgetDays()intgetMonths()longgetNanoseconds()booleanhasDayPrecision()Checks if that duration has a day precision (nothing bellow the day level).inthashCode()booleanhasMillisecondPrecision()Checks if that duration has a millisecond precision (nothing bellow the millisecond level).booleanisNegative()Checks if the duration is negative.static DurationnewInstance(int months, int days, long nanoseconds)longsubstractFrom(long timeInMillis)Substracts this duration from the specified time in milliseconds.java.lang.StringtoString()
-
-
-
Field Detail
-
NANOS_PER_MICRO
public static final long NANOS_PER_MICRO
- See Also:
- Constant Field Values
-
NANOS_PER_MILLI
public static final long NANOS_PER_MILLI
- See Also:
- Constant Field Values
-
NANOS_PER_SECOND
public static final long NANOS_PER_SECOND
- See Also:
- Constant Field Values
-
NANOS_PER_MINUTE
public static final long NANOS_PER_MINUTE
- See Also:
- Constant Field Values
-
NANOS_PER_HOUR
public static final long NANOS_PER_HOUR
- See Also:
- Constant Field Values
-
DAYS_PER_WEEK
public static final int DAYS_PER_WEEK
- See Also:
- Constant Field Values
-
MONTHS_PER_YEAR
public static final int MONTHS_PER_YEAR
- See Also:
- Constant Field Values
-
-
Method Detail
-
newInstance
public static Duration newInstance(int months, int days, long nanoseconds)
-
from
public static Duration from(java.lang.String input)
Converts aStringinto a duration.The accepted formats are:
- multiple digits followed by a time unit like: 12h30m where the time unit can be:
y: yearsm: monthsw: weeksd: daysh: hoursm: minutess: secondsms: millisecondsusorµs: microsecondsns: nanoseconds
- ISO 8601 format: P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W
- ISO 8601 alternative format: P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]
- Parameters:
input- theStringto convert- Returns:
- a number of nanoseconds
- multiple digits followed by a time unit like: 12h30m where the time unit can be:
-
getMonths
public int getMonths()
-
getDays
public int getDays()
-
getNanoseconds
public long getNanoseconds()
-
addTo
public long addTo(long timeInMillis)
Adds this duration to the specified time in milliseconds.- Parameters:
timeInMillis- the time to which the duration must be added- Returns:
- the specified time plus this duration
-
substractFrom
public long substractFrom(long timeInMillis)
Substracts this duration from the specified time in milliseconds.- Parameters:
timeInMillis- the time from which the duration must be substracted- Returns:
- the specified time minus this duration
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hasDayPrecision
public boolean hasDayPrecision()
Checks if that duration has a day precision (nothing bellow the day level).- Returns:
trueif that duration has a day precision,falseotherwise
-
hasMillisecondPrecision
public boolean hasMillisecondPrecision()
Checks if that duration has a millisecond precision (nothing bellow the millisecond level).- Returns:
trueif that duration has a millisecond precision,falseotherwise
-
floorTimestamp
public static long floorTimestamp(long timeInMillis, Duration duration, long startingTimeInMillis)Rounds a timestamp down to the closest multiple of a duration.- Parameters:
timeInMillis- the time to round in millisecondduration- the durationstartingTimeInMillis- the time offset in milliseconds- Returns:
- the timestamp rounded down to the closest multiple of the duration
-
floorTime
public static long floorTime(long timeInNanos, Duration duration)Rounds a time down to the closest multiple of a duration.- Parameters:
timeInNanos- the time of day in nanosecondsduration- the duration- Returns:
- the time rounded down to the closest multiple of the duration
-
isNegative
public boolean isNegative()
Checks if the duration is negative.- Returns:
trueif the duration is negative,falseotherwise
-
-