Module ical4j.core

Class TemporalAdapter<T extends Temporal>

java.lang.Object
net.fortuna.ical4j.model.TemporalAdapter<T>
Type Parameters:
T - A concrete implementation of Temporal
All Implemented Interfaces:
Serializable

public class TemporalAdapter<T extends Temporal> extends Object implements Serializable
The iCalendar specification supports multiple representations of date/time values, as outlined below. This class encapsulates a Temporal value and provides support for all corresponding representations in the specification. The recommended Temporal implementations for use with iCal4j are as follows:
  • LocalDate - represents an iCalendar DATE value as defined in section 3.3.4 of RFC5545
  • LocalDateTime - represents an iCalendar FORM #1: DATE-TIME value as defined in section 3.3.5 of RFC5545
  • Instant - represents an iCalendar FORM #2: DATE-TIME value as defined in section 3.3.5 of RFC5545
  • ZonedDateTime - represents an iCalendar FORM #3: DATE-TIME value as defined in section 3.3.5 of RFC5545
Note that where a local (i.e. floating) temporal type is used we need to apply a ZoneId for calculations such as recurrence inclusions and other date-based comparisons. Use isFloating(Temporal) to determine floating instances.
See Also:
  • Constructor Details

    • TemporalAdapter

      public TemporalAdapter(TemporalAdapter<T> adapter)
    • TemporalAdapter

      public TemporalAdapter(T temporal)
    • TemporalAdapter

      public TemporalAdapter(T temporal, TimeZoneRegistry timeZoneRegistry)
  • Method Details

    • getTemporal

      public T getTemporal()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(ZoneId zoneId)
    • toLocalTime

      public ZonedDateTime toLocalTime()
    • toLocalTime

      public ZonedDateTime toLocalTime(ZoneId zoneId)
    • toLocalTime

      public static ZonedDateTime toLocalTime(Temporal temporal, ZoneId zoneId)
    • parse

      public static <T extends Temporal> TemporalAdapter<T> parse(String value) throws DateTimeParseException
      Parse a string representation of a temporal value.
      Parameters:
      value - a string representing a temporal
      Returns:
      an adapter containing the parsed temporal value and format type
      Throws:
      DateTimeParseException - if the string cannot be parsed
    • parse

      public static <T extends Temporal> TemporalAdapter<T> parse(String value, CalendarDateFormat parseFormat) throws DateTimeParseException
      Throws:
      DateTimeParseException
    • parse

      public static TemporalAdapter<ZonedDateTime> parse(String value, ZoneId zoneId)
      Parse a string representation of a temporal value applicable to the specified timezone.
      Parameters:
      value - a string representing a floating temporal value
      zoneId - a timezone applied to the parsed value
      Returns:
      an adapter containing the parsed temporal value
      Throws:
      DateTimeParseException - if the string cannot be parsed
    • parse

      public static TemporalAdapter<ZonedDateTime> parse(String value, TzId tzId)
      Parse a string representation of a temporal value applicable to the specified timezone.
      Parameters:
      value - a string representing a floating temporal value
      tzId - a timezone applied to the parsed value
      Returns:
      an adapter containing the parsed temporal value
      Throws:
      DateTimeParseException - if the string cannot be parsed
    • parse

      public static TemporalAdapter<ZonedDateTime> parse(String value, TzId tzId, TimeZoneRegistry timeZoneRegistry)
      Parameters:
      value - a string representing a floating temporal value
      tzId - a timezone applied to the parsed value
      timeZoneRegistry - timezone definitions
      Returns:
    • from

      public static TemporalAdapter<?> from(Date date)
      This method provides support for conversion of legacy Date and DateTime instances to temporal values.
      Parameters:
      date - a date/time instance
      Returns:
      a temporal adapter instance equivalent to the specified date/time value
    • isFloating

      public static boolean isFloating(Temporal date)
      Indicates whether the temporal type represents a "floating" date/time value.
      Returns:
      true if the temporal type is floating, otherwise false
    • isUtc

      public static boolean isUtc(Temporal date)
      Indicates whether the temporal type represents a UTC date/time value. A temporal is defined as UTC if it matches any of the following: - does not have associated zone information (e.g. Instant or OffsetDateTime) - where offset is supported the offset must be zero
      Returns:
      true if the temporal type is in UTC time, otherwise false
    • isDateTimePrecision

      public static boolean isDateTimePrecision(Temporal date)
      Indicates whether the temporal type represents a date/time value.
      Returns:
      true if the temporal type has DATE-TIME precision, otherwise false
    • isBefore

      public static <T extends Temporal> boolean isBefore(T date1, T date2)
    • isAfter

      public static <T extends Temporal> boolean isAfter(T date1, T date2)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object