-
Notifications
You must be signed in to change notification settings - Fork 202
DateOnly and TimeOnly implementation #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #573 +/- ##
==========================================
+ Coverage 94.24% 94.27% +0.02%
==========================================
Files 21 21
Lines 3216 3232 +16
Branches 509 516 +7
==========================================
+ Hits 3031 3047 +16
Misses 123 123
Partials 62 62 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 implements support for generating System.DateOnly and System.TimeOnly types for XML Schema xs:date and xs:time types respectively, addressing feature requests #524 and #310. When enabled via the new UseDateOnly configuration option, the generator will produce .NET 6.0+ compatible date and time types instead of the traditional DateTime type.
Key Changes:
- Adds a new
UseDateOnlyconfiguration property that controls whetherxs:dateandxs:timemap toDateOnly/TimeOnlyorDateTime - Introduces internal placeholder structs for
DateOnlyandTimeOnlyto enable type mapping even when the generator runs on older .NET frameworks (netstandard2.0) - Adds CLI support via the
--dateOnly(or-do) option - Fixes an existing bug where
xs:datewithDateTimeWithTimeZone=trueincorrectly included the DataType attribute
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| XmlSchemaClassGenerator/GeneratorConfiguration.cs | Adds the UseDateOnly boolean property with XML documentation |
| XmlSchemaClassGenerator/Generator.cs | Exposes UseDateOnly property and includes minor whitespace formatting improvements |
| XmlSchemaClassGenerator/CodeUtilities.cs | Defines internal DateOnly/TimeOnly structs, updates type mapping logic in GetEffectiveType, adds type reference mapping in CreateTypeReference, and consolidates DataType attribute logic for date/time types |
| XmlSchemaClassGenerator/TypeModel.cs | Adds default value parsing support for DateOnly and TimeOnly using .Parse() methods, includes unrelated indentation/formatting changes |
| XmlSchemaClassGenerator.Tests/DateTimeTypeTests.cs | Fixes test name and assertion to correctly reflect that DataType attribute should NOT be present when using DateTimeOffset with xs:date |
| XmlSchemaClassGenerator.Tests/DateOnlyTimeOnlyTests.cs | Adds comprehensive test coverage for the new DateOnly/TimeOnly feature including default values and interaction with DateTimeWithTimeZone |
| XmlSchemaClassGenerator.Console/Program.cs | Adds --dateOnly command-line option for CLI users |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Lines starting with # and empty lines are ignored.", v => nameSubstituteFiles.Add(v) }, | ||
| { "o|output=", "the {FOLDER} to write the resulting .cs files to", v => outputFolder = v }, | ||
| { "d|datetime-offset", "map xs:datetime and derived types to System.DateTimeOffset instead of System.DateTime", v => dateTimeWithTimeZone = v != null }, | ||
| { "do|dateOnly", "map xs:date to System.DateOnly and xs:time to System.TimeOnly", v => useDateOnly = v != null }, |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new command-line option --dateOnly (or -do) should be documented in the README.md file to match the documentation pattern for other CLI options like --datetime-offset. Users need to be able to discover this new feature through the project documentation.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot open a new pull request to apply changes based on the comments in this thread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -d, --datetime-offset map xs:datetime, xs:date and xs:time to System. | ||
| DateTimeOffset instead of System.DateTime | ||
| --do, --dateOnly map xs:date and xs:time to System.DateOnly and | ||
| System.TimeOnly instead of System.DateTime |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should clarify that DateOnly and TimeOnly are only available in .NET 6+ to help users understand framework requirements.
| System.TimeOnly instead of System.DateTime | |
| System.TimeOnly instead of System.DateTime | |
| (requires .NET 6.0 or later) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be needed
|
@Lanayx Thanks! |
Walkthrough - Implement DateOnly/TimeOnly Support
I have implemented support for generating
System.DateOnlyandSystem.TimeOnlytypes forxs:dateandxs:timeXML schema types.Changes
1.
GeneratorConfiguration.csandGenerator.csAdded a new configuration property
UseDateOnly.2.
CodeUtilities.csDateOnlyandTimeOnlystructs to allow the generator to identify these types even when running on older .NET frameworks (netstandard2.0).GetEffectiveTypeto mapXmlTypeCode.DateandXmlTypeCode.Timeto these internal types whenUseDateOnlyis true.CreateTypeReferenceto map the internal types toSystem.DateOnlyandSystem.TimeOnlystring references in the generated code.3.
TypeModel.csUpdated
GetDefaultValueForto handle standard default value parsers forDateOnlyandTimeOnly(using.Parse()).4.
Program.csAdded a new command line option
--dateOnly(or-do) to the CLI.Verification
I added a new test file
XmlSchemaClassGenerator.Tests/DateOnlyTimeOnlyTests.csand confirmed that:-dois enabled,xs:dategeneratespublic System.DateOnly PropertyName.-dois enabled,xs:timegeneratespublic System.TimeOnly PropertyName.DateTime.xs:dateandxs:timeare correctly parsed usingSystem.DateOnly.ParseandSystem.TimeOnly.Parse.xs:timeandxs:datecorrectly map toDateTimeOffsetwhenUseDateOnlyis false andDateTimeWithTimeZoneis true.Usage
To use the new feature via CLI:
To use via code:
(implemented by Gemini Pro 3)
This should fix #524 and #310