-
Notifications
You must be signed in to change notification settings - Fork 30
Convert All Usage of LocalDateTime
to Instant
#456
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parthban-db
reviewed
Jun 4, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/CliTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/CliTokenSource.java
Show resolved
Hide resolved
parthban-db
reviewed
Jun 4, 2025
databricks-sdk-java/src/main/java/com/databricks/sdk/core/CliTokenSource.java
Show resolved
Hide resolved
renaudhartert-db
approved these changes
Jun 4, 2025
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.
LGTM modulo resolution of the fallback discussion.
parthban-db
approved these changes
Jun 5, 2025
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes are proposed in this pull request?
This pull request refactors the Databricks Java SDK to replace all usages of LocalDateTime with Instant for representing date-time values. The primary motivation is to ensure that all date-time handling is unambiguous, always in UTC, and consistent across the SDK.
How does time currently operate in the SDK?
Currently, tokens in the SDK use LocalDateTime for expiry timestamps, which by itself is timezone-agnostic and could be ambiguous. Thus, it is not clear how time is handled from the type alone and we need to look at the implementation details of the ClockSupplier used.
The SDK currently uses system time through the
SystemClockSupplier
class as defined here. This implementation of the ClockSupplier interface returnsClock.systemDefaultZone()
, meaning it uses the actual system time from the operating system. TheSystemClockSupplier
is the used throughout the SDK to conduct OAuth token expiration checks as seen here in theisExpired()
method of the Token class. WhileLocalDateTime
doesn't explicitly store timezone information, the system's timezone is being implicitly used for these comparisons throughClock.systemDefaultZone()
. In other words, token expiry times are implicitly measured in the system's timezone.Converting to UTC
To convert these expiry times to UTC while maintaining the SDK's current behavior, we need to handle two distinct scenarios:
1. Tokens with
expires_in
Add the
expires_in
value to the current UTC time.This approach maintains the original expiration behavior while using UTC internally.
2. Tokens with
expires_on
(e.g., Azure CLI, Databricks CLI)With Time Zone Indicator
These can be easily converted to UTC using standard library methods.
Without Time Zone Indicator
expiresOn
field from Azure CLIReference
We do this with
LocalDateTime.atZone(systemDefault).toInstant()
How is this tested?
Future Work
expiresOn
: Local datetime without timezone (maintained for backward compatibility)expires_on
: POSIX timestamp (seconds since epoch) - preferred formatCurrent Implementation
expiresOn
fieldLocalDateTime
creates timezone interpretation challengesTo Do
expiresOn
This legacy field should be deprecated in favor of
expires_on
Future PRs should prioritize using
expires_on
(POSIX timestamp) which:NO_CHANGELOG=true