public static GregorianDateTime CalcTithiEndEx(GregorianDateTime vcStart, int GYear, int nMasa, int nPaksa, int nTithi, GCEarthData earth, out GregorianDateTime endTithi) { int i, gy, nType; GregorianDateTime d = new GregorianDateTime(); GCAstroData day = new GCAstroData(); int tithi; int counter; GregorianDateTime start = new GregorianDateTime(), end = new GregorianDateTime(); // SUNDATA sun; // MOONDATA moon; double sunrise; start.shour = -1.0; end.shour = -1.0; start.day = start.month = start.year = -1; end.day = end.month = end.year = -1; /* d = GetFirstDayOfYear(earth, nGYear + 1486); * d.shour = 0.5; * d.TimeZone = earth.tzone; */ d.Set(vcStart); i = 0; do { d.AddDays(13); day.DayCalc(d, earth); day.Masa = day.MasaCalc(d, earth); gy = day.GaurabdaYear; i++; }while (((day.sunRise.Paksa != nPaksa) || (day.Masa != nMasa)) && (i <= 30)); if (i >= 30) { d.year = d.month = d.day = -1; endTithi = null; return(d); } // we found masa and paksa // now we have to find tithi tithi = nTithi + nPaksa * 15; if (day.sunRise.Tithi == tithi) { // loc1 // find tithi juncts in this day and according to that times, // look in previous or next day for end and start of this tithi nType = 1; } else { if (day.sunRise.Tithi < tithi) { // do increment of date until nTithi == tithi // but if nTithi > tithi // then do decrement of date counter = 0; while (counter < 30) { d.NextDay(); day.DayCalc(d, earth); if (day.sunRise.Tithi == tithi) { goto cont_2; } if ((day.sunRise.Tithi < tithi) && (day.sunRise.Paksa != nPaksa)) { d.PreviousDay(); goto cont_2; } if (day.sunRise.Tithi > tithi) { d.PreviousDay(); goto cont_2; } counter++; } // somewhere is error d.year = d.month = d.day = 0; nType = 0; } else { // do decrement of date until nTithi <= tithi counter = 0; while (counter < 30) { d.PreviousDay(); day.DayCalc(d, earth); if (day.sunRise.Tithi == tithi) { goto cont_2; } if ((day.sunRise.Tithi > tithi) && (day.sunRise.Paksa != nPaksa)) { goto cont_2; } if (day.sunRise.Tithi < tithi) { goto cont_2; } counter++; } // somewhere is error d.year = d.month = d.day = 0; nType = 0; } cont_2: if (day.sunRise.Tithi == tithi) { // do the same as in loc1 nType = 1; } else { // nTithi != tithi and nTithi < tithi // but on next day is nTithi > tithi // that means we will find start and the end of tithi // in this very day or on next day before sunrise nType = 2; } } // now we know the type of day-accurancy // nType = 0 means, that we dont found a day // nType = 1 means, we find day, when tithi was present at sunrise // nType = 2 means, we found day, when tithi started after sunrise // but ended before next sunrise // sunrise = day.sunRise.TotalDays; endTithi = new GregorianDateTime(); if (nType == 1) { GregorianDateTime d1, d2; d.shour = sunrise; GCTithi.GetPrevTithiStart(earth, d, out d1); //d = d1; //d.shour += 0.02; GCTithi.GetNextTithiStart(earth, d, out d2); endTithi.Set(d2); return(d1); } else if (nType == 2) { GregorianDateTime d1, d2; d.shour = sunrise; GCTithi.GetNextTithiStart(earth, d, out d1); d.Set(d1); d.shour += 0.1; d.NormalizeValues(); GCTithi.GetNextTithiStart(earth, d, out d2); endTithi.Set(d2); return(d1); } // if nType == 0, then this algoritmus has some failure if (nType == 0) { d.year = 0; d.month = 0; d.day = 0; d.shour = 0.0; endTithi.Set(d); } else { d.Set(start); endTithi.Set(end); } return(d); }
/*********************************************************************/ /* Calculates Date of given Tithi */ /*********************************************************************/ public static GregorianDateTime CalcTithiDate(int nGYear, int nMasa, int nPaksa, int nTithi, GCEarthData earth) { int i = 0, gy = 0; GregorianDateTime d = new GregorianDateTime(); GCAstroData day = new GCAstroData(); int tithi = 0; int counter = 0; UInt32 tmp = 0; if (nGYear >= 464 && nGYear < 572) { tmp = GCAstroData.gGaurBeg[(nGYear - 464) * 26 + nMasa * 2 + nPaksa]; d.month = Convert.ToInt32((tmp & 0x3e0) >> 5); d.day = Convert.ToInt32(tmp & 0x1f); d.year = Convert.ToInt32(tmp & 0xfffc00) >> 10; d.TimezoneHours = earth.OffsetUtcHours; d.NextDay(); day.DayCalc(d, earth); day.Masa = day.MasaCalc(d, earth); gy = day.GaurabdaYear; } else { //d = GetFirstDayOfYear(earth, nGYear + 1486); d.day = 15; d.month = 2 + nMasa; d.year = nGYear + 1486; if (d.month > 12) { d.month -= 12; d.year++; } d.shour = 0.5; d.TimezoneHours = earth.OffsetUtcHours; i = 0; do { d.AddDays(13); day.DayCalc(d, earth); day.Masa = day.MasaCalc(d, earth); gy = day.GaurabdaYear; i++; }while (((day.sunRise.Paksa != nPaksa) || (day.Masa != nMasa)) && (i <= 30)); } if (i >= 30) { d.year = d.month = d.day = -1; return(d); } // we found masa and paksa // now we have to find tithi tithi = nTithi + nPaksa * 15; if (day.sunRise.Tithi == tithi) { // loc1 // find tithi juncts in this day and according to that times, // look in previous or next day for end and start of this tithi d.PreviousDay(); day.DayCalc(d, earth); if ((day.sunRise.Tithi > tithi) && (day.sunRise.Paksa != nPaksa)) { d.NextDay(); } return(d); } if (day.sunRise.Tithi < tithi) { // do increment of date until nTithi == tithi // but if nTithi > tithi // then do decrement of date counter = 0; while (counter < 16) { d.NextDay(); day.DayCalc(d, earth); if (day.sunRise.Tithi == tithi) { return(d); } if ((day.sunRise.Tithi < tithi) && (day.sunRise.Paksa != nPaksa)) { return(d); } if (day.sunRise.Tithi > tithi) { return(d); } counter++; } // somewhere is error d.year = d.month = d.day = 0; return(d); } else { // do decrement of date until nTithi <= tithi counter = 0; while (counter < 16) { d.PreviousDay(); day.DayCalc(d, earth); if (day.sunRise.Tithi == tithi) { return(d); } if ((day.sunRise.Tithi > tithi) && (day.sunRise.Paksa != nPaksa)) { d.NextDay(); return(d); } if (day.sunRise.Tithi < tithi) { d.NextDay(); return(d); } counter++; } // somewhere is error d.year = d.month = d.day = 0; return(d); } // now we know the type of day-accurancy // nType = 0 means, that we dont found a day // nType = 1 means, we find day, when tithi was present at sunrise // nType = 2 means, we found day, when tithi started after sunrise // but ended before next sunrise // return(d); }
public static bool CalcEndDate(GCEarthData m_earth, GregorianDateTime vcStart, out GregorianDateTime vcEnd, PeriodUnit nType, int nCount) { if (m_earth == null || vcStart == null) { vcEnd = null; return(false); } GaurabdaDate vaStart = new GaurabdaDate(); VCTIMEtoVATIME(vcStart, out vaStart, m_earth); vcEnd = new GregorianDateTime(); GaurabdaDate vaEnd = new GaurabdaDate(); if (nCount > LimitForPeriodUnit(nType)) { nCount = LimitForPeriodUnit(nType); } switch (nType) { case PeriodUnit.Days: vcEnd.Set(vcStart); vcEnd.AddDays(nCount); VCTIMEtoVATIME(vcEnd, out vaEnd, m_earth); break; case PeriodUnit.Weeks: vcEnd.Set(vcStart); vcEnd.AddDays(nCount * 7); VCTIMEtoVATIME(vcEnd, out vaEnd, m_earth); break; case PeriodUnit.Months: vcEnd.Set(vcStart); vcEnd.month += nCount; while (vcEnd.month > 12) { vcEnd.year++; vcEnd.month -= 12; } VCTIMEtoVATIME(vcEnd, out vaEnd, m_earth); break; case PeriodUnit.Years: vcEnd.Set(vcStart); vcEnd.year += nCount; VCTIMEtoVATIME(vcEnd, out vaEnd, m_earth); break; case PeriodUnit.Tithis: vaEnd.Set(vaStart); vaEnd.tithi += nCount; while (vaEnd.tithi >= 30) { vaEnd.tithi -= 30; vaEnd.masa++; } while (vaEnd.masa >= 12) { vaEnd.masa -= 12; vaEnd.gyear++; } VATIMEtoVCTIME(vaEnd, out vcEnd, m_earth); break; case PeriodUnit.Masas: vaEnd.Set(vaStart); vaEnd.masa = MasaToComboMasa(vaEnd.masa); if (vaEnd.masa == (int)MasaId.ADHIKA_MASA) { vcEnd.Set(vcStart); vcEnd.month += nCount; while (vcEnd.month > 12) { vcEnd.year++; vcEnd.month -= 12; } VCTIMEtoVATIME(vcEnd, out vaEnd, m_earth); vaEnd.tithi = vaStart.tithi; VATIMEtoVCTIME(vaEnd, out vcEnd, m_earth); } else { vaEnd.masa += nCount; while (vaEnd.masa >= 12) { vaEnd.masa -= 12; vaEnd.gyear++; } vaEnd.masa = ComboMasaToMasa(vaEnd.masa); VATIMEtoVCTIME(vaEnd, out vcEnd, m_earth); } break; case PeriodUnit.Gaurabda: vaEnd.Set(vaStart); vaEnd.gyear += nCount; VATIMEtoVCTIME(vaEnd, out vcEnd, m_earth); break; } return(true); }