serializedCosmicValue function
Returns a sanitized date string from the given value
.
Converts different representation of date to a string representation.
Implementation
String? serializedCosmicValue(Object? value) {
return switch (value) {
Timestamp timestamp => timestamp.toDate().toUtc().toIso8601String(),
DateTime dateTime => dateTime.toUtc().toIso8601String(),
String string => DateTime.tryParse(string)?.toUtc().toIso8601String(),
int millisecondsSinceEpoch =>
DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch)
.toUtc()
.toIso8601String(),
_ => null,
};
}