Skip to content

Add AlwaysOutputFractionalSeconds to DateTime scalar options#9745

Merged
glen-84 merged 3 commits into
mainfrom
gai/always-output-fractional-seconds
May 20, 2026
Merged

Add AlwaysOutputFractionalSeconds to DateTime scalar options#9745
glen-84 merged 3 commits into
mainfrom
gai/always-output-fractional-seconds

Conversation

@glen-84
Copy link
Copy Markdown
Member

@glen-84 glen-84 commented May 20, 2026

Summary

  • Adds an opt-in AlwaysOutputFractionalSeconds option to both DateTimeOptions structs — the core scalars one (HotChocolate.Types.DateTimeOptions) and the NodaTime one (HotChocolate.Types.NodaTime.DateTimeOptions). When enabled, fractional seconds are always emitted in serialized output, padded with trailing zeros up to OutputPrecision. Defaults to false, preserving today's trailing-zero-stripping behavior.
  • Affects all six scalars that share these option structs: DateTimeType, LocalDateTimeType, LocalTimeType in each of the two packages. Input parsing is unchanged.
  • For the core scalars, the default-precision const-string shortcut (UtcFormat / LocalFormat) is bypassed when padding is requested, since those constants encode the F (non-padding) specifier.
  • Updates the v15→v16 migration guide for DateTime scalar serialization with the new option and a recipe to restore the v15 fff shape (OutputPrecision = 3 + AlwaysOutputFractionalSeconds = true).

Test plan

  • New tests in core DateTimeTypeTests covering: padding at default precision (exercises the const-shortcut bypass), padding at precision 3, whole-second value emitting .000, precision-0 no-op, and the local-offset (non-Utc) format path.
  • New default-precision pad tests in core LocalDateTimeTypeTests and LocalTimeTypeTests guarding each class's own const-shortcut bypass.
  • New tests in NodaTime DateTimeTypeTests covering: padding at precisions 9 and 3, whole-second value emitting .000, and precision-0 no-op.
  • Existing test suites pass: NodaTime (524 tests) and core DateTimeType / LocalDateTimeType / LocalTimeType (176 tests).

Copilot AI review requested due to automatic review settings May 20, 2026 08:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new scalar configuration option to control whether serialized date/time values always include a fractional-seconds component (zero-padded to the configured output precision), instead of omitting it when it would be all zeros.

Changes:

  • Introduced AlwaysOutputFractionalSeconds on DateTimeOptions (both .NET and NodaTime option types).
  • Updated .NET scalar format selection (DateTimeType, LocalDateTimeType, LocalTimeType) to use f vs F format specifiers based on the new option (while preserving the existing default fast-path when padding is disabled).
  • Updated NodaTime scalar format selection to support the same padding behavior, plus added/expanded tests covering padding, whole-second zeros, precision 0 no-op, and offset behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/HotChocolate/Core/test/Types.Tests/Types/Scalars/LocalTimeTypeTests.cs Adds a regression test ensuring default-precision output pads fractional seconds when enabled.
src/HotChocolate/Core/test/Types.Tests/Types/Scalars/LocalDateTimeTypeTests.cs Adds a regression test ensuring default-precision output pads fractional seconds when enabled.
src/HotChocolate/Core/test/Types.Tests/Types/Scalars/DateTimeTypeTests.cs Adds coverage for padded output across precisions, whole-second behavior, precision 0, and non-UTC offsets.
src/HotChocolate/Core/test/Types.NodaTime.Tests/DateTimeTypeTests.cs Adds equivalent padding behavior tests for NodaTime scalars.
src/HotChocolate/Core/src/Types/Types/Scalars/LocalTimeType.cs Switches output formatting to optionally pad fractional seconds (f) vs trim (F).
src/HotChocolate/Core/src/Types/Types/Scalars/LocalDateTimeType.cs Switches output formatting to optionally pad fractional seconds (f) vs trim (F).
src/HotChocolate/Core/src/Types/Types/Scalars/DateTimeType.cs Switches both UTC/local output formats to optionally pad fractional seconds (f) vs trim (F).
src/HotChocolate/Core/src/Types/Types/Scalars/DateTimeOptions.cs Adds AlwaysOutputFractionalSeconds option with documentation.
src/HotChocolate/Core/src/Types.NodaTime/LocalTimeType.cs Adds padding-aware output format selection; keeps input parsing non-padded.
src/HotChocolate/Core/src/Types.NodaTime/LocalDateTimeType.cs Adds padding-aware output format selection; keeps input parsing non-padded.
src/HotChocolate/Core/src/Types.NodaTime/DateTimeType.cs Adds padding-aware output format selection; keeps input parsing non-padded.
src/HotChocolate/Core/src/Types.NodaTime/DateTimeOptions.cs Adds AlwaysOutputFractionalSeconds option with documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added the 📚 documentation This issue is about working on our documentation. label May 20, 2026
@glen-84 glen-84 merged commit b9a77ba into main May 20, 2026
142 checks passed
@glen-84 glen-84 deleted the gai/always-output-fractional-seconds branch May 20, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants