= VirtualClock
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Works in connection with xref:refguide:applib:index/services/iactnlayer/InteractionService.adoc[InteractionService] , such that it allows an xref:refguide:applib:index/services/iactn/Interaction.adoc[Interaction] to run with its own simulated (or actual) time.

== API

[source,java]
.VirtualClock.java
----
interface VirtualClock {
  Instant nowAsInstant()     // <.>
  VirtualClock system()     // <.>
  VirtualClock nowAt(Instant virtualNow)     // <.>
  VirtualClock nowAt(java.time.@NonNull LocalDate virtualNow)     // <.>
  VirtualClock nowAt(java.time.@NonNull LocalDateTime virtualNow)
  VirtualClock nowAt(java.time.@NonNull OffsetDateTime virtualNow)
  VirtualClock nowAt(java.time.@NonNull ZonedDateTime virtualNow)
  VirtualClock nowAt(java.util.@NonNull Date virtualNow)
  VirtualClock nowAt(org.joda.time.@NonNull LocalDate virtualNow)     // <.>
  VirtualClock nowAt(org.joda.time.@NonNull LocalDateTime virtualNow)     // <.>
  VirtualClock nowAt(org.joda.time.@NonNull DateTime virtualNow)     // <.>
  VirtualClock frozenAt(Instant frozenAt)     // <.>
  VirtualClock frozenAt(java.time.@NonNull LocalDate frozenAt)
  VirtualClock frozenAt(java.time.@NonNull LocalDateTime frozenAt)
  VirtualClock frozenAt(java.time.@NonNull OffsetDateTime frozenAt)
  VirtualClock frozenAt(java.time.@NonNull ZonedDateTime frozenAt)
  VirtualClock frozenAt(java.util.@NonNull Date frozenAt)
  VirtualClock frozenAt(org.joda.time.@NonNull LocalDate frozenAt)     // <.>
  VirtualClock frozenAt(org.joda.time.@NonNull LocalDateTime frozenAt)     // <.>
  VirtualClock frozenAt(org.joda.time.@NonNull DateTime frozenAt)     // <.>
  VirtualClock frozenTestClock()     // <.>
  ZoneId localTimeZone()     // <.>
  long nowAsEpochMilli()     // <.>
  LocalDate nowAsLocalDate(ZoneId zoneId)     // <.>
  LocalDate nowAsLocalDate()     // <.>
  LocalDateTime nowAsLocalDateTime(ZoneId zoneId)     // <.>
  LocalDateTime nowAsLocalDateTime()     // <.>
  OffsetDateTime nowAsOffsetDateTime(ZoneId zoneId)     // <.>
  OffsetDateTime nowAsOffsetDateTime()     // <.>
  java.util.Date nowAsJavaUtilDate()     // <.>
  java.sql.Timestamp nowAsJavaSqlTimestamp()     // <.>
  XMLGregorianCalendar nowAsXmlGregorianCalendar()     // <.>
  org.joda.time.DateTime nowAsJodaDateTime(ZoneId zoneId)     // <.>
  org.joda.time.DateTime nowAsJodaDateTime()     // <.>
  org.joda.time.LocalDateTime nowAsJodaLocalDateTime(ZoneId zoneId)     // <.>
  org.joda.time.LocalDateTime nowAsJodaLocalDateTime()     // <.>
  org.joda.time.LocalDate nowAsJodaLocalDate(ZoneId zoneId)     // <.>
  org.joda.time.LocalDate nowAsJodaLocalDate()     // <.>
}
----

<.> xref:#nowAsInstant_[nowAsInstant()]
+
--
Returns the (virtual) time as an _Instant_ .
--
<.> xref:#system_[system()]
+
--
Returns the system's default ticking clock.
--
<.> xref:#nowAt_Instant[nowAt(Instant)]
+
--
Returns a ticking clock set to virtual time _Instant_ _virtualNow_
--
<.> xref:#nowAt_java_time_LocalDate[nowAt(java_time_LocalDate)]
+
--
Returns a ticking clock set to virtual time.
--
<.> xref:#nowAt_org_joda_time_LocalDate[nowAt(org_joda_time_LocalDate)]
+
--
[WARNING]
====
[red]#_deprecated:_#

convert use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#nowAt_org_joda_time_LocalDateTime[nowAt(org_joda_time_LocalDateTime)]
+
--
[WARNING]
====
[red]#_deprecated:_#

