-
Notifications
You must be signed in to change notification settings - Fork 0
feat: java.time.ZonedDateTime resolver #63
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
MessiasLima
merged 7 commits into
main
from
add-zoned-date-time-resolver-8048027922549992562
Jun 15, 2026
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db5e349
Add support for java.time.ZonedDateTime
google-labs-jules[bot] a4d3555
Update documentation for ZonedDateTime support
google-labs-jules[bot] e7af4d1
Update AGENTS.md for ZonedDateTime support
google-labs-jules[bot] c76bd71
Use random ZoneId in JavaZonedDateTimeResolver
google-labs-jules[bot] cf060c0
Optimize JavaZonedDateTimeResolver and add KDocs
google-labs-jules[bot] 6fe74c7
Merge branch 'main' into add-zoned-date-time-resolver-804802792254999…
MessiasLima 0e23c9d
min and max constants
MessiasLima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/dev/appoutlet/some/resolver/JavaZonedDateTimeResolver.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package dev.appoutlet.some.resolver | ||
|
|
||
| import dev.appoutlet.some.core.ResolverChain | ||
| import dev.appoutlet.some.core.TypeResolver | ||
| import java.time.LocalDate | ||
| import java.time.LocalTime | ||
| import java.time.Year | ||
| import java.time.ZoneOffset | ||
| import java.time.ZonedDateTime | ||
| import kotlin.random.Random | ||
| import kotlin.reflect.KType | ||
| import kotlin.reflect.typeOf | ||
|
|
||
| private const val HOURS_IN_DAY = 24 | ||
| private const val MINUTES_IN_HOUR = 60 | ||
| private const val SECONDS_IN_MINUTE = 60 | ||
| private const val START_YEAR = 1970 | ||
| private const val END_YEAR = 2100 | ||
|
|
||
| class JavaZonedDateTimeResolver(private val random: Random) : TypeResolver { | ||
|
MessiasLima marked this conversation as resolved.
|
||
| override fun canResolve(type: KType): Boolean { | ||
| return type == typeOf<ZonedDateTime>() | ||
| } | ||
|
|
||
| override fun resolve(type: KType, chain: ResolverChain): Any { | ||
| val year = random.nextInt(START_YEAR, END_YEAR + 1) | ||
| val dayOfYear = random.nextInt(1, Year.of(year).length() + 1) | ||
| val hour = random.nextInt(HOURS_IN_DAY) | ||
| val minute = random.nextInt(MINUTES_IN_HOUR) | ||
| val second = random.nextInt(SECONDS_IN_MINUTE) | ||
| val date = LocalDate.ofYearDay(year, dayOfYear) | ||
| return ZonedDateTime.of(date, LocalTime.of(hour, minute, second), ZoneOffset.UTC) | ||
| } | ||
| } | ||
|
MessiasLima marked this conversation as resolved.
|
||
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/dev/appoutlet/some/resolver/JavaZonedDateTimeResolverTest.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package dev.appoutlet.some.resolver | ||
|
|
||
| import dev.appoutlet.some.test.defaultTestChain | ||
| import java.time.Instant | ||
| import java.time.ZonedDateTime | ||
| import kotlin.random.Random | ||
| import kotlin.reflect.typeOf | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertIs | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class JavaZonedDateTimeResolverTest { | ||
| @Test | ||
| fun `JavaZonedDateTimeResolver generates ZonedDateTime values`() { | ||
| val resolver = JavaZonedDateTimeResolver(Random.Default) | ||
|
|
||
| val result = resolver.resolve(typeOf<ZonedDateTime>(), defaultTestChain) | ||
| assertIs<ZonedDateTime>(result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `JavaZonedDateTimeResolver generates ZonedDateTime within valid range`() { | ||
| val resolver = JavaZonedDateTimeResolver(Random.Default) | ||
| val start = ZonedDateTime.parse("1970-01-01T00:00:00Z") | ||
| val end = ZonedDateTime.parse("2101-01-01T00:00:00Z") | ||
|
|
||
| repeat(100) { | ||
| val result = resolver.resolve(typeOf<ZonedDateTime>(), defaultTestChain) as ZonedDateTime | ||
| assertTrue(result.isAfter(start) || result.isEqual(start), "ZonedDateTime should be after or at 1970-01-01") | ||
| assertTrue(result.isBefore(end), "ZonedDateTime should be before 2101-01-01") | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `JavaZonedDateTimeResolver canResolve detects ZonedDateTime type`() { | ||
| val resolver = JavaZonedDateTimeResolver(Random.Default) | ||
| assertTrue(resolver.canResolve(typeOf<ZonedDateTime>())) | ||
| } | ||
|
|
||
| @Test | ||
| fun `JavaZonedDateTimeResolver rejects other types`() { | ||
| val resolver = JavaZonedDateTimeResolver(Random.Default) | ||
| assertFalse(resolver.canResolve(typeOf<String>()), "Should not resolve String") | ||
| assertFalse(resolver.canResolve(typeOf<Int>()), "Should not resolve Int") | ||
| assertFalse(resolver.canResolve(typeOf<Instant>()), "Should not resolve java.time.Instant") | ||
| } | ||
| } |
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.
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.
@jules add detailed KDocs