Skip to content

Repository files navigation

Clock

Build StatusMaven CentralDepShield 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

DateTimenow = Clock.now();
LongnowAsMillies = Clock.milliseconds();
DateTimetheUnixEpoch = 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-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.

Testing Locally

This builds with Maven 3.6.1 and Java 11.

mvn clean verify

Contributing

Please see the Contribution Guidelines.

About

System Clock abstractions & Joda DateTime providers

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages