2021-01-17 15:08:32 +01:00
|
|
|
import 'package:built_value/serializer.dart';
|
|
|
|
|
|
|
|
class DateTimeSerializer implements PrimitiveSerializer<DateTime> {
|
|
|
|
@override
|
|
|
|
DateTime deserialize(
|
|
|
|
Serializers serializers,
|
|
|
|
Object serialized, {
|
|
|
|
FullType specifiedType = FullType.unspecified,
|
|
|
|
}) {
|
|
|
|
assert(serialized is String,
|
|
|
|
"DateTimeSerializer expected 'String' but got ${serialized.runtimeType}");
|
2021-05-16 09:16:35 +02:00
|
|
|
return DateTime.parse(serialized as String);
|
2021-01-17 15:08:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Object serialize(
|
|
|
|
Serializers serializers,
|
|
|
|
DateTime dt, {
|
|
|
|
FullType specifiedType = FullType.unspecified,
|
|
|
|
}) =>
|
|
|
|
dt.toString();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Iterable<Type> get types => [DateTime];
|
|
|
|
|
|
|
|
@override
|
2022-09-18 19:02:57 +02:00
|
|
|
String get wireName => 'DateTime';
|
2021-01-17 15:08:32 +01:00
|
|
|
}
|