aviad aviad - 1 year ago 80
Java Question

How to compare Joda DateTime objects with acceptable offset (tolerance)?

I wonder is there any standard API in

to compare 2
objects with specified tolerance?
I am looking for a one-liner preferably by using
standard API. Not for time-aritmethic expressions like in this post.

Ideally, it would be something like:

boolean areNearlyEqual = SomeJodaAPIClass.equal(dt1, dt2, maxTolerance);


Answer Source

Use this:

new Duration(dt1, dt2).isShorterThan(Duration.millis(maxTolerance))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download