Package de.xima.fc.utils
Class TemporalUtils
- java.lang.Object
- 
- de.xima.fc.utils.TemporalUtils
 
- 
- 
Field SummaryFields Modifier and Type Field Description static DurationONE_SECONDA duration of one second.
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanequals(Duration lhs, Duration rhs, Duration threshold)Checks whether two durations are equal to within the given threshold.static InstantinstantToMicrosecondPrecision(Instant instant)Converts the given instant to millisecond precision, i.e.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 DayOfWeektoDayOfWeek(Instant instant, ZoneId targetZone)static InstanttoInstant(LocalDate sourceDate, LocalTime sourceTime, ZoneId sourceZone)Converts 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 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 Detail- 
ONE_SECONDpublic static final Duration ONE_SECOND A duration of one second.
 
- 
 - 
Method Detail- 
equalspublic static boolean equals(Duration lhs, Duration rhs, Duration threshold) Checks whether two durations are equal to within the given threshold.- Parameters:
- lhs- First duration to compare.- nullis considered- Duration.ZERO.
- rhs- Second duration to compare.- nullis considered- Duration.ZERO.
- threshold- Threshold for the comparison.
- Returns:
- trueif- |rhs-lhs| <= threshold, or- falseotherwise.
 
 - 
instantToMicrosecondPrecisionpublic static Instant instantToMicrosecondPrecision(Instant instant) Converts the given instant to millisecond precision, i.e. rounds down to the nearest microsecond.- Parameters:
- instant- Instant to convert.
- Returns:
- The given instant, rounded down to the nearest microsecond.
 
 - 
maxpublic static <T extends TemporalAccessor & Comparable<T>> T max(T lhs, T rhs) - 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.
 
 - 
plusNoWrapAroundpublic static LocalTime plusNoWrapAround(LocalTime time, Duration amountToAdd) 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.
 
 - 
plusNullOnWrapAroundpublic static LocalTime plusNullOnWrapAround(LocalTime time, Duration amountToAdd) 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.
 
 - 
plusNullOnWrapAroundpublic static ZonedDateTime plusNullOnWrapAround(ZonedDateTime dateTime, Duration amountToAdd) 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.
 
 - 
toDayOfWeekpublic static DayOfWeek toDayOfWeek(Instant instant, ZoneId targetZone) - Parameters:
- instant- An instant for which to get the day of week.
- targetZone- Target time zone in which to get the day of week.
- Returns:
- The day of week of the given instant, as measured in the given target time zone.
 
 - 
toInstantpublic static Instant toInstant(LocalDate sourceDate, LocalTime sourceTime, ZoneId sourceZone) 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.
 
 - 
toInstantpublic static Instant toInstant(LocalDateTime sourceDateTime, ZoneId sourceZone) 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.
 
 - 
toLocalDateTimepublic static LocalDateTime toLocalDateTime(Instant instant, ZoneId targetZone) 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.
 
 - 
toLocalDateTimepublic 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.
 
 - 
toLocalDateTimepublic 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.
 
 - 
toZonedDateTimepublic static ZonedDateTime toZonedDateTime(Instant instant, ZoneId targetZone) 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.
 
 - 
toZonedDateTimepublic 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.
 
 - 
toZonedDateTimepublic static ZonedDateTime toZonedDateTime(ZonedDateTime sourceDateTime, ZoneId targetZone) 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.
 
 
- 
 
-