Giter Club home page Giter Club logo

clocks's Introduction

Clocks

Maven Central

Implementations of JSR310's java.time.Clock to help with testing, and for integration with Joda-Time.

Modules

  • testing - test clocks for use with codebases that only use java.time
  • joda - JodaClock and various friends, a bridge between Joda-Time and java.time
  • joda-testing - equivalent test clocks that extend JodaClock

Testing

The basic test clock is ManualClock, which is constructed with an initial time and zone, and can be advanced by fixed intervals or to other instants. It enforces time only going forwards.

SupplierClock is mainly a convenience to wrap a supplier of instants as a clock (with some initial time zone). LatchableClock is a hybrid clock that can either be "free-running" (just like the system clock) or "frozen" (just like a manual clock).

Joda-Time integration

JodaClock is an abstract extension of java.time.Clock that provides factory methods for Joda-Time instants, DateTimes and LocalDates. It also allows accessing and overriding the time zone based on DateTimeZone as well as ZoneId. The default JodaCompatibleClock implementation uses Joda-Time's static DateTimeUtils accessor as the time source- so getting the instant from a clock instant works just like Joda's "now" factory method.

This can be used for adopting the pattern of Clock objects for Joda-Time in general, and is also a useful aid when combining codebases that use java.time and Joda-Time, since JodaClock objects can be shared between both. JodaClock also supports being wrapped around any Clock object.

In addition, the joda-testing module provides ManualJodaClock etc classes, equivalent to the JSR310 clocks in the testing module.

joda-testing also provides a ResetTime JUnit rule, that will reset Joda's static time to a fixed point before a test, and release it afters. ResetTime also itself implements JodaClock directly, and has similar bump/advance methods to ManualJodaClock.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.