Repository navigation
Conversation
With :utc and :zoned, a date-time with no offset decodes as UTC. Some
producers write a wall clock with no offset, which names no instant.
The :as_written mode types the fields as
Union{Dates.DateTime,TimeZones.ZonedDateTime}. A value with no offset
decodes to a DateTime and encodes without an offset. A value with Z or
an offset decodes to a ZonedDateTime with that offset and encodes with
it. The generated models encode through _encode_as_written, so the
:utc behavior of _encode(::DateTime) does not change.
Contributor
Author
|
Closed. A new PR will add support for the registry format |
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
This PR adds a third value for the
datetimeoption,:as_written. With:utcand:zoned, a date-time with no offset decodes as UTC. Some producers write a wallclock with no offset, and that value names no instant. Reading it as UTC gives a
wrong instant without an error.
With
datetime = :as_written:2024-01-01T00:00:00Dates.DateTime2024-01-01T00:00:00.0002024-01-01T00:00:00ZZonedDateTime, UTC2024-01-01T00:00:00.000+00:002024-01-01T02:00:00+02:00ZonedDateTime,FixedTimeZone+02:002024-01-01T02:00:00.000+02:00The field type is
Union{Dates.DateTime,TimeZones.ZonedDateTime}. The generatedmodule has
using TimeZones, as with:zoned.Changes
src/planning.jl: the option check accepts:as_written. The field type comesfrom methods on
Val(datetime).src/runtime.jl:_decode_unionsends aDateTime/ZonedDateTimeunion to_decode_as_written, after thenothingcheck. Trial decoding would convert anoffset to UTC.
_encode_as_written(::Dates.DateTime)writes no offset, and recursesinto vectors and dicts.
ext/OpenAPITimeZonesExt.jl:_decode_as_writtenuses the same regex, millisecondtruncation and
DecodeErrormessages as the other decoders. It dispatches on theZand offset captures._encode_as_written(::ZonedDateTime)uses_encode.src/client.jl,src/servergen.jl:_emit_modeltakes anencodekeyword. Under:as_written, model fields, aliases, union values and additional properties encodethrough
_encode_as_written._encode(::Dates.DateTime)does not change, so:utcoutput still has
Z.docs/src/clients.md,docs/src/models.md: the new mode.Limits
A date-time sent directly as a query, header or cookie parameter, or as a top-level
request body, still goes through
_encode. Only model values use_encode_as_written.Tests
The new test set in
test/runtime.jlcovers:Z,+02:00,-07:00, fractional seconds, and invalidtext;
:utcand:zonedoutput does not change.julia --project=. -e 'using Pkg; Pkg.test()': all test sets pass (1467 passes, 0failures, 0 errors).
generated runtime units: 418 of 418.