convert use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#nowAt_org_joda_time_DateTime[nowAt(org_joda_time_DateTime)]
+
--
[WARNING]
====
[red]#_deprecated:_#

convert use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#frozenAt_Instant[frozenAt(Instant)]
+
--
Always returns the time _Instant_ as given by _frozenAt_
--
<.> xref:#frozenAt_org_joda_time_LocalDate[frozenAt(org_joda_time_LocalDate)]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#frozenAt_org_joda_time_LocalDateTime[frozenAt(org_joda_time_LocalDateTime)]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#frozenAt_org_joda_time_DateTime[frozenAt(org_joda_time_DateTime)]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#frozenTestClock_[frozenTestClock()]
+
--
Always returns the time _Instant_ 2003/8/17 21:30:25 (UTC)
--
<.> xref:#localTimeZone_[localTimeZone()]
+
--
Used to interpret local time.
--
<.> xref:#nowAsEpochMilli_[nowAsEpochMilli()]
+
--
Returns the (virtual) time as the number of milliseconds since the epoch start.
--
<.> xref:#nowAsLocalDate_ZoneId[nowAsLocalDate(ZoneId)]
+
--
Returns the (virtual) time as _LocalDate_ , using the _ZoneId_ timezone.
--
<.> xref:#nowAsLocalDate_[nowAsLocalDate()]
+
--
Returns the (virtual) time as _LocalDate_ , using the _ZoneId#systemDefault() system default_ timezone.
--
<.> xref:#nowAsLocalDateTime_ZoneId[nowAsLocalDateTime(ZoneId)]
+
--
Returns the (virtual) time as _LocalDateTime_ , using the _ZoneId_ timezone.
--
<.> xref:#nowAsLocalDateTime_[nowAsLocalDateTime()]
+
--
Returns the (virtual) time as _LocalDateTime_ , using the _ZoneId#systemDefault() system default_ timezone.
--
<.> xref:#nowAsOffsetDateTime_ZoneId[nowAsOffsetDateTime(ZoneId)]
+
--
Returns the (virtual) time as _OffsetDateTime_ , using the _ZoneId_ timezone.
--
<.> xref:#nowAsOffsetDateTime_[nowAsOffsetDateTime()]
+
--
Returns the (virtual) time as _OffsetDateTime_ , using the _ZoneId#systemDefault() system default_ timezone.
--
<.> xref:#nowAsJavaUtilDate_[nowAsJavaUtilDate()]
+
--
Returns the (virtual)time as _java.util.Date_ .
--
<.> xref:#nowAsJavaSqlTimestamp_[nowAsJavaSqlTimestamp()]
+
--
Returns the (virtual) time as _java.sql.Timestamp_ .
--
<.> xref:#nowAsXmlGregorianCalendar_[nowAsXmlGregorianCalendar()]
+
--
Returns the (virtual) time as _XMLGregorianCalendar_ .
--
<.> xref:#nowAsJodaDateTime_ZoneId[nowAsJodaDateTime(ZoneId)]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _org.joda.time.DateTime_ , using the specified _ZoneId_ timezone.
--
<.> xref:#nowAsJodaDateTime_[nowAsJodaDateTime()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _org.joda.time.DateTime_ , using the _ZoneId#systemDefault() system default_ timezone.
--
<.> xref:#nowAsJodaLocalDateTime_ZoneId[nowAsJodaLocalDateTime(ZoneId)]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====
--
<.> xref:#nowAsJodaLocalDateTime_[nowAsJodaLocalDateTime()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _org.joda.time.LocalDateTime_ , using the _ZoneId#systemDefault() system default_ timezone.
--
<.> xref:#nowAsJodaLocalDate_ZoneId[nowAsJodaLocalDate(ZoneId)]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _DateTime_ , using the specified _ZoneId_ timezone.
--
<.> xref:#nowAsJodaLocalDate_[nowAsJodaLocalDate()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _DateTime_ , using the _ZoneId#systemDefault() system default_ timezone.
--

== Members

