Class GeneralTimestamp<C>
- Type Parameters:
C
- generic type of date component
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionat(ZonalOffset offset, StartOfDay startOfDay)
Combines this general timestamp with given timezone offset to a global UTC-moment.boolean
contains(ChronoElement<?> element)
Queries if the value for given chronological element can be accessed viaget(element)
.boolean
<V> V
get(ChronoElement<V> element)
Returns the partial value associated with given chronological element.int
getInt(ChronoElement<Integer> element)
Returns the partial value associated with given chronological element.<V> V
getMaximum(ChronoElement<V> element)
Yields the maximum value of given chronological element in the current context of this object.<V> V
getMinimum(ChronoElement<V> element)
Yields the minimum value of given chronological element in the current context of this object.Returns the associated timezone ID for display purposes if available.Yields the variant name of a calendar system.int
hashCode()
boolean
Queries if this object contains a timezone for display purposes.in(Timezone tz, StartOfDay startOfDay)
Combines this general timestamp with given timezone to a global UTC-moment.Subtracts given count of days from this general timestamp and return the result.minus(CalendarDays days)
Subtracts given count of days from this general timestamp and return the result.static <C extends CalendarVariant<C>>
GeneralTimestamp<C>Creates a new timestamp consisting of a calendar variant and a time component.Adds given count of clock units to this general timestamp and return the result.plus(CalendarDays days)
Adds given count of days to this general timestamp and return the result.toDate()
Yields the date component.toString()
toTime()
Yields the time component.
-
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 componenttime
- time component- Returns:
- general timestamp
- Since:
- 3.8/4.5
-
of
Creates a new timestamp consisting of a general date and a time component.
- Type Parameters:
C
- generic type of date component- Parameters:
calendrical
- date componenttime
- time component- Returns:
- general timestamp
- Since:
- 3.8/4.5
-
toDate
Yields the date component.
- Returns:
- date component
- Since:
- 3.8/4.5
-
toTime
Yields the time component.
- Returns:
- time component
- Since:
- 3.8/4.5
-
minus
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
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 subtractedunit
- 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
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
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 addedunit
- 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
-
hashCode
public int hashCode() -
toString
-
at
Combines this general timestamp with given timezone offset to a global UTC-moment.
- Parameters:
offset
- timezone offsetstartOfDay
- start of day- Returns:
- global UTC-moment based on this general timestamp interpreted in given timezone
- Since:
- 3.8/4.5
-
in
Combines this general timestamp with given timezone to a global UTC-moment.
- Parameters:
tz
- timezonestartOfDay
- start of day- Returns:
- global UTC-moment based on this general timestamp interpreted in given timezone
- Since:
- 3.8/4.5
-
contains
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 interfaceChronoDisplay
- 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 elsefalse
- See Also:
ChronoDisplay.get(ChronoElement)
-
get
Description copied from interface:ChronoDisplay
Returns the partial value associated with given chronological element.
- Specified by:
get
in interfaceChronoDisplay
- 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
Description copied from interface:ChronoDisplay
Returns the partial value associated with given chronological element.
- Specified by:
getInt
in interfaceChronoDisplay
- 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
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 interfaceChronoDisplay
- 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
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 interfaceChronoDisplay
- 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 interfaceChronoDisplay
- Returns:
true
if a timezone is available and can be achieved withChronoDisplay.getTimezone()
elsefalse
-
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 interfaceChronoDisplay
- Returns:
- timezone identifier if available
- See Also:
ChronoDisplay.hasTimezone()
-
getVariant
Description copied from interface:VariantSource
Yields the variant name of a calendar system.
- Specified by:
getVariant
in interfaceVariantSource
- Returns:
- String which is empty if there are no variants
-