Year, Month, and Day parameters describe an un-representable DateTime. Error for one date converting only

405 views Asked by At

My code is working fine for all date except one that is 2019,10,28. i do not know why i am getting error to convert this date to umulqura or hijri.

        UmAlQuraCalendar HijriCalender = new UmAlQuraCalendar();
        var date = new DateTime (2019,10,28);
        var check = ConvertToHijri(date);

    public static DateTime ConvertToHijri(this DateTime value)
    {
        try
        {
        if (value.Year > 1500)
        {
                GregorianCalendar Gre = new GregorianCalendar();
                UmAlQuraCalendar HijriCalender = new UmAlQuraCalendar();

  DateTime gDate = new DateTime(value.Year, value.Month, value.Day, Gre);
                var year = HijriCalender.GetYear(gDate);
                var month = HijriCalender.GetMonth(gDate);
                var day = HijriCalender.GetDayOfMonth(gDate);
                var test = new DateTime(year, month, day);
                return test;
            }

        }
        catch (Exception ex)
        {

            Console.WriteLine(ex.Message);
        }
        return value;
    }

this code works very fine to convert dates from Georgian to Hijri or Umulqura but only specific date 2019,10,28 is not converting.

0

There are 0 answers