Repository navigation
Fix handling of utcDateTime types - #5085
Conversation
Time types defined as utcDateTime now properly convert their values to UTC before sending over the wire. This changed the semantics of the code model's Time.utc value; when true, it indicates that the value must be converted to UTC before sending (see doc comments for more info). Updated the example codegen for time types to construct the time.Time values in place via time.Date() instead of using time.Parse() which was leaking the wire format into the examples. Improved error message when post codegen steps fail due to a Windows MAX_PATH violation. Added VSCode settings to avoid scanning node modules and temp files which tends to peg the CPU for long periods of time. Updated developer docs with info on how to use mise to configure the repo required tooling.
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
commit: |
There was a problem hiding this comment.
Pull request overview
This PR updates the Go emitter’s handling of utcDateTime so RFC3339 date-times are normalized to UTC (via .UTC()) before serialization, while non-offset-preserving encodings (RFC7231, Unix timestamp) avoid unnecessary conversions. It also improves generated samples for date/time values by emitting readable time.Date(...) / time.Unix(...) literals rather than time.Parse(...), and enhances diagnostics for post-emit tooling failures (notably Windows path-length issues).
Changes:
- Normalize RFC3339
utcDateTimevalues to UTC across request construction and model JSON serde (including slice/map shapes) and fix the type cache key soutcDateTimeandoffsetDateTimedon’t share the same cached time wrapper. - Emit more readable Go sample datetime values using
time.Date/time.Unix, preserving offsets foroffsetDateTimeand foldingutcDateTimeto UTC. - Improve post-emit tool failure diagnostics and add developer QoL updates (VS Code settings, mise docs, cspell word).
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/typespec-go/test/unittest/scenarios/models-serde-unpopulate.md | Updates fixture to pass new utc argument to populateTime and demonstrates UTC coercion. |
| packages/typespec-go/test/unittest/scenarios/datetime-utc-marshalling.md | New scenario verifying UTC coercion behavior for header/query RFC3339 and model array fields. |
| packages/typespec-go/test/unittest/scenarios/datetime-example-values.md | New scenario validating example code emits time.Date/time.Unix literals rather than parsing wire strings. |
| packages/typespec-go/test/unittest/scenario-suites/datetime-utc-marshalling.test.ts | Adds generated scenario-suite test wrapper for the UTC marshalling scenario. |
| packages/typespec-go/test/unittest/scenario-suites/datetime-example-values.test.ts | Adds generated scenario-suite test wrapper for the example-values scenario. |
| packages/typespec-go/test/http-specs/encode/datetimegroup/custom_client_test.go | Adds an explicit wire-string assertion test to ensure non-UTC inputs serialize as UTC where required. |
| packages/typespec-go/src/tcgcadapter/types.ts | Adjusts utcDateTime handling and ensures cached time types include utc in the cache key. |
| packages/typespec-go/src/emitter.ts | Improves post-emit tool error messaging (with a Windows MAX_PATH-focused explanation). |
| packages/typespec-go/src/codemodel/type.ts | Clarifies semantics of Time.utc as “must coerce to UTC before marshalling” (RFC3339 utcDateTime only). |
| packages/typespec-go/src/codegen/fake/servers.ts | Removes redundant .UTC() on time.Unix(...) parsing paths for fake server generation. |
| packages/typespec-go/src/codegen/core/operations.ts | Applies UTC coercion for time body params and slice/map date-time marshalling where needed. |
| packages/typespec-go/src/codegen/core/models.ts | Updates generated model serde to support UTC coercion for time fields, slices, and additionalProperties maps. |
| packages/typespec-go/src/codegen/core/helpers.ts | Ensures formatted time values (including slices) apply .UTC() when required by the type model. |
| packages/typespec-go/src/codegen/core/example.ts | Reworks time example rendering to generate time.Date/time.Unix literals with correct UTC/offset semantics. |
| packages/typespec-go/docs/development.md | Adds guidance around using mise shims and documents Windows path-length pitfalls for post-emit tools. |
| packages/typespec-go/.vscode/settings.json | Adds VS Code search/watcher excludes to avoid expensive scans of node_modules/temp. |
| cspell.yaml | Adds pipx to spelling allowlist. |
| .chronus/changes/time-utc-2026-6-28-8-53-58.md | Adds a changelog entry for the UTC normalization + example generation changes. |
|
The "go / emitter diff / Generate & Diff" step was skipped. It appears to be intention since the PR comes from a fork (see here). Why is that? |
It is the limitation for GitHub action to do the diff from fork. You could use a feature branch in current repo instead. |
|
This is a pretty significant limitation. Are there plans to fix it, is it even possible? I would prefer to not use a branch in upstream unless there is really no other choice. |
|
why can't the diff run on a fork? |
From previous Libba's PR: microsoft/typespec#11122 (comment) |
|
If it's just the comment we should still run it, what breaks is commenting on pr this way, there is way around we should just copy here like how we make the chronus comment, it just need 2 workflow which is anoyoing but it works |
|
I opened #5123 to track fixing this. |
Time types defined as utcDateTime now properly convert their values to UTC before sending over the wire. This changed the semantics of the code model's Time.utc value; when true, it indicates that the value must be converted to UTC before sending (see doc comments for more info).
Updated the example codegen for time types to construct the time.Time values in place via time.Date() instead of using time.Parse() which was leaking the wire format into the examples.
Improved error message when post codegen steps fail due to a Windows MAX_PATH violation.
Added VSCode settings to avoid scanning node modules and temp files which tends to peg the CPU for long periods of time. Updated developer docs with info on how to use mise to configure the repo required tooling.
Fixes: