ConvertStartDateToUnspecifiedDateTime method
Converts xs:dateTime String with either "Z", "-00:00" bias, or "" suffixes to
unspecified StartDate value ignoring the suffix.
The String value to parse.
Implementation
DateTime? ConvertStartDateToUnspecifiedDateTime(String? value) {
if (StringUtils.IsNullOrEmpty(value)) {
return null;
} else {
// Keep only the date part (yyyy-MM-dd) and ignore any "Z" / "+hh:mm"
// suffix, like DateTimeOffset.Parse(value).Date does in C#. Dart has no
// "unspecified" kind; a UTC TZDateTime keeps the components unchanged.
final match = RegExp(r'^(\d{4,})-(\d{2})-(\d{2})').firstMatch(value!);
if (match == null) {
throw FormatException("Invalid xs:date value", value);
}
return datetime.TZDateTime.utc(
int.parse(match.group(1)!),
int.parse(match.group(2)!),
int.parse(match.group(3)!),
);
}
// if (StringUtils.IsNullOrEmpty(value))
// {
// return null;
// }
// else
// {
// DateTimeOffset dateTimeOffset = DateTimeOffset.Parse(value, CultureInfo.InvariantCulture);
//
// // Return only the date part with the kind==Unspecified.
// return dateTimeOffset.Date;
// }
}