Replies: 1 comment
-
|
Thanks for taking the time to write up this clear discussion of the issue and possible solutions! Having dealt with I'm not sure about which solution makes the most sense though. I'm curious to hear what other people think. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the specification represents both
datetime(without offset) anddatetime with offsetusing the same type,datetime. As a result, the default format for this type is not unique, leading to ambiguity and practical challenges when handling such values programmatically.We propose (one of the alternatives):
datetime with offset, e.g.,datetimeoffset, to differentiate it fromdatetime(without offset).useOffset: true/false) to explicitly indicate whether an offset is expected for adatetimefield.datetimeformat to only allow%Y-%m-%dT%H:%M:%S(without timezone information). If a timezone or offset is needed, the format must explicitly indicate it, and consumers are then expected to use adatetime with offsettype.Context of
datetimeanddatetime with offsetIn .NET, the distinction between
DateTimeandDateTimeOffsetis critical:DateTime:DateTimeOffset:By conflating these two representations into a single
datetimetype in the specification, the following issues arise:1. Safe Typing is Obstructed
Currently, it is impossible to determine whether a
DateTimeorDateTimeOffsetshould be used in .NET based solely on thetypeproperty in the specification. This leads to:2. Ambiguity in Parsing and Default Formats
The specification allows for a
datetimevalue to optionally include an offset (e.g.,2025-01-07T15:30:00+02:00) or not (e.g.,2025-01-07T15:30:00). When a format is explicitly provided, it is sometimes possible to infer whether a timezone or offset is expected. However:datetimeanddatetimeoffset.3. Parsing at Runtime is Problematic
When reading or parsing datetime values, the current approach assumes producers can mix both
datetimeanddatetimeoffsetvalues within the same field. This introduces several issues:datetimeanddatetimeoffsetvalues in the same field is inconvenient to handle and prone to errors, as it burdens the consumer with reconciling inconsistent representations.Proposed Benefits
Clear Type Distinction:
datetimeoffsettype or auseOffsetproperty would enable producers and consumers to unambiguously identify the intended representation and enforce type safety at both design time and runtime.Improved Parsing Logic:
datetimeanddatetimeoffset, parsing logic becomes straightforward, eliminating the need for guessing based on the value format.Consistency Across Producers and Consumers:
datetimeformat to%Y-%m-%dT%H:%M:%Sensures clarity. Consumers can then infer that if a format includes timezone information (e.g.,%Y-%m-%dT%H:%M:%S%z), they should expect adatetime with offsettype. This approach avoids mixing representations within the same field and enforces clear expectations for data handling.Implementation Suggestions
Introduce
datetimeoffsetas a New Type:datetimevalues with an explicit offset.YYYY-MM-DDTHH:mm:ss±hh:mm).Add an Explicit
useOffsetProperty:datetimetype with a property, e.g.,useOffset, to clarify whether an offset is required for the field.Restrict Default
datetimeFormat:%Y-%m-%dT%H:%M:%Sas the default format fordatetime.datetime with offset. Consumers should rely on the format to determine the expected type and handle it accordingly.Conclusion
By adopting this proposal, the specification would align better with robust, type-safe handling of datetime values in programming environments like .NET. This change would eliminate ambiguities, improve parsing reliability, and ensure consistent handling of datetime values across producers and consumers.
Beta Was this translation helpful? Give feedback.
All reactions