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
-
Currently, the specification represents both
datetime
(without offset) anddatetime with offset
using 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 adatetime
field.datetime
format 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 offset
type.Context of
datetime
anddatetime with offset
In .NET, the distinction between
DateTime
andDateTimeOffset
is critical:DateTime
:DateTimeOffset
:By conflating these two representations into a single
datetime
type in the specification, the following issues arise:1. Safe Typing is Obstructed
Currently, it is impossible to determine whether a
DateTime
orDateTimeOffset
should be used in .NET based solely on thetype
property in the specification. This leads to:2. Ambiguity in Parsing and Default Formats
The specification allows for a
datetime
value 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:datetime
anddatetimeoffset
.3. Parsing at Runtime is Problematic
When reading or parsing datetime values, the current approach assumes producers can mix both
datetime
anddatetimeoffset
values within the same field. This introduces several issues:datetime
anddatetimeoffset
values 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:
datetimeoffset
type or auseOffset
property would enable producers and consumers to unambiguously identify the intended representation and enforce type safety at both design time and runtime.Improved Parsing Logic:
datetime
anddatetimeoffset
, parsing logic becomes straightforward, eliminating the need for guessing based on the value format.Consistency Across Producers and Consumers:
datetime
format to%Y-%m-%dT%H:%M:%S
ensures 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 offset
type. This approach avoids mixing representations within the same field and enforces clear expectations for data handling.Implementation Suggestions
Introduce
datetimeoffset
as a New Type:datetime
values with an explicit offset.YYYY-MM-DDTHH:mm:ss±hh:mm
).Add an Explicit
useOffset
Property:datetime
type with a property, e.g.,useOffset
, to clarify whether an offset is required for the field.Restrict Default
datetime
Format:%Y-%m-%dT%H:%M:%S
as 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