Package net.time4j

Class GeneralTimestamp<C>

java.lang.Object
net.time4j.GeneralTimestamp<C>
Type Parameters:
C - generic type of date component
All Implemented Interfaces:
ChronoDisplay, VariantSource

public final class GeneralTimestamp<C> extends Object implements ChronoDisplay, VariantSource

Represents a general timestamp consisting of a general date and a 24-hour-clock time.

Note: This class is only relevant for non-gregorian use-cases. Most users will use PlainTimestamp instead.

Since:
3.8/4.5
Author:
Meno Hochschild
  • Method Details

    • of

      public static <C extends CalendarVariant<C>> GeneralTimestamp<C> of(C calendarVariant, PlainTime time)

      Creates a new timestamp consisting of a calendar variant and a time component.

      Type Parameters:
      C - generic type of date component
      Parameters:
      calendarVariant - date component
      time - time component
      Returns:
      general timestamp
      Since:
      3.8/4.5
    • of

      public static <C extends Calendrical<?,​ C>> GeneralTimestamp<C> of(C calendrical, PlainTime time)

      Creates a new timestamp consisting of a general date and a time component.

      Type Parameters:
      C - generic type of date component
      Parameters:
      calendrical - date component
      time - time component
      Returns:
      general timestamp
      Since:
      3.8/4.5
    • toDate

      public C toDate()

      Yields the date component.

      Returns:
      date component
      Since:
      3.8/4.5
    • toTime

      public PlainTime toTime()

      Yields the time component.

      Returns:
      time component
      Since:
      3.8/4.5
    • minus

      public GeneralTimestamp<C> minus(CalendarDays days)

      Subtracts given count of days from this general timestamp and return the result.

      Parameters:
      days - the duration in days to be subtracted
      Returns:
      result of subtraction as changed copy, this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      5.0
    • minus

      public GeneralTimestamp<C> minus(long amount, ClockUnit unit)

      Subtracts given count of days from this general timestamp and return the result.

      Warning: If users also wish to take into account time zones then a conversion of this general timestamp to a Moment must be done first before applying any time arithmetic.

      Parameters:
      amount - the amount of units to be subtracted
      unit - the clock unit to be applied
      Returns:
      result of subtraction as changed copy, this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      5.0
      See Also:
      at(ZonalOffset, StartOfDay), in(Timezone, StartOfDay), Moment.minus(long, TimeUnit)
    • plus

      public GeneralTimestamp<C> plus(CalendarDays days)

      Adds given count of days to this general timestamp and return the result.

      Parameters:
      days - the duration in days to be added
      Returns:
      result of addition as changed copy, this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      5.0
    • plus

      public GeneralTimestamp<C> plus(long amount, ClockUnit unit)

      Adds given count of clock units to this general timestamp and return the result.

      Warning: If users also wish to take into account time zones then a conversion of this general timestamp to a Moment must be done first before applying any time arithmetic.

      Parameters:
      amount - the amount of units to be added
      unit - the clock unit to be applied
      Returns:
      result of addition as changed copy, this instance remains unaffected
      Throws:
      ArithmeticException - in case of numerical overflow
      Since:
      5.0
      See Also:
      at(ZonalOffset, StartOfDay), in(Timezone, StartOfDay), Moment.plus(long, TimeUnit)
    • equals

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

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

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

      public Moment at(ZonalOffset offset, StartOfDay startOfDay)

      Combines this general timestamp with given timezone offset to a global UTC-moment.

      Parameters:
      offset - timezone offset
      startOfDay - start of day
      Returns:
      global UTC-moment based on this general timestamp interpreted in given timezone
      Since:
      3.8/4.5
    • in

      public Moment in(Timezone tz, StartOfDay startOfDay)

      Combines this general timestamp with given timezone to a global UTC-moment.

      Parameters:
      tz - timezone
      startOfDay - start of day
      Returns:
      global UTC-moment based on this general timestamp interpreted in given timezone
      Since:
      3.8/4.5
    • contains

      public boolean contains(ChronoElement<?> element)
      Description copied from interface: ChronoDisplay

      Queries if the value for given chronological element can be accessed via get(element).

      If the argument is missing then this method will yield false. Note: Elements which are not registered but define a suitable rule are also accessible.

      Specified by:
      contains in interface ChronoDisplay
      Parameters:
      element - chronological element to be asked (optional)
      Returns:
      true if the element is registered or there is an element rule for evaluating the value else false
      See Also:
      ChronoDisplay.get(ChronoElement)
    • get

      public <V> V get(ChronoElement<V> element)
      Description copied from interface: ChronoDisplay

      Returns the partial value associated with given chronological element.

      Specified by:
      get in interface ChronoDisplay
      Type Parameters:
      V - generic type of element value
      Parameters:
      element - element which has the value
      Returns:
      associated element value as object (never null)
      See Also:
      ChronoDisplay.contains(ChronoElement)
    • getInt

      public int getInt(ChronoElement<Integer> element)
      Description copied from interface: ChronoDisplay

      Returns the partial value associated with given chronological element.

      Specified by:
      getInt in interface ChronoDisplay
      Parameters:
      element - element which has the value
      Returns:
      associated element value as int primitive or Integer.MIN_VALUE if not available
      See Also:
      ChronoDisplay.get(ChronoElement)
    • getMinimum

      public <V> V getMinimum(ChronoElement<V> element)
      Description copied from interface: ChronoDisplay

      Yields the minimum value of given chronological element in the current context of this object.

      The definition of a minimum and a maximum does generally not imply that every intermediate value between minimum and maximum is valid in this context. For example in the timezone Europe/Berlin the hour [T02:00] will be invalid if switching to summer time.

      In most cases the minimum value is not dependent on this context.

      Specified by:
      getMinimum in interface ChronoDisplay
      Type Parameters:
      V - generic type of element value
      Parameters:
      element - element whose minimum value is to be evaluated
      Returns:
      minimum maybe context-dependent element value
      See Also:
      ChronoElement.getDefaultMinimum(), ChronoDisplay.getMaximum(ChronoElement)
    • getMaximum

      public <V> V getMaximum(ChronoElement<V> element)
      Description copied from interface: ChronoDisplay

      Yields the maximum value of given chronological element in the current context of this object.

      Maximum values are different from minimum case often dependent on the context. An example is the element SECOND_OF_MINUTE whose maximum is normally 59 but can differ in UTC-context with leap seconds. Another more common example is the maximum of the element DAY_OF_MONTH (28-31) which is dependent on the month and year of this context (leap years!).

      Note: In timezone-related timestamps possible offset jumps inducing gaps on the local timeline will be conserved. That means that minimum and maximum do not guarantee a continuum of valid intermediate values.

      Specified by:
      getMaximum in interface ChronoDisplay
      Type Parameters:
      V - generic type of element value
      Parameters:
      element - element whose maximum value is to be evaluated
      Returns:
      maximum maybe context-dependent element value
      See Also:
      ChronoElement.getDefaultMaximum(), ChronoDisplay.getMinimum(ChronoElement)
    • hasTimezone

      public boolean hasTimezone()
      Description copied from interface: ChronoDisplay

      Queries if this object contains a timezone for display purposes.

      Specified by:
      hasTimezone in interface ChronoDisplay
      Returns:
      true if a timezone is available and can be achieved with ChronoDisplay.getTimezone() else false
    • getTimezone

      public TZID getTimezone()
      Description copied from interface: ChronoDisplay

      Returns the associated timezone ID for display purposes if available.

      Note: Although global types like Moment indeed have a timezone reference (namely UTC+00:00), such types will not support formatted output without explicitly giving a timezone for display purposes. Therefore calling this method on global types will throw an exception. This method is not just about any timezone reference but a timezone designed for display purposes.

      Specified by:
      getTimezone in interface ChronoDisplay
      Returns:
      timezone identifier if available
      See Also:
      ChronoDisplay.hasTimezone()
    • getVariant

      public String getVariant()
      Description copied from interface: VariantSource

      Yields the variant name of a calendar system.

      Specified by:
      getVariant in interface VariantSource
      Returns:
      String which is empty if there are no variants