google / built_value.dart

Immutable value types, enum classes, and serialization.
https://pub.dev/packages/built_value
BSD 3-Clause "New" or "Revised" License
861 stars 184 forks source link

Support milliseconds with ISO8601DurationSerializer #1231

Open solwey-wes opened 1 year ago

solwey-wes commented 1 year ago

Per https://stackoverflow.com/questions/27058529/iso-8601-duration-with-milliseconds

Use case - EdgeDB outputs ISO 8601 duration values with decimal values for millisecond precision (and doesn't currently have a DSL function to convert to milliseconds since epoch). I can address with them or write something custom but I figure an update to the bundled serializer would be the best solution :)

'PT9.977S' https://www.edgedb.com/docs/stdlib/datetime#function::std::duration_get

dave26199 commented 1 year ago

Changing a serializer is a breaking change so it would have to be optional; I suggest you start with something custom and we can later add it here if there is more interest. Thanks :)

solwey-wes commented 1 year ago

@dave26199 Oki will do. I was gonna ask how this would be breaking ‘cause de/serialization of existing values would function exactly as before, but I think I get it…consumers might be implicitly casting to seconds and relying on systems that assume that exact fidelity without decimals/commas. But if so, it seems those systems function in spite of ISO spec…which exists to minimize these compatibility issues. A strange loop 👀.

Either way I seem to be the only one who has bumped into this so happy to chip away at it and submit a PR so it’s here if more come along :)

dave26199 commented 1 year ago

It's more the serialization side I was worried about, writing a different string can definitely be breaking :) but different deserialization is also a behavior change even if it seems more correct.

Sounds good, thanks.