def unittests(): GCUT.info('sankranti') vc = Today() vc2 = GCGregorianDate() vc3 = GCGregorianDate(date=vc) vc3.AddDays(100) n = GetSankMethodName(GetSankrantiType()) GCUT.msg('Sankranti Type: {}'.format(n)) import io s = io.StringIO() clr = GCLocation() writeXml(s, clr, vc, vc3) GCUT.msg(s.getvalue())
def CalcTithiDate(nGYear, nMasa, nPaksa, nTithi, earth): i = 0 gy = 0 d = GCGregorianDate() dtemp = GCGregorianDate() day = GCDayData() tithi = 0 counter = 0 tmp = 0 if nGYear >= 464 and nGYear < 572: tmp = gGaurBeg[(nGYear - 464) * 26 + nMasa * 2 + nPaksa] d.month = (tmp & 0x3e0) >> 5 d.day = (tmp & 0x1f) d.year = (tmp & 0xfffc00) >> 10 d.tzone = earth.tzone d.NextDay() day.DayCalc(d, earth) day.nMasa = day.MasaCalc(d, earth) gy = day.nGaurabdaYear 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 += 1 d.shour = 0.5 d.tzone = earth.tzone i = 0 while True: d.AddDays(13) day.DayCalc(d, earth) day.nMasa = day.MasaCalc(d, earth) gy = day.nGaurabdaYear i += 1 if i >= 30: break if (day.nPaksa == nPaksa) and (day.nMasa == nMasa): break 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.nTithi == 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.nTithi > tithi) and (day.nPaksa != nPaksa): d.NextDay() return d if day.nTithi < 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.nTithi == tithi: return d if (day.nTithi < tithi) and (day.nPaksa != nPaksa): return d if day.nTithi > tithi: return d counter += 1 # 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.nTithi == tithi: return d if (day.nTithi > tithi) and (day.nPaksa != nPaksa): d.NextDay() return d if day.nTithi < tithi: d.NextDay() return d counter += 1 # 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
def CalcTithiEndEx(vcStart, GYear, nMasa, nPaksa, nTithi, earth, endTithi): d = GCGregorianDate() dtemp = GCGregorianDate() day = GCDayData() tithi = 0 counter = 0 sunrise = 0.0 start = GCGregorianDate() end = GCGregorianDate() start.shour = -1.0 end.shour = -1.0 start.day = start.month = start.year = -1 end.day = end.month = end.year = -1 d.Set(vcStart) i = 0 while True: d.AddDays(13) day.DayCalc(d, earth) day.nMasa = day.MasaCalc(d, earth) gy = day.nGaurabdaYear i += 1 if ((day.nPaksa == nPaksa) and (day.nMasa == nMasa)) or i > 30: break 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.nTithi == 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.nTithi < 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.nTithi == tithi: break if (day.nTithi < tithi) and (day.nPaksa != nPaksa): d.PreviousDay() break if day.nTithi > tithi: d.PreviousDay() break counter += 1 # somewhere is error if counter >= 30: 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.nTithi == tithi: break if (day.nTithi > tithi) and (day.nPaksa != nPaksa): break if day.nTithi < tithi: break counter += 1 # somewhere is error if counter >= 30: d.year = d.month = d.day = 0 nType = 0 if day.nTithi == 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.sun.sunrise_deg / 360 + earth.tzone / 24 if nType == 1: d1 = GCGregorianDate() d2 = GCGregorianDate() d.shour = sunrise GCTithi.GetPrevTithiStart(earth, d, d1) #d = d1 #d.shour += 0.02 GCTithi.GetNextTithiStart(earth, d, d2) endTithi.Set(d2) return d1 elif nType == 2: d1 = GCGregorianDate() d2 = GCGregorianDate() d.shour = sunrise GCTithi.GetNextTithiStart(earth, d, d1) d.Set(d1) d.shour += 0.1 d.NormalizeValues() GCTithi.GetNextTithiStart(earth, d, 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