All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart-dio.local_date_serializer.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>header}}
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:time_machine/time_machine.dart';

class OffsetDateSerializer implements PrimitiveSerializer {

  const OffsetDateSerializer();

  @override
  Iterable get types => BuiltList([OffsetDate]);

  @override
  String get wireName => 'OffsetDate';

  @override
  OffsetDate deserialize(Serializers serializers, Object serialized,
      {FullType specifiedType = FullType.unspecified}) {
    final local = LocalDate.dateTime(DateTime.parse(serialized as String));
    return OffsetDate(local, Offset(0));
  }

  @override
  Object serialize(Serializers serializers, OffsetDate offsetDate,
      {FullType specifiedType = FullType.unspecified}) {
    return offsetDate.toString('yyyy-MM-dd');
  }
}

class OffsetDateTimeSerializer implements PrimitiveSerializer {

  const OffsetDateTimeSerializer();

  @override
  Iterable get types => BuiltList([OffsetDateTime]);

  @override
  String get wireName => 'OffsetDateTime';

  @override
  OffsetDateTime deserialize(Serializers serializers, Object serialized,
      {FullType specifiedType = FullType.unspecified}) {
    final local = LocalDateTime.dateTime(DateTime.parse(serialized as String));
    return OffsetDateTime(local, Offset(0));
  }

  @override
  Object serialize(Serializers serializers, OffsetDateTime offsetDateTime,
      {FullType specifiedType = FullType.unspecified}) {
    return offsetDateTime.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy