fromSerializedDateTime function

dynamic fromSerializedDateTime (dynamic serialized)

Converts the serialized integer or ISO formatted String into a Datetime value

example: fromSerializedDateTime(1533343671) // returns a DateTime object for 2018-08-04T00:47:51-0000 fromSerializedDateTime('2002-02-27T14:00:00-0500') // returns DateTime Object form 2002-02-27T14:00:00-0500

Implementation

fromSerializedDateTime(serialized) {
  return serialized is num
      ? new DateTime.fromMillisecondsSinceEpoch(serialized)
      : serialized is String
        ? DateTime.parse(serialized)
        : serialized;
}