Package org.apache.hc.core5.util
Class Deadline
java.lang.Object
org.apache.hc.core5.util.Deadline
A deadline based on a UNIX time, the elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January
1970.
- Since:
- 5.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic DeadlineCalculates a deadline with a given time in milliseconds plus a given time value.static DeadlineCalculates a deadline from now plus a given time value.booleanFormats this deadline.Formats the deadline value as a string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".freeze()static DeadlinefromUnixMilliseconds(long value) Creates a deadline from a UNIX time in milliseconds.longgetValue()Gets the UNIX time deadline value.inthashCode()booleanisBefore(long millis) Returns whether this deadline occurs before the given time in milliseconds.booleanReturns whether the deadline has expired.booleanisMax()Returns whether this deadline is the maximum deadline.booleanisMin()Returns whether this deadline is the minimum deadline.booleanReturns whether this deadline has not expired.Returns the smaller of this and anotherDeadline.static DeadlineCreates a deadline from a string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".longReturns the difference in milliseconds between the deadline and now.Returns the difference as a TimeValue between the deadline and now.toString()
-
Field Details
-
DATE_FORMAT
The format used for parsing and formatting dates.- See Also:
-
MAX_VALUE
The maximum (longest-lived) deadline. -
MIN_VALUE
The minimum (shortest-lived) deadline.
-
-
Method Details
-
calculate
Calculates a deadline with a given time in milliseconds plus a given time value. Non-positive time values represent an indefinite timeout without a deadline.- Parameters:
timeMillis- A time in UNIX milliseconds, usually the current time.timeValue- time value to add totimeMillis.- Returns:
- a deadline representing the current time plus the given time value.
-
calculate
Calculates a deadline from now plus a given time value. Non-positive time values represent an indefinite timeout without a deadline.- Parameters:
timeValue- time value to add totimeMillis.- Returns:
- a deadline representing the current time plus the given time value.
-
fromUnixMilliseconds
Creates a deadline from a UNIX time in milliseconds.- Parameters:
value- a UNIX time in milliseconds.- Returns:
- a new deadline.
-
parse
Creates a deadline from a string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".- Parameters:
source- a string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".- Returns:
- a deadline from a string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".
- Throws:
ParseException- if the specified source string cannot be parsed.
-
equals
-
hashCode
public int hashCode() -
format
Formats this deadline.- Parameters:
overdueTimeUnit- the time unit to show how much over the deadline we are.- Returns:
- a formatted string.
-
formatTarget
Formats the deadline value as a string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".- Returns:
- a formatted string in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZ".
-
freeze
-
getValue
public long getValue()Gets the UNIX time deadline value.- Returns:
- the UNIX time deadline value.
-
isBefore
public boolean isBefore(long millis) Returns whether this deadline occurs before the given time in milliseconds.- Parameters:
millis- the time to compare.- Returns:
- whether this deadline occurs before the given time in milliseconds.
-
isExpired
public boolean isExpired()Returns whether the deadline has expired.- Returns:
- whether the deadline has expired.
-
isMax
public boolean isMax()Returns whether this deadline is the maximum deadline.- Returns:
- whether this deadline is the maximum deadline.
-
isMin
public boolean isMin()Returns whether this deadline is the minimum deadline.- Returns:
- whether this deadline is the minimum deadline.
-
isNotExpired
public boolean isNotExpired()Returns whether this deadline has not expired.- Returns:
- whether this deadline has not expired.
-
min
Returns the smaller of this and anotherDeadline.- Parameters:
other- another deadline.- Returns:
- the smaller of
thisandother.
-
remaining
public long remaining()Returns the difference in milliseconds between the deadline and now.- Returns:
- the different in milliseconds between the deadline and now.
-
remainingTimeValue
Returns the difference as a TimeValue between the deadline and now.- Returns:
- Returns the different as a TimeValue between the deadline and now.
-
toString
-