parseRFC3339DateTime static method
Parse a datetime string in RFC3339 format and return a corresponding DateTime object. The method checks if the input string contains a timezone offset. If it does, it splits the string into date and offset parts, parses the date part, and returns it. If there's no offset, it parses the input string as a UTC time.
Implementation
static DateTime parseRFC3339DateTime(String dateTimeString) {
// Check if the input string contains a timezone offset
if (dateTimeString.contains('+')) {
// Split the string into the date and offset parts
final parts = dateTimeString.split('+');
if (parts.length != 2) {
throw CborException("Invalid RFC3339 format: $dateTimeString");
}
final datePart = DateTime.parse(parts[0]);
return datePart;
} else {
// Parse the input string as a UTC time
return DateTime.parse(dateTimeString).toUtc();
}
}