long DaysUpToPersianYear(int PersianYear) {
long NumDays; // number of absolute days
int NumCycles; // number of 33 year cycles
int NumYearsLeft; // number of years into 33 year cycle
//
// Compute the number of 33 years cycles.
//
NumCycles = (PersianYear - 1) / DateCycle;
//
// Compute the number of years left. This is the number of years
// into the 33 year cycle for the given year.
//
NumYearsLeft = (PersianYear-1) % DateCycle;
//
// Compute the number of absolute days up to the given year.
//
NumDays = NumCycles * DaysPerCycle + GregorianOffset;
while (NumYearsLeft > 0) {
NumDays += 365;
// Common year is 365 days, and leap year is 366 days.
if(IsLeapYear(NumYearsLeft, CurrentEra)) {
NumDays++;
}
NumYearsLeft--;
}
//
// Return the number of absolute days.
//
return (NumDays);
}