Package com.nt.udc.util
Class Interval
java.lang.Object
com.nt.udc.util.Interval
Implementation of an Interval which is not available in the java.time library
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInterval
(ZonedDateTime earliestStart, ZonedDateTime latestEnd) internal constructor for creating an interval from ZoneDateTimes. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checks if the supplied Interval is wholly contained within this interval.boolean
contains
(ZonedDateTime timestamp) Contains logic is inclusive of start time, but exclusive of end time.boolean
static final Interval
create a new Inverval from an existing Intervalstatic final Interval
from
(ZonedDateTime earliestStart, ZonedDateTime latestEnd) creates an Interval from two supplied ZoneDateTimes.static final Interval
fromUTC
(long earliestStart, long latestEnd) creates an Interval from to supplied longs representing epoch milliseconds.getEnd()
gets the end time for the Intervallong
gets the epoch millisecond time for the Interval end time.long
gets the epoch millisecond time for the Interval start time.getStart()
gets the start time for the Intervalint
hashCode()
boolean
checks if the supplied Interval overlaps with this IntervaltoString()
static final ZonedDateTime
toUTC
(long millis) Creates a ZonedDateTime from a long that represents epoch time in milliseconds.static final ZonedDateTime
toUTC
(ZonedDateTime zdt) Converts a ZonedDateTime to UTC time
-
Field Details
-
MAX_UTC
-
-
Constructor Details
-
Interval
internal constructor for creating an interval from ZoneDateTimes.- Parameters:
earliestStart
- the earliest startlatestEnd
- the latest end
-
-
Method Details
-
from
creates an Interval from two supplied ZoneDateTimes. The dates should be supplied in Chronological order. If they are not....then they will be ordered from earliest to latest. Null supplied dates will be converted to timenow in UTC/GMT format.- Parameters:
earliestStart
- the start time for the intervallatestEnd
- the end time for the interval- Returns:
- the interval
-
fromUTC
creates an Interval from to supplied longs representing epoch milliseconds. The resulting start and end ZonedDateTimes will be created in UTC format.- Parameters:
earliestStart
- the easliest start time in epoch millisecondslatestEnd
- he latest end time in epoch milliseconds. Pass in Long.MAX_VALUE to represent infinity- Returns:
- the newly created Interval in UTC time zone.
-
toUTC
Converts a ZonedDateTime to UTC time- Parameters:
zdt
- the supplied ZoneDateTime that should be represented in UTC time- Returns:
- a ZoneDateTime in UTC time
-
toUTC
Creates a ZonedDateTime from a long that represents epoch time in milliseconds.- Parameters:
millis
- epoch time in milliseconds- Returns:
- a ZonedDateTime in UTC time zone
-
from
create a new Inverval from an existing Interval- Parameters:
interval
- the existing Interval from which a new instance will be created.- Returns:
- a new instance of a copy constructed Interval
-
getEnd
gets the end time for the Interval- Returns:
- the end time for the Interval
-
getStart
gets the start time for the Interval- Returns:
- the start time for the Interval
-
getEpochMilliEnd
public long getEpochMilliEnd()gets the epoch millisecond time for the Interval end time. Will return Long.MAX_VALUE if the end time is infinity- Returns:
- the epoch millisecond time for the Interval end time
-
getEpochMilliStart
public long getEpochMilliStart()gets the epoch millisecond time for the Interval start time.- Returns:
- the epoch millisecond time for the Interval start time
-
hashCode
public int hashCode() -
equals
-
contains
Contains logic is inclusive of start time, but exclusive of end time.- Parameters:
timestamp
- null equals now time. This is implemented same as JodaTime lib for backward compatibility- Returns:
- true if supplied date is contained in the Interval.
-
overlaps
checks if the supplied Interval overlaps with this Interval- Parameters:
otherInterval
- the supplied Interval to check against- Returns:
- true if the supplied Interval overlaps with this Interval. The endpoint logic is exclusive.
-
toDuration
-
contains
checks if the supplied Interval is wholly contained within this interval.- Parameters:
otherInterval
- the supplied Interval to check against- Returns:
- true if the supplied Interval is completely contained within this Interval.
-
toString
-