Repository navigation
Support ISO-8601 date/time strings in A2uiFormatDateFunction - #906
Open
zeroasterisk wants to merge 1 commit into
Open
zeroasterisk wants to merge 1 commit into
zeroasterisk wants to merge 1 commit into
Conversation
A2uiFormatDateFunction.execute() required the 'value' argument to be an epoch timestamp (seconds or milliseconds, as a Number or numeric String). Canonical A2UI examples (e.g. specification/v1_0/catalogs/basic/examples/ 01_flight-status.json in a2ui-project/a2ui) send date fields as ISO-8601 strings (e.g. "2025-12-15", "2025-12-15T10:15:00Z"), which A2uiFunctionArgParser.getLongArg() rejects with an A2uiException.A2uiValidationException. Add ISO-8601 date/date-time string parsing (date-only, minute, second, and millisecond precision, with or without a trailing 'Z') as a fallback when the value isn't numeric, reusing the same pattern list already used by androidx.a2ui.compose.ui.catalog.parseIsoDateTimeToUtcMillis for DateTimeInput components, so both catalog surfaces parse ISO date/time strings consistently. Non-date, non-numeric strings continue to throw A2uiException.A2uiValidationException as before -- callers that already run function execution through A2uiCoreExecutionContext.executeFunction() route this to dispatchError() rather than crashing, so no separate crash-handling change was needed there; it verified there. Test: ./gradlew :a2ui:a2ui-model:testDebugUnitTest (unit tests updated to cover ISO date-only, ISO instant, ISO instant with milliseconds, and verifying invalid strings still throw A2uiValidationException). All 13 pre-existing tests plus 4 new ones verified locally against a standalone Kotlin/JVM compile of the affected sources (JUnit4 + Truth), since the sandboxed environment used to prepare this change has no Android SDK / full Gradle build available.
This branch has not been deployed
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.
A2uiFormatDateFunction.execute() only accepted the
valueargument as an epoch timestamp (a Number, or a numeric String), via A2uiFunctionArgParser.getLongArg(). Canonical A2UI examples send date fields as ISO-8601 strings -- e.g.specification/v1_0/catalogs/basic/examples/01_flight-status.jsonin a2ui-project/a2ui sends"date": "2025-12-15"and"departureTime": "2025-12-15T10:15:00Z"-- which threwA2uiException.A2uiValidationException("Invalid 'value' argument, expected long").This adds ISO-8601 date/date-time string parsing as a fallback when
valueisn't numeric, supporting date-only and date-time values (minute/second/millisecond precision, with or without a trailingZ). It reuses the same pattern list already used byandroidx.a2ui.compose.ui.catalog.parseIsoDateTimeToUtcMillis(used forDateTimeInputcomponents) so both catalog surfaces parse ISO date/time strings consistently.Non-date, non-numeric values still throw
A2uiException.A2uiValidationException, unchanged.On the separate 'validation exception crashes the app' concern raised alongside this bug: I traced
A2uiCoreExecutionContext.executeFunction()(a2ui-engine) andA2uiComponentScopeImpl.resolvePayload()(compose-runtime) -- both already wrap function execution in try/catch and routeA2uiException/genericExceptiontodispatchError()/reportError()instead of propagating. So a thrownA2uiValidationExceptionfromformatDatedoes not crash the app through those paths; it is reported back to the agent as intended. No change was needed there.Test: Ported the upstream
A2uiFormatDateFunctionTestunmodified into a standalone Kotlin/JVM harness (extracted a2ui-model sources, JUnit4 + Truth, since the sandbox available to prepare this change has no Android SDK / full Gradle build) and ran it against both the old and new implementation:A2uiValidationExceptionas described in the bug report.A2uiFormatDateFunctionTest.ktcovering ISO date-only, ISO instant, ISO instant with milliseconds, and confirming non-date garbage strings still throwA2uiValidationException. 17/17 pass.Please re-run
./gradlew :a2ui:a2ui-model:testin CI/Treehugger to confirm on the real Android toolchain.