void ConvertGregorianToHijri(DateTime time, ref int HijriYear, ref int HijriMonth, ref int HijriDay)
{
int index, b, DaysPerThisMonth;
double nDays;
TimeSpan ts;
int yh1=0, mh1=0, dh1=0;
BCLDebug.Assert((time.Ticks >= minDate.Ticks) && (time.Ticks <= maxDate.Ticks), "Gregorian date is out of range.");
// Find the index where we should start our search by quessing the Hijri year that we will be in HijriYearInfo.
// A Hijri year is 354 or 355 days. Use 355 days so that we will search from a lower index.
index = (int)((time.Ticks - minDate.Ticks) / Calendar.TicksPerDay) / 355;
do
{
} while (time.CompareTo(HijriYearInfo[++index].GregorianDate)>0); //while greater
if (time.CompareTo(HijriYearInfo[index].GregorianDate) != 0)
{
index--;
}
ts = time.Subtract(HijriYearInfo[index].GregorianDate);
yh1 = index + MinCalendarYear;
mh1 = 1;
dh1 = 1;
nDays = ts.TotalDays;
b = HijriYearInfo[index].HijriMonthsLengthFlags;
DaysPerThisMonth = 29 + (b&1);
while (nDays >= DaysPerThisMonth)
{
nDays -= DaysPerThisMonth;
b = b >> 1;
DaysPerThisMonth = 29 + (b&1);
mh1++;
}
dh1 += (int)nDays;
HijriDay = dh1;
HijriMonth = mh1;
HijriYear = yh1;
}