ethiopianToGregorianString static method
Convert Ethiopian date string to Gregorian date string Input format: "day/month/year" or "day-month-year" Returns: Formatted Gregorian date string
Implementation
static String ethiopianToGregorianString(String ethiopianDateStr, {String separator = '/'}) {
try {
// Validate format first
if (!_isValidDateFormat(ethiopianDateStr)) {
throw Exception('Invalid date format. Use day/month/year or day-month-year with proper separators');
}
// Support both / and - separators
final parts = ethiopianDateStr.contains('/')
? ethiopianDateStr.split('/')
: ethiopianDateStr.split('-');
if (parts.length != 3) {
throw Exception('Invalid date format. Use day/month/year or day-month-year');
}
final day = int.parse(parts[0]);
final month = int.parse(parts[1]);
final year = int.parse(parts[2]);
// Validate Ethiopian date ranges
if (month < 1 || month > 13) {
throw Exception('Ethiopian month must be between 1 and 13');
}
if (month == 13 && day > 6) {
throw Exception('Pagume month can only have up to 6 days');
}
if (day < 1 || day > 30) {
throw Exception('Day must be between 1 and 30');
}
final result = ethiopianToGregorian(year: year, month: month, day: day);
return '${result['day']}$separator${result['month']}$separator${result['year']}';
} catch (e) {
throw Exception('Date conversion failed: $e');
}
}