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.

  • Method Details

    • 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.
      Overrides:
      equals in class Object
      Parameters:
      object - the right-hand side to compare against with this object.
      Returns:
      true if all attributes equal true, otherwise false.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object