clock

A simple abstraction of the system clock for testing purposes

License

License

GroupId

GroupId

com.deere.isg
ArtifactId

ArtifactId

clock
Last Version

Last Version

3.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

clock
A simple abstraction of the system clock for testing purposes
Project URL

Project URL

http://github.com/JohnDeere/clock
Source Code Management

Source Code Management

https://github.com/JohnDeere/clock

Download clock

How to add to project

<!-- https://jarcasting.com/artifacts/com.deere.isg/clock/ -->
<dependency>
    <groupId>com.deere.isg</groupId>
    <artifactId>clock</artifactId>
    <version>3.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.deere.isg/clock/
implementation 'com.deere.isg:clock:3.1.0'
// https://jarcasting.com/artifacts/com.deere.isg/clock/
implementation ("com.deere.isg:clock:3.1.0")
'com.deere.isg:clock:jar:3.1.0'
<dependency org="com.deere.isg" name="clock" rev="3.1.0">
  <artifact name="clock" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.deere.isg', module='clock', version='3.1.0')
)
libraryDependencies += "com.deere.isg" % "clock" % "3.1.0"
[com.deere.isg/clock "3.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
joda-time : joda-time jar 2.10

test (1)

Group / Artifact Type Version
junit : junit jar 4.8.2

Project Modules

There are no modules declared in this project.

Clock

Build Status Maven Central DepShield Badge

System Clock Abstractions & Joda DateTime providers.

Installation

Clock requires Java 8+ to run.

<dependency>
    <groupId>com.deere.isg</groupId>
    <artifactId>clock</artifactId>
    <version>3.1.0</version>
</dependency>

Module support for Java 9 and later

 requires com.deere.isg.clock;

Usage

Getting the current date-time in UTC

   DateTime now = Clock.now();
   Long nowAsMillies = Clock.milliseconds();
   DateTime theUnixEpoch = Clock.epoch(); // -> 1970-01-01:00:00:00

Freezing the clock

Many times in tests you might want to set the system clock to a specific time or simply stop it from progressing. You can do this with freeze. Note that because the clock is static (like the real clock), you must unfreeze it in your teardown.

   Clock.freeze(2011,09,28,4,20); // by a full date-time
   Clock.freeze(2011,09,28); // by just the date
   Clock.freeze(420); // by millies
   Clock.freeze(new DateTime()); // by a specific datetime instance
   Clock.freeze(); //Just stops the clock at the current datetime.
   Clock.freeze(new YourOwnClock()); // define time on your own terms

   Clock.clear() // unfreezes the clock and returns it to system clock progression.

Testing Locally

This builds with Maven 3.6.1 and Java 11.

mvn clean verify

Contributing

Please see the Contribution Guidelines.

com.deere.isg

John Deere

Versions

Version
3.1.0
3.0.0