Package org.apache.cassandra.cql3
Class Duration
java.lang.Object
org.apache.cassandra.cql3.Duration
Represents 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
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final longstatic final longstatic final longstatic final longstatic final long -
Method Summary
Modifier and TypeMethodDescriptionlongaddTo(long timeInMillis) Adds this duration to the specified time in milliseconds.booleanstatic longRounds 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 DurationConverts aStringinto a duration.intgetDays()intlongbooleanChecks if that duration has a day precision (nothing bellow the day level).inthashCode()booleanChecks if that duration has a millisecond precision (nothing bellow the millisecond level).booleanChecks 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.toString()
-
Field Details
-
NANOS_PER_MICRO
public static final long NANOS_PER_MICRO- See Also:
-
NANOS_PER_MILLI
public static final long NANOS_PER_MILLI- See Also:
-
NANOS_PER_SECOND
public static final long NANOS_PER_SECOND- See Also:
-
NANOS_PER_MINUTE
public static final long NANOS_PER_MINUTE- See Also:
-
NANOS_PER_HOUR
public static final long NANOS_PER_HOUR- See Also:
-
DAYS_PER_WEEK
public static final int DAYS_PER_WEEK- See Also:
-
MONTHS_PER_YEAR
public static final int MONTHS_PER_YEAR- See Also:
-
-
Method Details
-
newInstance
-
from
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() -
equals
-
toString
-
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
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
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
-