-
Notifications
You must be signed in to change notification settings - Fork 943
Updated date time APIs #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated date time APIs #392
Conversation
@jimmyjames As someone reviewing this, it would be beneficial here to have some information in the PR about why these changes are being made. What are the benefits of |
I've updated the PR description to capture the motivations. |
Co-Authored-By: Luciano Balmaceda <[email protected]>
69415a3
to
1dcc415
Compare
@@ -1,15 +1,24 @@ | |||
package com.auth0.jwt.interfaces; | |||
|
|||
import java.time.Instant; | |||
import java.util.Date; | |||
|
|||
/** | |||
* The Clock class is used to wrap calls to Date class. | |||
*/ | |||
public interface Clock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... probably not appropriate to do it during this PR, but should this interface be deprecated in favor of java.time.Clock
?
Changes
Adds new APIs for DateTime claims using java.time.Instant
Motivations:
Instant
over date are immutability (thread-safe), better API design allowing for more natural time-based calculations, and nanosecond precision (as opposed to millisecond precision withjava.util.Date
).This change adds the following new public APIs:
Claim.java:
Instant asInstant()
Clock.java:
Instant getNow()
JWTCreator.java:
Builder withNotBefore(Instant notBefore)
Builder withIssuedAt(Instant issuedAt)
Builder withClaim(String name, Instant value)
Payload.java:
Instant getExpiresAtInstant()
Instant getNotBeforeInstant()
Instant getIssuedAtInstant()
Verification.java:
Verification withClaim(String name, Instant value)
A separate later PR will deprecate the
java.util.Date
APIs in favor of these new ones.References
There are many articles and resources regarding the new date/time APIs introduced in JDK8. This article discusses it at a high level.
Testing
Tests updated to use the new Date/Time APIs.
Checklist