Skip to content

Fix handling of utcDateTime types - #5085

Merged
Joel Hendrix (jhendrixMSFT) merged 6 commits into
Azure:mainfrom
jhendrixMSFT:time-utc
Jul 31, 2026
Merged

Joel Hendrix (jhendrixMSFT) merged 6 commits into
Azure:mainfrom
jhendrixMSFT:time-utc

Conversation

@jhendrixMSFT

@jhendrixMSFT Joel Hendrix (jhendrixMSFT) commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

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:

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.
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:go Issues for @azure-tools/typespec-go emitter label Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @azure-tools/typespec-go
Show changes

@azure-tools/typespec-go - fix ✏️

Ensure UTC date-time values are converted to UTC before sending. Update example generation for date-time values to use time.Date() instead of time.Parse() which leaks the wire format.

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-go@5085

commit: e2f1978

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 utcDateTime values to UTC across request construction and model JSON serde (including slice/map shapes) and fix the type cache key so utcDateTime and offsetDateTime don’t share the same cached time wrapper.
  • Emit more readable Go sample datetime values using time.Date / time.Unix, preserving offsets for offsetDateTime and folding utcDateTime to 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.

Comment thread packages/typespec-go/src/emitter.ts Resolved
@jhendrixMSFT

Copy link
Copy Markdown
Member Author

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?

@tadelesh

Chenjie Shi (tadelesh) commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

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.

@jhendrixMSFT

Copy link
Copy Markdown
Member Author

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.

CC Heath Stewart (@heaths)

@timotheeguerin

Copy link
Copy Markdown
Member

why can't the diff run on a fork?

@tadelesh

Copy link
Copy Markdown
Member

why can't the diff run on a fork?

From previous Libba's PR: microsoft/typespec#11122 (comment)

@timotheeguerin

Timothee Guerin (timotheeguerin) commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

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

@jhendrixMSFT

Copy link
Copy Markdown
Member Author

I opened #5123 to track fixing this.

Merged via the queue into Azure:main with commit 2f049f5 Jul 31, 2026
44 checks passed
@jhendrixMSFT
Joel Hendrix (jhendrixMSFT) deleted the time-utc branch July 31, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:go Issues for @azure-tools/typespec-go emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When can codegen assume GMT/UTC/etc time Example generator emits invalid Go for RFC7231 datetime values (regression from #1992)

5 participants