Add AlwaysOutputFractionalSeconds to DateTime scalar options#9745
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
AlwaysOutputFractionalSecondsonDateTimeOptions(both .NET and NodaTime option types). - Updated .NET scalar format selection (
DateTimeType,LocalDateTimeType,LocalTimeType) to usefvsFformat 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.
This was referenced May 20, 2026
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.
Summary
AlwaysOutputFractionalSecondsoption to bothDateTimeOptionsstructs — 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 toOutputPrecision. Defaults tofalse, preserving today's trailing-zero-stripping behavior.DateTimeType,LocalDateTimeType,LocalTimeTypein each of the two packages. Input parsing is unchanged.UtcFormat/LocalFormat) is bypassed when padding is requested, since those constants encode theF(non-padding) specifier.DateTimescalar serialization with the new option and a recipe to restore the v15fffshape (OutputPrecision = 3+AlwaysOutputFractionalSeconds = true).Test plan
DateTimeTypeTestscovering: 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.LocalDateTimeTypeTestsandLocalTimeTypeTestsguarding each class's own const-shortcut bypass.DateTimeTypeTestscovering: padding at precisions 9 and 3, whole-second value emitting.000, and precision-0 no-op.DateTimeType/LocalDateTimeType/LocalTimeType(176 tests).