Deprecate Shared Instant and replace uses of it with Kotlin Instant#781
Open
stevenzeck wants to merge 7 commits intoreadium:developfrom
Open
Deprecate Shared Instant and replace uses of it with Kotlin Instant#781stevenzeck wants to merge 7 commits intoreadium:developfrom
stevenzeck wants to merge 7 commits intoreadium:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the toolkit away from the custom org.readium.r2.shared.util.Instant wrapper by adopting the Kotlin standard library kotlin.time.Instant, adding a shared parsing helper (String.toInstant()), updating call sites, and deprecating the legacy wrapper API.
Changes:
- Added
String.toInstant()to parse ISO-8601-like date strings (with fallback parsing) into Kotlin instants. - Replaced usages of the legacy Shared
Instantacross Shared/OPDS/Streamer/LCP/Test app modules withkotlin.time.Instantand epoch-millis conversions where needed. - Deprecated the legacy
Instantwrapper and documented migration guidance in the changelog.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test-app/src/main/java/org/readium/r2/testapp/reader/PublicationMetadataDialogFragment.kt | Switches publication date handling to kotlin.time.Clock/System.now() and epoch-millis to java.util.Date. |
| test-app/src/main/java/org/readium/r2/testapp/drm/LcpManagementViewModel.kt | Replaces legacy toJavaDate() with Date(instant.toEpochMilliseconds()) conversions. |
| readium/streamer/src/test/java/org/readium/r2/streamer/parser/epub/MetadataTest.kt | Updates imports after Instant migration (currently introduces an unused import). |
| readium/streamer/src/main/java/org/readium/r2/streamer/parser/epub/MetadataAdapter.kt | Uses the new String.toInstant() when parsing EPUB metadata dates. |
| readium/shared/src/test/java/org/readium/r2/shared/util/InstantTest.kt | Suppresses deprecation warnings for tests that still cover the legacy wrapper. |
| readium/shared/src/test/java/org/readium/r2/shared/publication/MetadataTest.kt | Migrates test data from Instant.parse(...) to String.toInstant(). |
| readium/shared/src/test/java/org/readium/r2/shared/opds/AvailabilityTest.kt | Migrates test data from Instant.parse(...) to String.toInstant(). |
| readium/shared/src/main/java/org/readium/r2/shared/util/Instant.kt | Deprecates the legacy Instant wrapper and suggests replacements. |
| readium/shared/src/main/java/org/readium/r2/shared/publication/Metadata.kt | Switches modified/published to Kotlin Instant and parses via toInstant(). |
| readium/shared/src/main/java/org/readium/r2/shared/opds/OpdsMetadata.kt | Switches OPDS metadata modified to Kotlin Instant. |
| readium/shared/src/main/java/org/readium/r2/shared/opds/Availability.kt | Switches OPDS availability instants and parsing to Kotlin Instant/toInstant(). |
| readium/shared/src/main/java/org/readium/r2/shared/extensions/String.kt | Introduces String.toInstant() extension for permissive parsing. |
| readium/opds/src/test/java/org/readium/r2/opds/OPDS1ParserTest.kt | Updates OPDS1 parser tests to use String.toInstant() for dates. |
| readium/opds/src/main/java/org/readium/r2/opds/OPDS2Parser.kt | Updates OPDS2 parsing to use String.toInstant() for modified. |
| readium/opds/src/main/java/org/readium/r2/opds/OPDS1Parser.kt | Updates OPDS1 parsing to use String.toInstant() for modified/published. |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/lsd/PotentialRights.kt | Switches LSD rights end date parsing to Kotlin Instant via toInstant(). |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/lsd/Event.kt | Switches event timestamp parsing to Kotlin Instant via toInstant(). |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/model/components/lcp/Rights.kt | Switches start/end parsing to Kotlin Instant via toInstant(). |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/model/StatusDocument.kt | Switches updated timestamps parsing to Kotlin Instant via toInstant(). |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/model/LicenseDocument.kt | Switches issued/updated parsing to Kotlin Instant via toInstant(). |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/LicenseValidation.kt | Switches “now” to Clock.System.now() for license validation logic. |
| readium/lcp/src/main/java/org/readium/r2/lcp/license/License.kt | Migrates license API surface to Kotlin Instant. |
| readium/lcp/src/main/java/org/readium/r2/lcp/MaterialRenewListener.kt | Uses Clock.System.now() and epoch millis for the date picker integration. |
| readium/lcp/src/main/java/org/readium/r2/lcp/LcpLicense.kt | Migrates LCP license API to Kotlin Instant. |
| readium/lcp/src/main/java/org/readium/r2/lcp/LcpError.kt | Migrates error model references to Kotlin Instant. |
| CHANGELOG.md | Documents the deprecation and migration guidance for instants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+50
to
+51
| ?: tryOrNull { LocalDateTime.parse(this).toInstant(TimeZone.UTC) } | ||
| ?: tryOrNull { LocalDate.parse(this).atStartOfDayIn(TimeZone.UTC) } |
Contributor
Author
There was a problem hiding this comment.
LocalDateTime.toInstant and LocalDate.atStartOfDayIn both return kotlin.time.Instant.
Comment on lines
57
to
62
| @@ -50,24 +62,58 @@ public class Instant private constructor( | |||
| return instant?.let { Instant(it) } | |||
Contributor
Author
There was a problem hiding this comment.
Same comment as String.kt.
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
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.
Since Kotlin 2.1.20, Instant has been available in the Kotlin standard library. This PR does the following:
String.toInstant(), to parse strings into Kotlin InstanttoInstantwhere necessary.