https://github.com/albert221/rfc_3339_date_time_serializer
RFC 3339 DateTime serializer for built_value.
https://github.com/albert221/rfc_3339_date_time_serializer
built-value dart datetime encoding
Last synced: 9 months ago
JSON representation
RFC 3339 DateTime serializer for built_value.
- Host: GitHub
- URL: https://github.com/albert221/rfc_3339_date_time_serializer
- Owner: Albert221
- License: mit
- Created: 2019-11-20T13:14:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-21T01:44:18.000Z (over 6 years ago)
- Last Synced: 2025-03-25T19:41:49.889Z (over 1 year ago)
- Topics: built-value, dart, datetime, encoding
- Language: Dart
- Homepage: https://pub.dev/packages/rfc_3339_date_time_serializer
- Size: 9.77 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rfc_3339_date_time_serializer
An `RFC3339DateTimeSerializer` serializer class for [built_value], created to address [the issue][issue] about Dart's `DateTime.parse` not working with RFC 3339.
## Why is this package needed?
ISO 8601 has a character limit for _time-secfrac_ part equal to 6. RFC 3339 does not have that limit. Thanks to this, datetimes introducing more than 6 characters in _time-secfrac_ are invalid for `DateTime.parse`, because it works only with ISO 8601.
For example, Go's `encoding/json` serializes dates with 7 _time-secfrac_ characters.
## Usage
In your `serializers.dart`:
```dart
import 'rfc_3339_date_time_serializer/rfc_3339_date_time_serializer.dart';
@SerializersFor(const [/* (...) */])
final Serializers modelsSerializers = (_$modelsSerializers.toBuilder()
..addPlugin(StandardJsonPlugin())
..add(RFC3339DateTimeSerializer())) // this is the line you need to add
.build();
```
[built_value]: https://pub.dev/packages/built_value
[issue]: https://github.com/dart-lang/sdk/issues/24205