File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,24 @@ class DateTimeISO8601NullableConverter
2424 }
2525}
2626
27+ /// Converts [DateTime] ? to and from ISO 8601 [String]
28+ class DateTimeISO8601Converter extends JsonConverter <DateTime , String > {
29+ /// Creates a new instance of [DateTimeISO8601Converter] .
30+ const DateTimeISO8601Converter ();
31+
32+ @override
33+ DateTime fromJson (String json) => deserialize (json);
34+
35+ @override
36+ String toJson (DateTime object) => serialize (object);
37+
38+ /// Serializes [DateTime] to [int] .
39+ static String serialize (DateTime object) => object.toIso8601String ();
40+
41+ /// Deserializes [int] to [DateTime] .
42+ static DateTime deserialize (String json) => DateTime .parse (json);
43+ }
44+
2745/// Top level converter for serializing [DateTime] to [millisecondsSinceEpoch] .
2846class DateTimeConverter extends JsonConverter <DateTime , int ?> {
2947 /// Creates a new instance of [DateTimeConverter] .
You can’t perform that action at this time.
0 commit comments