Package nl.vpro.util
Class TimeUtils
java.lang.Object
nl.vpro.util.TimeUtils
- Since:
- 0.45
- Author:
- Michiel Meeuwissen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ZonedDateTime
static final Duration
static final ZoneId
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @PolyNull Date
static @PolyNull Duration
null
safe version ofDuration.between(Temporal, Temporal)
.static @PolyNull Duration
durationOf
(@PolyNull Duration d) durationOf
(Date i) static boolean
parse
(CharSequence dateValue) Parses aCharSequence
to a duration.static @PolyNull Duration
parseDurationOrThrow
(@PolyNull CharSequence d) static Optional<LocalDateTime>
static LocalTime
static Optional<? extends TemporalAmount>
parseTemporalAmount
(@Nullable CharSequence d) Parses aCharSequence
to aTemporalAmount
.static Optional<ZonedDateTime>
parseZoned
(CharSequence parse) static @PolyNull Duration
roundToMillis
(@PolyNull Duration duration) Rounds the duration to the nearest millis (This may round up half a millis).static String
toParsableString
(Duration duration) static @PolyNull Instant
static @PolyNull Instant
truncatedTo
(@PolyNull Instant instant, @Nullable ChronoUnit unit)
-
Field Details
-
ZONE_ID
-
LOCAL_EPOCH
-
MAX_DURATION
-
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
parseZoned
-
parse
-
parseDuration
Parses aCharSequence
to a duration. This begins for checking emptyness (and returns then an emptyOptional
. Then it basically callsDuration.parse(CharSequence)
, but if that fails it has several fall backs:- Also a week notation like
PT2W
as defined by ISO-8601 is supported - Possible white space breaking the parsing will be ignored
- If the string looks like an unresolved (spring EL) variable, we'll parse to the empty optional
- If the string parses as a
Long
, it will be interpreted as a number of milliseconds - If the string would become a valid ISO-8601 duration by prefixing it with 'P' or 'PT', that will be done too, making those prefixes effectively optional, so that the string like '1s' will parse to one second.
- See Also:
- Also a week notation like
-
parseDurationOrThrow
- Since:
- 5.0
-
parseDuration
-
parseTemporalAmount
Parses aCharSequence
to aTemporalAmount
. First usingPeriod.parse(CharSequence)
, and than, if that fails, usingparseDuration(CharSequence)
-
toParsableString
-
parseLocalDateTime
- Since:
- 2.6
-
parseLocalDate
- Since:
- 4.0
-
durationOf
-
durationOf
-
durationOf
-
toSecondsInteger
-
toSeconds
-
toMillis
-
asDate
-
between
null
safe version ofDuration.between(Temporal, Temporal)
. If one or both of the arguments are null, the result isnull
too. -
isLarger
-
roundToMillis
Rounds the duration to the nearest millis (This may round up half a millis). -
truncatedTo
- Since:
- 2.34
-
truncated
- Since:
- 2.34
-
parseLocalTime
-