ethiopianToGregorianDateConvertor function
contains constant functions for our library
Implementation
ethiopianToGregorianDateConvertor(
int day, ETC ethiopianCalender, bool forCalender) {
/// this function will be called when we want to display
/// gregorian calender with ethiopian calender
/// it takes ethiopian calender and date as a param and returns gregorian calender
EtDatetime ethiopianDateTime = EtDatetime(
year: ethiopianCalender.year, month: ethiopianCalender.month, day: day);
// Use UTC to avoid timezone-related off-by-one errors
DateTime gregorianCalender =
DateTime.fromMillisecondsSinceEpoch(ethiopianDateTime.moment, isUtc: true);
String result = gregorianCalender
.toString()
.substring(0, gregorianCalender.toString().indexOf(' '));
var gregorianConvertedDate = result.split('-');
return forCalender
? gregorianConvertedDate[2].toString().replaceAll(RegExp(r'^0+(?=.)'), '')
: result;
}