SE-0329: Clock, Instant, Date, and Duration

Are you talking about Codable or JSON? It may indeed be possible for a JSON implementation to encode the time as an arbitrary-precision floating-point string and be lossless (depending on what JSON allows), but this is not true for encoders or decoders in general.

Also, these kinds of type-specific hacks do not always work in generic contexts. For example, Foundation's URL has a similar issue: URL fails to decode when it is a generic argument and `GenericArgument(from: decoder)` is used

So even if JSON allows it, it's a fragile solution.

5 Likes