Class TemporalUtils
java.lang.Object
de.xima.fc.utils.TemporalUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether two durations are equal to within the given threshold.static InstantinstantToMicrosecondPrecision(Instant instant) Converts the given instant to millisecond precision, i.e. rounds down to the nearest microsecond.static <T extends TemporalAccessor & Comparable<T>>
Tmax(T lhs, T rhs) static LocalTimeplusNoWrapAround(LocalTime time, Duration amountToAdd) Adds the given duration to the given local time, without wrap around.static LocalTimeplusNullOnWrapAround(LocalTime time, Duration amountToAdd) Adds the given duration to the given local time, without wrap around.static ZonedDateTimeplusNullOnWrapAround(ZonedDateTime dateTime, Duration amountToAdd) Same specification asplusNoWrapAround(LocalTime, Duration), but with zoned date times instead.static booleantemporalHasZone(Temporal temporal) Checks whether the given temporal object has azone.static DayOfWeektoDayOfWeek(Instant instant, ZoneId targetZone) static InstantConverts the date time from the source time zone to an instant.static InstanttoInstant(LocalDateTime sourceDateTime, ZoneId sourceZone) Converts the date time from the source time zone to an instant.static LocalDateTimetoLocalDateTime(Instant instant, ZoneId targetZone) Converts an instant to a local date time in a given time zone.static LocalDateTimetoLocalDateTime(LocalDate sourceDate, LocalTime sourceTime, ZoneId sourceZone, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.static LocalDateTimetoLocalDateTime(LocalDateTime sourceDateTime, ZoneId sourceZone, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.static longtoUnixTimestampSeconds(Instant lastModified) Converts the given instant to a Unix timestamp in seconds.static ZonedDateTimetoZonedDateTime(Instant instant, ZoneId targetZone) Converts an instant to a zoned date time in a given time zone.static ZonedDateTimetoZonedDateTime(LocalDate sourceDate, LocalTime sourceTime, ZoneId sourceZone, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.static ZonedDateTimetoZonedDateTime(ZonedDateTime sourceDateTime, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.
-
Field Details
-
ONE_SECOND
A duration of one second.
-
-
Method Details
-
equals
Checks whether two durations are equal to within the given threshold.- Parameters:
lhs- First duration to compare.nullis consideredDuration.ZERO.rhs- Second duration to compare.nullis consideredDuration.ZERO.threshold- Threshold for the comparison.- Returns:
trueif|rhs-lhs| <= threshold, orfalseotherwise.
-
instantToMicrosecondPrecision
-
max
- Type Parameters:
T- Type of the temporal.- Parameters:
lhs- First temporal to compare.rhs- Second temporal to compare.- Returns:
- The temporal that represents a point in time further in the future.
-
plusNoWrapAround
Adds the given duration to the given local time, without wrap around.- 01:00 + 30min = 01:30
- 23:30 + 60min = 23:59 (
LocalTime.MAX) - 00:30 - 60min = 00:00
- 04:00 + 40h = 23:59 (
LocalTime.MAX)
- Parameters:
time- Time to which to add an amount.amountToAdd- Amount to add.- Returns:
- The result of adding the given amount to the given time, capped at
00:00and23:59.
-
plusNullOnWrapAround
Adds the given duration to the given local time, without wrap around.- 01:00 + 30min = 01:30
- 01:00 - 60min = 00:00
- 23:30 + 30min =
LocalTime.MAX - 23:30 + 60min = null
- 00:30 - 60min = null
- 04:00 + 40hours = null
- Parameters:
time- Time to which to add an amount.amountToAdd- Amount to add.- Returns:
- The result of adding the given amount to the given time, capped at
00:00and23:59.
-
plusNullOnWrapAround
Same specification asplusNoWrapAround(LocalTime, Duration), but with zoned date times instead.- Parameters:
dateTime- Time to which to add an amount.amountToAdd- Amount to add.- Returns:
- The result of adding the given amount to the given time, capped at
00:00and23:59.
-
temporalHasZone
-
toDayOfWeek
-
toInstant
Converts the date time from the source time zone to an instant.- Parameters:
sourceDate- Date to convert.sourceTime- Time to convert.sourceZone- Source time zone.- Returns:
- The given source date time, converted form the source time zone to an instant.
-
toInstant
Converts the date time from the source time zone to an instant.- Parameters:
sourceDateTime- Date time to convert.sourceZone- Source time zone.- Returns:
- The given source date time, converted form the source time zone to an instant.
-
toLocalDateTime
Converts an instant to a local date time in a given time zone.- Parameters:
instant- An instant to convert.targetZone- Target time zone.- Returns:
- The date and time of the instant in the target time zone.
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(LocalDate sourceDate, LocalTime sourceTime, ZoneId sourceZone, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.- Parameters:
sourceDate- Date to convert.sourceTime- Time to convert.sourceZone- Source time zone.targetZone- Target time zone.- Returns:
- The given source date time, converted form the source time zone to the target time zone.
-
toLocalDateTime
public static LocalDateTime toLocalDateTime(LocalDateTime sourceDateTime, ZoneId sourceZone, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.- Parameters:
sourceDateTime- Date time to convert.sourceZone- Source time zone.targetZone- Target time zone.- Returns:
- The given source date time, converted form the source time zone to the target time zone.
-
toUnixTimestampSeconds
Converts the given instant to a Unix timestamp in seconds.- Parameters:
lastModified- Instant to convert.- Returns:
- Unix timestamp in seconds, or 0 if the given instant is null.
-
toZonedDateTime
Converts an instant to a zoned date time in a given time zone.- Parameters:
instant- An instant to convert.targetZone- Target time zone.- Returns:
- The date and time of the instant in the target time zone.
-
toZonedDateTime
public static ZonedDateTime toZonedDateTime(LocalDate sourceDate, LocalTime sourceTime, ZoneId sourceZone, ZoneId targetZone) Converts the date time from the source time zone to the target time zone.- Parameters:
sourceDate- Date to convert.sourceTime- Time to convert.sourceZone- Source time zone.targetZone- Target time zone.- Returns:
- The given source date time, converted form the source time zone to the target time zone.
-
toZonedDateTime
Converts the date time from the source time zone to the target time zone.- Parameters:
sourceDateTime- Source date time to convert.targetZone- Target time zone.- Returns:
- The given source date time, converted form the source time zone to the target time zone.
-