System Clock Abstractions & Joda DateTime providers.
Clock requires Java 8+ to run.
<dependency>
<groupId>com.deere.isg</groupId>
<artifactId>clock</artifactId>
<version>3.1.0</version>
</dependency> requires com.deere.isg.clock;
Getting the current date-time in UTC
DateTimenow = Clock.now();
LongnowAsMillies = Clock.milliseconds();
DateTimetheUnixEpoch = Clock.epoch(); // -> 1970-01-01:00:00:00Many 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-timeClock.freeze(2011,09,28); // by just the dateClock.freeze(420); // by milliesClock.freeze(newDateTime()); // by a specific datetime instanceClock.freeze(); //Just stops the clock at the current datetime.Clock.freeze(newYourOwnClock()); // define time on your own termsClock.clear() // unfreezes the clock and returns it to system clock progression.This builds with Maven 3.6.1 and Java 11.
mvn clean verifyPlease see the Contribution Guidelines.