toTimeUTCValue 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 String then DateTime.parse is used in parsing. Or if
sourceFormat
(and optionally isUTCSource
too) is given, then that format
instance is used in parsing.
Otherwise a FormatException is thrown.
Implementation
DateTime toTimeUTCValue(
Object? data, {
DateFormat? sourceFormat,
bool isUTCSource = false,
}) {
if (data == null) throw const NullValueException();
if (data is DateTime) {
return data.toUtc();
} else if (data is String) {
if (sourceFormat == null) {
// "The function parses a subset of ISO 8601 which includes the subset
// accepted by RFC 3339."
return DateTime.parse(data).toUtc();
} else {
return sourceFormat.parse(data, isUTCSource).toUtc();
}
}
throw ConversionException(target: DateTime, data: data);
}