Package org.somda.sdc.common.util
Class AnyDateTime
- java.lang.Object
-
- org.somda.sdc.common.util.AnyDateTime
-
public class AnyDateTime extends Object
Date-time object that supports local and offset time depending on construction parameters.Required as both local and offset representation are supported by XML Schema DateTime.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAnyDateTime.Else<T>An alternative lambda to be executed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AnyDateTimecreate(LocalDateTime local)Creates an instance with local date and time.static AnyDateTimecreate(OffsetDateTime offset)Creates an instance with offset date and time.AnyDateTime.Else<OffsetDateTime>doIfLocal(Consumer<LocalDateTime> consumer)Convenience function to be called if object was created with local date and time.AnyDateTime.Else<LocalDateTime>doIfOffset(Consumer<OffsetDateTime> consumer)Convenience function to be called if object was created with offset date and time.booleanequals(Object object)Compares two AnyDateTime objects on equality.OffsetDateTimeforceOffset()Returns a offset date and time no matter if a local time was given on construction.OffsetDateTimeforceOffset(ZoneOffset localOffset)Returns a offset date and time no matter if a local date and time was given on construction.Optional<LocalDateTime>getLocal()Gets the local date and time.Optional<OffsetDateTime>getOffset()Gets the offset date and time.inthashCode()StringtoString()
-
-
-
Method Detail
-
create
public static AnyDateTime create(LocalDateTime local)
Creates an instance with local date and time.- Parameters:
local- the local date and time to set.- Returns:
- a new instance.
-
create
public static AnyDateTime create(OffsetDateTime offset)
Creates an instance with offset date and time.- Parameters:
offset- the offset date and time to set.- Returns:
- a new instance.
-
getOffset
public Optional<OffsetDateTime> getOffset()
Gets the offset date and time.- Returns:
- the offset time or
Optional.empty()if local time was given on construction.
-
getLocal
public Optional<LocalDateTime> getLocal()
Gets the local date and time.- Returns:
- the local date and time or
Optional.empty()if offset date and time was given on construction.
-
forceOffset
public OffsetDateTime forceOffset()
Returns a offset date and time no matter if a local time was given on construction.- Returns:
- the offset date and time given on construction or a offset date and time based on the local date and time and default-derived timezone.
-
forceOffset
public OffsetDateTime forceOffset(ZoneOffset localOffset)
Returns a offset date and time no matter if a local date and time was given on construction.- Parameters:
localOffset- the time zone offset to use in case this objects stores local time.- Returns:
- the offset time given on construction or a offset time based on the local time and given timezone.
-
doIfLocal
public AnyDateTime.Else<OffsetDateTime> doIfLocal(Consumer<LocalDateTime> consumer)
Convenience function to be called if object was created with local date and time.- Parameters:
consumer- the consumer for the local date and time.- Returns:
- an alternative call, i.e. in case offset date and time was given.
-
doIfOffset
public AnyDateTime.Else<LocalDateTime> doIfOffset(Consumer<OffsetDateTime> consumer)
Convenience function to be called if object was created with offset date and time.- Parameters:
consumer- the consumer for the offset date and time.- Returns:
- an alternative call, i.e. in case local date and time was given.
-
equals
public boolean equals(Object object)
Compares two AnyDateTime objects on equality.
-
-