Improve error handling and parsing a little
This commit is contained in:
@@ -27,21 +27,8 @@ DateTime parseRfc822Date(String date) {
|
||||
final minute = int.parse(timeParts[1]);
|
||||
final second = int.parse(timeParts[2]);
|
||||
|
||||
// Handle the timezone offset
|
||||
final timezone = parts[5];
|
||||
final isNegative = timezone.startsWith('-');
|
||||
final tzHours = int.parse(timezone.substring(1, 3));
|
||||
final tzMinutes = int.parse(timezone.substring(3, 5));
|
||||
|
||||
// Create the DateTime object
|
||||
DateTime dateTime = DateTime(year, month, day, hour, minute, second);
|
||||
|
||||
// Adjust for timezone
|
||||
if (isNegative) {
|
||||
dateTime = dateTime.subtract(Duration(hours: tzHours, minutes: tzMinutes));
|
||||
} else {
|
||||
dateTime = dateTime.add(Duration(hours: tzHours, minutes: tzMinutes));
|
||||
}
|
||||
|
||||
return dateTime;
|
||||
}
|
||||
|
Reference in New Issue
Block a user