google / google/built_value.dart
Serialization of Local DateTime
- Dominant language
- Dart
- Stars
- 886
- Forks
- 195
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 4
Description
Serialization/deserialization for ISO-8601 DateTime was added in #111.
When first using the library, I was a little surprised to find out that a var created from `new DateTime.now()` didn't serialize. While I agree serializing something that isn't UTC doesn't make sense (in *most* cases), why not call `.toUtc()` in the serializer?
Advantages:
- Less thought needed for the API user. (I don't need to remember to call `.toUtc()` every time I create a DateTime.)
- Avoids a runtime exception. (It's nice when APIs catch incorrect usage at compile time.)
Disadvantages:
- It might be considered a breaking change.
- Some API users may be caught off guard, *expecting* a local DateTime to exclude the timezone or to include their local timezone.
Perhaps making the serializer configurable could accomplish the best balance:
```dart
final ser = new Iso8601DateTimeSerializer(); // throws exception on non-UTC
// These would return a new instance
ser.withLocalDateTimeInUtc(); // uses .toUtc().toIso8601String()
ser.withNoZoneForLocalDateTime(); // uses .toIso8601String()
```
Contributor guide
Assessment
This issue has not been assessed yet.