public class HawaiiTime extends Object
Clock reference to instantiate new java.time date and time objects.
It provides convenient methods to use a fixed date time which is particular useful for unit testing but also to change the date time in a running application to test how it behaves on a given date or time.
Be aware that third-party libraries being used by the application do obviously not use HawaiiTime and probably instantiate date and time objects based on the System time.
| Modifier and Type | Field and Description |
|---|---|
protected static ZoneId |
DEFAULT_ZONE
The default zone.
|
| Constructor and Description |
|---|
HawaiiTime()
Constructs a new
HawaiiTime with the default DEFAULT_ZONE. |
HawaiiTime(Clock clock)
Constructs a new
HawaiiTime with the supplied clock. |
HawaiiTime(ZoneId zone)
Constructs a new
HawaiiTime with the supplied zone. |
| Modifier and Type | Method and Description |
|---|---|
Clock |
getClock()
Returns the clock used by this
HawaiiTime. |
ZoneId |
getZone()
Returns the zone used by this
HawaiiTime. |
Instant |
instant()
Returns the current
Instant. |
LocalDate |
localDate()
Returns the current
LocalDate. |
LocalDateTime |
localDateTime()
Returns the current
LocalDateTime. |
LocalTime |
localTime()
Returns the current
LocalTime. |
long |
millis()
Returns the current
millis. |
MonthDay |
monthDay()
Returns the current
MonthDay. |
OffsetDateTime |
offsetDateTime()
Returns the current
OffsetDateTime. |
OffsetTime |
offsetTime()
Returns the current
OffsetTime. |
void |
setClock(Clock clock)
Sets the clock to be used by this
HawaiiTime. |
void |
setZone(ZoneId zone)
Sets the zone to be used by this
HawaiiTime. |
void |
useFixedClock(Clock clock)
Sets a fixed clock to be used.
|
protected void |
useFixedClock(Instant instant)
Sets a fixed clock to be used.
|
protected void |
useFixedClock(Instant instant,
ZoneId zone)
Sets a fixed clock to be used.
|
void |
useFixedClock(LocalDateTime dateTime)
Sets a fixed clock to be used.
|
void |
useFixedClock(long millis)
Sets a fixed clock to be used.
|
void |
useFixedClock(OffsetDateTime dateTime)
Sets a fixed clock to be used.
|
void |
useFixedClock(ZonedDateTime dateTime)
Sets a fixed clock to be used.
|
void |
useSystemClock()
Sets the system clock to be used.
|
Year |
year()
Returns the current
Year. |
YearMonth |
yearMonth()
Returns the current
YearMonth. |
ZonedDateTime |
zonedDateTime()
Returns the current
ZonedDateTime. |
protected static final ZoneId DEFAULT_ZONE
public HawaiiTime()
HawaiiTime with the default DEFAULT_ZONE.public HawaiiTime(ZoneId zone)
HawaiiTime with the supplied zone.zone - the zone, not nullpublic HawaiiTime(Clock clock)
HawaiiTime with the supplied clock. Also the ZoneId is
derived from the supplied clock.clock - the clock, not nullpublic Clock getClock()
HawaiiTime.public void setClock(Clock clock)
HawaiiTime.clock - the clock, not nullpublic ZoneId getZone()
HawaiiTime.public void setZone(ZoneId zone)
HawaiiTime.zone - the zonepublic void useFixedClock(Clock clock)
clock - the fixed clock, not nullpublic void useFixedClock(long millis)
millis - the millis since epochpublic void useFixedClock(LocalDateTime dateTime)
dateTime - the fixed date time, not nullpublic void useFixedClock(OffsetDateTime dateTime)
dateTime - the fixed date time, not nullpublic void useFixedClock(ZonedDateTime dateTime)
dateTime - the fixed date time, not nullprotected void useFixedClock(Instant instant)
instant - the fixed instant, not nullprotected void useFixedClock(Instant instant, ZoneId zone)
instant - the fixed instant, not nullzone - the fixed zone, not nullpublic void useSystemClock()
public Instant instant()
Instant.Instantpublic LocalDate localDate()
LocalDate.LocalDatepublic LocalDateTime localDateTime()
LocalDateTime.LocalDateTimepublic LocalTime localTime()
LocalTime.LocalTimepublic long millis()
millis.millispublic MonthDay monthDay()
MonthDay.MonthDaypublic OffsetDateTime offsetDateTime()
OffsetDateTime.OffsetDateTimepublic OffsetTime offsetTime()
OffsetTime.OffsetTimepublic Year year()
Year.Yearpublic YearMonth yearMonth()
YearMonth.YearMonthpublic ZonedDateTime zonedDateTime()
ZonedDateTime.ZonedDateTime