public class HawaiiTime
extends java.lang.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 java.time.ZoneId |
DEFAULT_ZONE
The default zone.
|
Constructor and Description |
---|
HawaiiTime()
Constructs a new
HawaiiTime with the default DEFAULT_ZONE . |
HawaiiTime(java.time.Clock clock)
Constructs a new
HawaiiTime with the supplied clock. |
HawaiiTime(java.time.ZoneId zone)
Constructs a new
HawaiiTime with the supplied zone. |
Modifier and Type | Method and Description |
---|---|
java.time.Clock |
getClock()
Returns the clock used by this
HawaiiTime . |
java.time.ZoneId |
getZone()
Returns the zone used by this
HawaiiTime . |
java.time.Instant |
instant()
Returns the current
Instant . |
java.time.LocalDate |
localDate()
Returns the current
LocalDate . |
java.time.LocalDateTime |
localDateTime()
Returns the current
LocalDateTime . |
java.time.LocalTime |
localTime()
Returns the current
LocalTime . |
long |
millis()
Returns the current
millis . |
java.time.MonthDay |
monthDay()
Returns the current
MonthDay . |
java.time.OffsetDateTime |
offsetDateTime()
Returns the current
OffsetDateTime . |
java.time.OffsetTime |
offsetTime()
Returns the current
OffsetTime . |
void |
setClock(java.time.Clock clock)
Sets the clock to be used by this
HawaiiTime . |
void |
setZone(java.time.ZoneId zone)
Sets the zone to be used by this
HawaiiTime . |
void |
useFixedClock(java.time.Clock clock)
Sets a fixed clock to be used.
|
protected void |
useFixedClock(java.time.Instant instant)
Sets a fixed clock to be used.
|
protected void |
useFixedClock(java.time.Instant instant,
java.time.ZoneId zone)
Sets a fixed clock to be used.
|
void |
useFixedClock(java.time.LocalDateTime dateTime)
Sets a fixed clock to be used.
|
void |
useFixedClock(long millis)
Sets a fixed clock to be used.
|
void |
useFixedClock(java.time.OffsetDateTime dateTime)
Sets a fixed clock to be used.
|
void |
useFixedClock(java.time.ZonedDateTime dateTime)
Sets a fixed clock to be used.
|
void |
useSystemClock()
Sets the system clock to be used.
|
java.time.Year |
year()
Returns the current
Year . |
java.time.YearMonth |
yearMonth()
Returns the current
YearMonth . |
java.time.ZonedDateTime |
zonedDateTime()
Returns the current
ZonedDateTime . |
public HawaiiTime()
HawaiiTime
with the default DEFAULT_ZONE
.public HawaiiTime(java.time.ZoneId zone)
HawaiiTime
with the supplied zone.zone
- the zone, not nullpublic HawaiiTime(java.time.Clock clock)
HawaiiTime
with the supplied clock. Also the ZoneId
is derived from the supplied clock.clock
- the clock, not nullpublic java.time.Clock getClock()
HawaiiTime
.public void setClock(java.time.Clock clock)
HawaiiTime
.clock
- the clock, not nullpublic java.time.ZoneId getZone()
HawaiiTime
.public void setZone(java.time.ZoneId zone)
HawaiiTime
.zone
- the zonepublic void useFixedClock(java.time.Clock clock)
clock
- the fixed clock, not nullpublic void useFixedClock(long millis)
millis
- the millis since epochpublic void useFixedClock(java.time.LocalDateTime dateTime)
dateTime
- the fixed date time, not nullpublic void useFixedClock(java.time.OffsetDateTime dateTime)
dateTime
- the fixed date time, not nullpublic void useFixedClock(java.time.ZonedDateTime dateTime)
dateTime
- the fixed date time, not nullprotected void useFixedClock(java.time.Instant instant)
instant
- the fixed instant, not nullprotected void useFixedClock(java.time.Instant instant, java.time.ZoneId zone)
instant
- the fixed instant, not nullzone
- the fixed zone, not nullpublic void useSystemClock()
public java.time.Instant instant()
Instant
.Instant
public java.time.LocalDate localDate()
LocalDate
.LocalDate
public java.time.LocalDateTime localDateTime()
LocalDateTime
.LocalDateTime
public java.time.LocalTime localTime()
LocalTime
.LocalTime
public long millis()
millis
.millis
public java.time.MonthDay monthDay()
MonthDay
.MonthDay
public java.time.OffsetDateTime offsetDateTime()
OffsetDateTime
.OffsetDateTime
public java.time.OffsetTime offsetTime()
OffsetTime
.OffsetTime
public java.time.Year year()
Year
.Year
public java.time.YearMonth yearMonth()
YearMonth
.YearMonth
public java.time.ZonedDateTime zonedDateTime()
ZonedDateTime
.ZonedDateTime