toTimeMillisUTCValue function
Converts the data to a DateTime value.
The returned time is ensured to be in the UTC time zone.
If the data is already a DateTime then it is returned (UTC ensured).
If the data is int then
DateTime.fromMillisecondsSinceEpoch is used in parsing.
If the data is String then it is parsed to int and
DateTime.fromMillisecondsSinceEpoch is used in parsing.
Otherwise a FormatException is thrown.
Implementation
DateTime toTimeMillisUTCValue(Object? data, {bool isUTCSource = false}) {
if (data == null) throw const NullValueException();
if (data is DateTime) {
return data.toUtc();
} else if (data is int) {
return DateTime.fromMillisecondsSinceEpoch(data, isUtc: isUTCSource)
.toUtc();
} else if (data is String) {
return DateTime.fromMillisecondsSinceEpoch(
int.parse(data),
isUtc: isUTCSource,
).toUtc();
}
throw ConversionException(target: DateTime, data: data);
}