Implement some sort of basic rss scraping
This commit is contained in:
47
lib/utils.dart
Normal file
47
lib/utils.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
DateTime parseRfc822Date(String date) {
|
||||
// Split the date string into components
|
||||
final parts = date.split(' ');
|
||||
|
||||
// Map the month names to their corresponding numbers
|
||||
const monthMap = {
|
||||
'Jan': 1,
|
||||
'Feb': 2,
|
||||
'Mar': 3,
|
||||
'Apr': 4,
|
||||
'May': 5,
|
||||
'Jun': 6,
|
||||
'Jul': 7,
|
||||
'Aug': 8,
|
||||
'Sep': 9,
|
||||
'Oct': 10,
|
||||
'Nov': 11,
|
||||
'Dec': 12,
|
||||
};
|
||||
|
||||
// Extract the components
|
||||
final day = int.parse(parts[1]);
|
||||
final month = monthMap[parts[2]]!;
|
||||
final year = int.parse(parts[3]);
|
||||
final timeParts = parts[4].split(':');
|
||||
final hour = int.parse(timeParts[0]);
|
||||
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