@CalendarType(value="iso8601") public final class PlainTime extends TimePoint<IsoTimeUnit,PlainTime> implements WallTime, Temporal<PlainTime>, LocalizedPatternSupport
Represents a plain wall time without any timezone or date component as defined in ISO-8601 up to nanosecond precision.
This type also supports the special value 24:00 in its state space. That value means midnight at the end of day and can be both set and queried.
Following elements which are declared as constants are registered by this class:
PlainTime.COMPONENT
PlainTime.AM_PM_OF_DAY
PlainTime.CLOCK_HOUR_OF_AMPM
PlainTime.CLOCK_HOUR_OF_DAY
PlainTime.DIGITAL_HOUR_OF_AMPM
PlainTime.DIGITAL_HOUR_OF_DAY
PlainTime.ISO_HOUR
PlainTime.MINUTE_OF_HOUR
PlainTime.MINUTE_OF_DAY
PlainTime.SECOND_OF_MINUTE
PlainTime.SECOND_OF_DAY
PlainTime.MILLI_OF_SECOND
PlainTime.MICRO_OF_SECOND
PlainTime.NANO_OF_SECOND
PlainTime.MILLI_OF_DAY
PlainTime.MICRO_OF_DAY
PlainTime.NANO_OF_DAY
PlainTime.PRECISION
PlainTime.DECIMAL_HOUR
PlainTime.DECIMAL_MINUTE
PlainTime.DECIMAL_SECOND
Modifier and Type | Field and Description |
---|---|
static ZonalElement<Meridiem> |
AM_PM_OF_DAY
Element with the half day section relative to noon (ante meridiem
or post meridiem).
|
static AdjustableElement<Integer,PlainTime> |
CLOCK_HOUR_OF_AMPM
Element with the hour of half day in the value range
1-12
(dial on an analogue watch). |
static AdjustableElement<Integer,PlainTime> |
CLOCK_HOUR_OF_DAY
Element with the hour in the value range
1-24 (analogue
display). |
static WallTimeElement |
COMPONENT
Element with the wall time in the value range
[T00:00:00,000000000] until [T24:00:00,000000000]
(inclusive in the context of PlainTime else exclusive). |
static ZonalElement<BigDecimal> |
DECIMAL_HOUR
Decimal hour in the value range
0.0 inclusive until
24.0 exclusive (inclusive in PlainTime ). |
static ZonalElement<BigDecimal> |
DECIMAL_MINUTE
Decimal minute in the value range
0.0 inclusive until
60.0 exclusive. |
static ZonalElement<BigDecimal> |
DECIMAL_SECOND
Decimal second in the value range
0.0 inclusive until
60.0 exclusive. |
static ProportionalElement<Integer,PlainTime> |
DIGITAL_HOUR_OF_AMPM
Element with the digital hour of half day in the value range
0-11 . |
static ProportionalElement<Integer,PlainTime> |
DIGITAL_HOUR_OF_DAY
Element with the digital hour in the value range
0-23 . |
static ProportionalElement<Integer,PlainTime> |
ISO_HOUR
Element with the ISO-8601-hour of day in the value range
0-24 . |
static ProportionalElement<Long,PlainTime> |
MICRO_OF_DAY
Element with the day time in microseconds in the value range
0-86400000000 . |
static ProportionalElement<Integer,PlainTime> |
MICRO_OF_SECOND
Element with the microsecond in the value range
0-999999 . |
static ProportionalElement<Integer,PlainTime> |
MILLI_OF_DAY
Element with the day time in milliseconds in the value range
0-86400000 . |
static ProportionalElement<Integer,PlainTime> |
MILLI_OF_SECOND
Element with the millisecond in the value range
0-999 . |
static ProportionalElement<Integer,PlainTime> |
MINUTE_OF_DAY
Element with the minute of day in the value range
0-1440 . |
static ProportionalElement<Integer,PlainTime> |
MINUTE_OF_HOUR
Element with the minute of hour in the value range
0-59 . |
static ProportionalElement<Long,PlainTime> |
NANO_OF_DAY
Element with the day time in nanoseconds in the value range
0-86400000000000 . |
static ProportionalElement<Integer,PlainTime> |
NANO_OF_SECOND
Element with the nanosecond in the value range
0-999999999 . |
static ChronoElement<ClockUnit> |
PRECISION
Defines the precision as the smallest non-zero time element and
truncates time parts of higher precision if necessary.
|
static ProportionalElement<Integer,PlainTime> |
SECOND_OF_DAY
Element with the second of day in the value range
0-86400 . |
static ProportionalElement<Integer,PlainTime> |
SECOND_OF_MINUTE
Element with the second of minute in the value range
0-59 . |
Modifier and Type | Method and Description |
---|---|
static TimeAxis<IsoTimeUnit,PlainTime> |
axis()
Provides a static access to the associated time axis respective
chronology which contains the chronological rules.
|
int |
compareTo(PlainTime time)
Defines a natural order which is solely based on the timeline
order.
|
boolean |
equals(Object obj)
Compares the full state, that is hour, minute, second and nanosecond
of this instance and given argument.
|
static TemporalFormatter<PlainTime> |
formatter(DisplayMode mode,
Locale locale)
Creates a new formatter which uses the given display mode and locale
for formatting and parsing plain times.
|
static <P extends ChronoPattern<P>> |
formatter(String formatPattern,
P patternType,
Locale locale)
Creates a new formatter which uses the given pattern and locale
for formatting and parsing plain times.
|
static PlainTime |
from(WallTime time)
Common conversion method.
|
int |
getHour()
Yields the hour of day.
|
int |
getMinute()
Liefert die Minute (der aktuellen Stunde).
|
int |
getNanosecond()
Yields the nanosecond.
|
int |
getSecond()
Yields the second of minute.
|
int |
hashCode()
Subclasses must redefine this method corresponding to the
behaviour of
equals() . |
boolean |
isAfter(PlainTime time)
Queries if this object is after given object on a timeline.
|
boolean |
isBefore(PlainTime time)
Queries if this object is before given object on a timeline.
|
boolean |
isMidnight()
Is this instance at midnight, either at start or at end of day?
|
boolean |
isSimultaneous(PlainTime time)
Queries if this object and given object have the same position
on the time axis.
|
static TemporalFormatter<PlainTime> |
localFormatter(DisplayMode mode)
Creates a new formatter which uses the given display mode in the
default locale for formatting and parsing plain times.
|
static <P extends ChronoPattern<P>> |
localFormatter(String formatPattern,
P patternType)
Creates a new formatter which uses the given pattern in the
default locale for formatting and parsing plain times.
|
static PlainTime |
midnightAtEndOfDay()
Yields midnight at the end of the day, that is midnight at
the start of the following day.
|
static PlainTime |
midnightAtStartOfDay()
Yields midnight at the start of the day.
|
static PlainTime |
of(BigDecimal decimal)
Creates a wall time by given decimal hour.
|
static PlainTime |
of(int hour)
Creates a wall time as full hour.
|
static PlainTime |
of(int hour,
int minute)
Creates a wall time with hour and minute.
|
static PlainTime |
of(int hour,
int minute,
int second)
Creates a wall time with hour, minute and second.
|
static PlainTime |
of(int hour,
int minute,
int second,
int nanosecond)
Creates a wall time with hour, minute, second and nanosecond.
|
DayCycles |
roll(long amount,
ClockUnit unit)
Rolls this time by the given duration (as amount and unit) and
also counts possible day overflow.
|
String |
toString()
Dependent on the precision of this instance, this method yields a
canonical representation in one of following formats (CLDR-syntax):
'T'HH
'T'HH:mm
'T'HH:mm:ss
'T'HH:mm:ss,SSS
'T'HH:mm:ss,SSSSSS
'T'HH:mm:ss,SSSSSSSSS
The fraction part will be preceded by a comma as recommended by ISO
unless the system property "net.time4j.format.iso.decimal.dot"
was set to "true".
|
max, min, minus, minus, plus, plus, until, until
contains, get, get, getMaximum, getMinimum, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
public static final WallTimeElement COMPONENT
Element with the wall time in the value range
[T00:00:00,000000000]
until [T24:00:00,000000000]
(inclusive in the context of PlainTime
else exclusive).
Example of usage:
PlainTimestamp tsp = PlainTimestamp.localFormatter("uuuu-MM-dd", PatternType.CLDR) .withDefault( PlainTime.COMPONENT, PlainTime.midnightAtStartOfDay()) .parse("2014-08-20"); System.out.println(tsp); // output: 2014-08-20T00
Note: This element does not define any base unit.
@FormattableElement(format="a") public static final ZonalElement<Meridiem> AM_PM_OF_DAY
Element with the half day section relative to noon (ante meridiem or post meridiem).
This element handles the value 24:00 in the same way as 00:00, hence does not make any difference between start and end of day. In detail the mapping from hours to meridiem values looks like following:
AM_PM_OF_DAY | AM | AM | ... | AM | PM | PM | ... | PM | AM |
ISO-8601-Wert | T0 | T1 | ... | T11 | T12 | T13 | ... | T23 | T24 |
Example:
import static net.time4j.PlainTime.AM_PM_OF_DAY; PlainTime time = PlainTime.of(12, 45, 20); System.out.println(time.get(AM_PM_OF_DAY)); // Output: PM
This element does not define a base unit.
@FormattableElement(format="h") public static final AdjustableElement<Integer,PlainTime> CLOCK_HOUR_OF_AMPM
Element with the hour of half day in the value range 1-12
(dial on an analogue watch).
This element handles the value 24:00 in the same way as 00:00, hence
does not make any difference between start and end of day. This is a
limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full
hour range users can use the element PlainTime.ISO_HOUR
. In detail
the mapping to ISO-hours looks like following:
CLOCK_HOUR_OF_AMPM | 12 | 1 | ... | 11 | 12 | 1 | ... | 11 | 12 |
ISO-8601-Wert | T0 | T1 | ... | T11 | T12 | T13 | ... | T23 | T24 |
@FormattableElement(format="k") public static final AdjustableElement<Integer,PlainTime> CLOCK_HOUR_OF_DAY
Element with the hour in the value range 1-24
(analogue
display).
This element handles the value 24:00 in the same way as 00:00, hence
does not make any difference between start and end of day. This is a
limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full
hour range users can use the element PlainTime.ISO_HOUR
. In detail
the mapping to ISO-hours looks like following:
CLOCK_HOUR_OF_DAY | 24 | 1 | ... | 11 | 12 | 13 | ... | 23 | 24 |
ISO-8601-Wert | T0 | T1 | ... | T11 | T12 | T13 | ... | T23 | T24 |
@FormattableElement(format="K") public static final ProportionalElement<Integer,PlainTime> DIGITAL_HOUR_OF_AMPM
Element with the digital hour of half day in the value range
0-11
.
This element handles the value 24:00 in the same way as 00:00, hence
does not make any difference between start and end of day. This is a
limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full
hour range users can use the element PlainTime.ISO_HOUR
. In detail
the mapping to ISO-hours looks like following:
DIGITAL_HOUR_OF_AMPM | 0 | 1 | ... | 11 | 0 | 1 | ... | 11 | 0 |
ISO-8601-Wert | T0 | T1 | ... | T11 | T12 | T13 | ... | T23 | T24 |
@FormattableElement(format="H") public static final ProportionalElement<Integer,PlainTime> DIGITAL_HOUR_OF_DAY
Element with the digital hour in the value range 0-23
.
This element handles the value 24:00 in the same way as 00:00, hence
does not make any difference between start and end of day. This is a
limitation which preserves the compatibility with CLDR and the class
java.text.SimpleDateFormat
. In order to support the full
hour range users can use the element PlainTime.ISO_HOUR
. In detail
the mapping to ISO-hours looks like following:
DIGITAL_HOUR_OF_DAY | 0 | 1 | ... | 11 | 12 | 13 | ... | 23 | 0 |
ISO-8601-Wert | T0 | T1 | ... | T11 | T12 | T13 | ... | T23 | T24 |
public static final ProportionalElement<Integer,PlainTime> ISO_HOUR
Element with the ISO-8601-hour of day in the value range
0-24
.
Given a context of PlainTime
with full hours, the maximum
is 24
and stands for the time 24:00 (midnight at end of day),
else the maximum is 23
in every different context.
PlainTime.getHour()
@FormattableElement(format="m") public static final ProportionalElement<Integer,PlainTime> MINUTE_OF_HOUR
Element with the minute of hour in the value range 0-59
.
PlainTime.getMinute()
public static final ProportionalElement<Integer,PlainTime> MINUTE_OF_DAY
Element with the minute of day in the value range 0-1440
.
Given a context of PlainTime
with full minutes, the maximum
is 1440
and stands for the time 24:00 (midnight at end of day),
else the maximum is 1439
in every different context.
@FormattableElement(format="s") public static final ProportionalElement<Integer,PlainTime> SECOND_OF_MINUTE
Element with the second of minute in the value range
0-59
.
This element does not know any leapseconds in a local context and
refers to a normal analogue clock. If this element is used in
UTC-context (Moment
) however then the value range is
0-58/59/60
instead.
PlainTime.getSecond()
public static final ProportionalElement<Integer,PlainTime> SECOND_OF_DAY
Element with the second of day in the value range
0-86400
.
Given a context of PlainTime
with full seconds, the maximum
is 86400
and stands for the time 24:00 (midnight at end of day),
else the maximum is 86399
in every different context. Leapseconds
are never counted.
public static final ProportionalElement<Integer,PlainTime> MILLI_OF_SECOND
Element with the millisecond in the value range 0-999
.
public static final ProportionalElement<Integer,PlainTime> MICRO_OF_SECOND
Element with the microsecond in the value range 0-999999
.
@FormattableElement(format="S") public static final ProportionalElement<Integer,PlainTime> NANO_OF_SECOND
Element with the nanosecond in the value range
0-999999999
.
@FormattableElement(format="A") public static final ProportionalElement<Integer,PlainTime> MILLI_OF_DAY
Element with the day time in milliseconds in the value range
0-86400000
.
Given a context of PlainTime
with full milliseconds, the
maximum is 86400000
and stands for the time 24:00 (midnight at
end of day), else the maximum is 86399999
in every different
context. Leapseconds are never counted.
public static final ProportionalElement<Long,PlainTime> MICRO_OF_DAY
Element with the day time in microseconds in the value range
0-86400000000
.
Given a context of PlainTime
with full microseconds, the
maximum is 86400000000
and stands for the time 24:00 (midnight
at end of day), else the maximum is 86399999999
in every
different context. Leapseconds are never counted.
public static final ProportionalElement<Long,PlainTime> NANO_OF_DAY
Element with the day time in nanoseconds in the value range
0-86400000000000
.
Given any context of PlainTime
, the maximum is always
86400000000000
and stands for the time 24:00 (midnight
at end of day), else the maximum is 86399999999999
in every
different context. Leapseconds are never counted.
Example:
import static net.time4j.ClockUnit.HOURS; import static net.time4j.PlainTime.NANO_OF_DAY; PlainTime time = PlainTime.midnightAtStartOfDay().plus(6, HOURS); // T06:00 System.out.println( time.get(NANO_OF_DAY.ratio()) .multiply(BigDecimal.ofHour(100)).stripTrailingZeros() + "% of day are over."); // Output: 25% of day are over.
public static final ZonalElement<BigDecimal> DECIMAL_HOUR
Decimal hour in the value range 0.0
inclusive until
24.0
exclusive (inclusive in PlainTime
).
This element does not define any base unit.
public static final ZonalElement<BigDecimal> DECIMAL_MINUTE
Decimal minute in the value range 0.0
inclusive until
60.0
exclusive.
This element does not define any base unit.
public static final ZonalElement<BigDecimal> DECIMAL_SECOND
Decimal second in the value range 0.0
inclusive until
60.0
exclusive.
This element does not define any base unit.
public static final ChronoElement<ClockUnit> PRECISION
Defines the precision as the smallest non-zero time element and truncates time parts of higher precision if necessary.
Setting higher precisions than available is without any effect. But setting lower precisions can truncate data however. Examples:
// reading of precision ------------------------------------- PlainTime time = PlainTime.of(12, 26, 52, 987654000); System.out.println(time.get(PRECISION)); // Output: MICROS // setting of precision ------------------------------------- PlainTime time = PlainTime.of(12, 26, 52, 987654000); System.out.println(time.with(PRECISION, ClockUnit.MILLIS)); // Output: T12:26:52,987
This element does not define any base unit.
public int getHour()
WallTime
Yields the hour of day.
public int getMinute()
WallTime
Liefert die Minute (der aktuellen Stunde).
public int getSecond()
WallTime
Yields the second of minute.
Given this context and the fact that this interface describes
an analogue clock without UTC reference, the special leapsecond
value 60
cannot be supported.
public int getNanosecond()
WallTime
Yields the nanosecond.
Implementations which are not capable of nanosecond precision
will just yield 0
or another suitable rounded value.
getNanosecond
in interface WallTime
0 - 999,999,999
public static PlainTime midnightAtStartOfDay()
Yields midnight at the start of the day.
PlainTime.midnightAtEndOfDay()
public static PlainTime midnightAtEndOfDay()
Yields midnight at the end of the day, that is midnight at the start of the following day.
PlainTime.midnightAtStartOfDay()
public static PlainTime of(int hour)
Creates a wall time as full hour.
hour
- iso-hour of day in the range 0-24
IllegalArgumentException
- if given hour is out of rangepublic static PlainTime of(int hour, int minute)
Creates a wall time with hour and minute.
hour
- hour of day in the range 0-23
or
24
if the given minute equals to 0
minute
- minute in the range 0-59
IllegalArgumentException
- if any argument is out of rangepublic static PlainTime of(int hour, int minute, int second)
Creates a wall time with hour, minute and second.
hour
- hour in the range 0-23
or 24
if the other arguments are equal to 0
minute
- minute in the range 0-59
second
- second in the range 0-59
IllegalArgumentException
- if any argument is out of rangepublic static PlainTime of(int hour, int minute, int second, int nanosecond)
Creates a wall time with hour, minute, second and nanosecond.
hour
- hour in the range 0-23
or 24
if the other argumenta equal to 0
minute
- minute in the range 0-59
second
- second in the range 0-59
nanosecond
- nanosecond in the range 0-999,999,999
IllegalArgumentException
- if any argument is out of rangePlainTime.of(int)
,
PlainTime.of(int, int)
,
PlainTime.of(int, int, int)
,
PlainTime.NANO_OF_SECOND
public static PlainTime of(BigDecimal decimal)
Creates a wall time by given decimal hour.
decimal
- decimal hour of day in the range [0.0-24.0]
IllegalArgumentException
- if the argument is out of rangePlainTime.DECIMAL_HOUR
public static PlainTime from(WallTime time)
Common conversion method.
time
- ISO-timepublic DayCycles roll(long amount, ClockUnit unit)
Rolls this time by the given duration (as amount and unit) and also counts possible day overflow.
amount
- amount to be added (maybe negative)unit
- time unitplus(long, IsoTimeUnit)
public static <P extends ChronoPattern<P>> TemporalFormatter<PlainTime> localFormatter(String formatPattern, P patternType)
Creates a new formatter which uses the given pattern in the default locale for formatting and parsing plain times.
P
- generic pattern typeformatPattern
- format definition as patternpatternType
- pattern dialectPlainTime
-objects
using system localeIllegalArgumentException
- if resolving of pattern failspublic static TemporalFormatter<PlainTime> localFormatter(DisplayMode mode)
Creates a new formatter which uses the given display mode in the default locale for formatting and parsing plain times.
mode
- formatting stylePlainTime
-objects
using system localeIllegalStateException
- if format pattern cannot be retrievedpublic static <P extends ChronoPattern<P>> TemporalFormatter<PlainTime> formatter(String formatPattern, P patternType, Locale locale)
Creates a new formatter which uses the given pattern and locale for formatting and parsing plain times.
P
- generic pattern typeformatPattern
- format definition as patternpatternType
- pattern dialectlocale
- locale settingPlainTime
-objects
using given localeIllegalArgumentException
- if resolving of pattern failsPlainTime.localFormatter(String, ChronoPattern)
public static TemporalFormatter<PlainTime> formatter(DisplayMode mode, Locale locale)
Creates a new formatter which uses the given display mode and locale for formatting and parsing plain times.
mode
- formatting stylelocale
- locale settingPlainTime
-objects
using given localeIllegalStateException
- if format pattern cannot be retrievedPlainTime.localFormatter(DisplayMode)
public boolean equals(Object obj)
Compares the full state, that is hour, minute, second and nanosecond of this instance and given argument.
equals
in class TimePoint<IsoTimeUnit,PlainTime>
TimePoint.compareTo(TimePoint)
public int hashCode()
TimePoint
Subclasses must redefine this method corresponding to the
behaviour of equals()
.
hashCode
in class TimePoint<IsoTimeUnit,PlainTime>
public boolean isBefore(PlainTime time)
Temporal
Queries if this object is before given object on a timeline.
public boolean isAfter(PlainTime time)
Temporal
Queries if this object is after given object on a timeline.
public boolean isSimultaneous(PlainTime time)
Temporal
Queries if this object and given object have the same position on the time axis.
Is equivalent to !isAfter(temporal) && !isBefore(temporal)
.
This method differs from the Object
-method equals()
such that first the comparison type must be a temporal one and second
that only temporal-only state will be considered.
isSimultaneous
in interface Temporal<PlainTime>
time
- object this instance is compared totrue
if this instance is temporally equal
to temporal
else false
public boolean isMidnight()
Is this instance at midnight, either at start or at end of day?
public int compareTo(PlainTime time)
Defines a natural order which is solely based on the timeline order.
The natural order is consistent with equals()
.
compareTo
in interface Comparable<PlainTime>
compareTo
in class TimePoint<IsoTimeUnit,PlainTime>
PlainTime.isBefore(PlainTime)
,
PlainTime.isAfter(PlainTime)
public String toString()
Dependent on the precision of this instance, this method yields a canonical representation in one of following formats (CLDR-syntax):
The fraction part will be preceded by a comma as recommended by ISO unless the system property "net.time4j.format.iso.decimal.dot" was set to "true".
public static TimeAxis<IsoTimeUnit,PlainTime> axis()
Provides a static access to the associated time axis respective chronology which contains the chronological rules.
null
)Copyright © 2014–2015. All rights reserved.