[#nowAsInstant_]
=== nowAsInstant()

Returns the (virtual) time as an _Instant_ .

[#system_]
=== system()

Returns the system's default ticking clock.

[#nowAt_Instant]
=== nowAt(Instant)

Returns a ticking clock set to virtual time _Instant_ _virtualNow_

[#nowAt_java_time_LocalDate]
=== nowAt(java_time_LocalDate)

Returns a ticking clock set to virtual time.

[#nowAt_org_joda_time_LocalDate]
=== nowAt(org_joda_time_LocalDate)

[WARNING]
====
[red]#_deprecated:_#

convert use java.time variant instead (Joda Time is deprecated)
====

[#nowAt_org_joda_time_LocalDateTime]
=== nowAt(org_joda_time_LocalDateTime)

[WARNING]
====
[red]#_deprecated:_#

convert use java.time variant instead (Joda Time is deprecated)
====

[#nowAt_org_joda_time_DateTime]
=== nowAt(org_joda_time_DateTime)

[WARNING]
====
[red]#_deprecated:_#

convert use java.time variant instead (Joda Time is deprecated)
====

[#frozenAt_Instant]
=== frozenAt(Instant)

Always returns the time _Instant_ as given by _frozenAt_

[#frozenAt_org_joda_time_LocalDate]
=== frozenAt(org_joda_time_LocalDate)

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

[#frozenAt_org_joda_time_LocalDateTime]
=== frozenAt(org_joda_time_LocalDateTime)

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

[#frozenAt_org_joda_time_DateTime]
=== frozenAt(org_joda_time_DateTime)

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

[#frozenTestClock_]
=== frozenTestClock()

Always returns the time _Instant_ 2003/8/17 21:30:25 (UTC)

[#localTimeZone_]
=== localTimeZone()

Used to interpret local time.

Returns _ZoneId#systemDefault()_ .

[#nowAsEpochMilli_]
=== nowAsEpochMilli()

Returns the (virtual) time as the number of milliseconds since the epoch start.

[#nowAsLocalDate_ZoneId]
=== nowAsLocalDate(ZoneId)

Returns the (virtual) time as _LocalDate_ , using the _ZoneId_ timezone.

[#nowAsLocalDate_]
=== nowAsLocalDate()

Returns the (virtual) time as _LocalDate_ , using the _ZoneId#systemDefault() system default_ timezone.

[#nowAsLocalDateTime_ZoneId]
=== nowAsLocalDateTime(ZoneId)

Returns the (virtual) time as _LocalDateTime_ , using the _ZoneId_ timezone.

[#nowAsLocalDateTime_]
=== nowAsLocalDateTime()

Returns the (virtual) time as _LocalDateTime_ , using the _ZoneId#systemDefault() system default_ timezone.

[#nowAsOffsetDateTime_ZoneId]
=== nowAsOffsetDateTime(ZoneId)

Returns the (virtual) time as _OffsetDateTime_ , using the _ZoneId_ timezone.

[#nowAsOffsetDateTime_]
=== nowAsOffsetDateTime()

Returns the (virtual) time as _OffsetDateTime_ , using the _ZoneId#systemDefault() system default_ timezone.

[#nowAsJavaUtilDate_]
=== nowAsJavaUtilDate()

Returns the (virtual)time as _java.util.Date_ .

[#nowAsJavaSqlTimestamp_]
=== nowAsJavaSqlTimestamp()

Returns the (virtual) time as _java.sql.Timestamp_ .

[#nowAsXmlGregorianCalendar_]
=== nowAsXmlGregorianCalendar()

Returns the (virtual) time as _XMLGregorianCalendar_ .

[#nowAsJodaDateTime_ZoneId]
=== nowAsJodaDateTime(ZoneId)

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _org.joda.time.DateTime_ , using the specified _ZoneId_ timezone.

[#nowAsJodaDateTime_]
=== nowAsJodaDateTime()

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _org.joda.time.DateTime_ , using the _ZoneId#systemDefault() system default_ timezone.

[#nowAsJodaLocalDateTime_ZoneId]
=== nowAsJodaLocalDateTime(ZoneId)

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

[#nowAsJodaLocalDateTime_]
=== nowAsJodaLocalDateTime()

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _org.joda.time.LocalDateTime_ , using the _ZoneId#systemDefault() system default_ timezone.

[#nowAsJodaLocalDate_ZoneId]
=== nowAsJodaLocalDate(ZoneId)

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _DateTime_ , using the specified _ZoneId_ timezone.

[#nowAsJodaLocalDate_]
=== nowAsJodaLocalDate()

[WARNING]
====
[red]#_deprecated:_#

use java.time variant instead (Joda Time is deprecated)
====

Returns the time as a Joda _DateTime_ , using the _ZoneId#systemDefault() system default_ timezone.
