Package org.apache.cassandra.cql3
Class Duration
- java.lang.Object
-
- org.apache.cassandra.cql3.Duration
-
public final class Duration extends java.lang.Object
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
Fields Modifier and Type Field Description static int
DAYS_PER_WEEK
static int
MONTHS_PER_YEAR
static long
NANOS_PER_HOUR
static long
NANOS_PER_MICRO
static long
NANOS_PER_MILLI
static long
NANOS_PER_MINUTE
static long
NANOS_PER_SECOND
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
addTo(long timeInMillis)
Adds this duration to the specified time in milliseconds.boolean
equals(java.lang.Object obj)
static long
floorTime(long timeInNanos, Duration duration)
Rounds a time down to the closest multiple of a duration.static long
floorTimestamp(long timeInMillis, Duration duration, long startingTimeInMillis)
Rounds a timestamp down to the closest multiple of a duration.static Duration
from(java.lang.String input)
Converts aString
into a duration.int
getDays()
int
getMonths()
long
getNanoseconds()
boolean
hasDayPrecision()
Checks if that duration has a day precision (nothing bellow the day level).int
hashCode()
boolean
hasMillisecondPrecision()
Checks if that duration has a millisecond precision (nothing bellow the millisecond level).boolean
isNegative()
Checks if the duration is negative.static Duration
newInstance(int months, int days, long nanoseconds)
long
substractFrom(long timeInMillis)
Substracts this duration from the specified time in milliseconds.java.lang.String
toString()
-
-
-
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 aString
into 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
: millisecondsus
orµ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
- theString
to 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:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hasDayPrecision
public boolean hasDayPrecision()
Checks if that duration has a day precision (nothing bellow the day level).- Returns:
true
if that duration has a day precision,false
otherwise
-
hasMillisecondPrecision
public boolean hasMillisecondPrecision()
Checks if that duration has a millisecond precision (nothing bellow the millisecond level).- Returns:
true
if that duration has a millisecond precision,false
otherwise
-
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:
true
if the duration is negative,false
otherwise
-
-