@MinDoc(copyright="Copyright 2016 A. Weinert", author="Albrecht Weinert", version="V.33", lastModified="27.03.2021", purpose="a common type for Clocks") public interface AClock
java.time.Clock
for real time applications —
usually by extending and/or wrapping it. An AClock provides readings of
the time in different forms, as long, Instant
,
ZonedDateTime
and else. All readings are
consistent with the last explicit update()
or setting,
should SClock
be implemented,too.update()
as doing
nothing and may omit the wrapped java.time.Clock
.
getZone()
, instant()
and millis()
are
implemented in the class java.time.Clock
, which
the package java.time
provides no suitable interface
for. update()
, getActTime()
and getActTime(ZoneId)
provide extra readings and a synchronised consistent update of all
readings.ComVar
Modifier and Type | Field and Description |
---|---|
static ZoneId |
CET_ZONE
Time zone for common use.
|
static ZoneId |
DEF_ZONE
Time zone for common use.
|
static ZoneId |
EET_ZONE
Time zone for common use.
|
static ZoneId |
GMT_ZONE
Time zone for common use.
|
static ZoneId |
sysZone
The JVM's system time zone.
|
static ZoneRules |
sysZoneRules
The JVM's system time zone rules.
|
static ZoneId |
UTC_ZONE
Time zone for common use.
|
static ZoneId |
WET_ZONE
Time zone for common use.
|
Modifier and Type | Method and Description |
---|---|
AClock |
fix()
Provide another AClock with a fixed time according to current state.
|
default String |
format(CharSequence form)
Format the actual time freely (PHP format string).
|
default String |
formatDIN()
Format the actual time according to DIN.
|
default ZonedDateTime |
getActTime()
The current zone related time of this AClock.
|
default ZonedDateTime |
getActTime(ZoneId zone)
The current time of this AClock related to a given zone.
|
default int |
getDayOfMonth()
The day in the month.
|
default int |
getHour()
The hour of the day.
|
default int |
getMilli()
The milliseconds in the second.
|
default int |
getMinute()
The minute in the hour.
|
default Month |
getMonth()
The month of the year.
|
default int |
getMonthOfYear()
The month of the year.
|
default int |
getNano()
The nanoseconds in the second.
|
default int |
getSecond()
The second in the minute.
|
default int |
getYear()
The year.
|
ZoneId |
getZone()
The clock's time-zone.
|
Instant |
instant()
The current instant of this AClock.
|
default long |
millis()
The current time of this Clock.
|
default ZonedDateTime |
of(int hour,
int minute,
int second,
int nanoOfSecond) |
default ZonedDateTime |
setActTime()
Update and get current zone related time of this AClock.
|
default long |
setActTimeMs()
The updated ms of this AClock.
|
default Instant |
setInstant()
The updated instant of this AClock.
|
String |
toString()
The state as String.
|
boolean |
update()
Update this AClock to its current time.
|
AClock |
withZone(ZoneId zone)
Provide another AClock with a different time-zone.
|
static final ZoneId sysZone
rules
are available in sysZoneRules
.DEF_ZONE
.static final ZoneRules sysZoneRules
static final ZoneId GMT_ZONE
static final ZoneId WET_ZONE
static final ZoneId CET_ZONE
static final ZoneId EET_ZONE
static final ZoneId UTC_ZONE
static final ZoneId DEF_ZONE
ZoneId getZone()
ZonedDateTime
.
It must never be null.AClock withZone(ZoneId zone)
zone
- the time zone for the new SysClock, null defaults to the
actual
zone.AClock fix()
Instant instant()
default Instant setInstant()
update(); return instant()
default long millis()
return instant().toEpochMilli()
default long setActTimeMs()
update(); return instant()
update()
; return millis()
. default ZonedDateTime getActTime()
return ZonedDateTime.ofInstant(instant(), getZone())
zone
default ZonedDateTime setActTime()
update(); return getActTime();
zone
default ZonedDateTime getActTime(ZoneId zone)
zone
- the zone to relate to;
null will be this Clock's zone
boolean update()
update()
will never have and effect (and shall be implemented
just returning true). update()
is called directly or indirectly by
setActTimeMs()
, setInstant()
or setActTime()
.
update
. Substantial
is meant relative to this clock's resolution; that may usually be ms but
will depend on application and platform. If in doubt or if the calculation
is intolerably expensive return true.String toString()
default String format(CharSequence form)
return TimeHelper
.format(form, getActTime()
)
default String formatDIN()
return TimeHelper
.formatDIN(getActTime()
)
TimeHelper.formatDIN(ZonedDateTime)
default ZonedDateTime of(int hour, int minute, int second, int nanoOfSecond)
default int getYear()
default int getMonthOfYear()
year
, 1..12; getMonth()
.getValue()
default int getDayOfMonth()
month
, 1..31default int getHour()
day
, 0..23default int getMinute()
hour
, 0..59default int getSecond()
minute
, 0..59 (60, 61)default int getNano()
second
, 0..999999999default int getMilli()
getNano() /
1000000