def phasis_on_or_before(self, date): """Return the closest fixed date on or before date 'date', when crescent moon first became visible at location 'location'.""" mean = date - ifloor(Lunar.lunar_phase(date + 1) / 360.0 * Lunar.MEAN_SYNODIC_MONTH) tau = ((mean - 30) if (((date - mean) <= 3) and (not self.visible_crescent(date))) else (mean - 2)) return next_int(tau, lambda d: self.visible_crescent(d))
def arcsin(cls, amp): """Return the inverse of Hindu sine function of amp.""" if (amp < 0): return -cls.arcsin(-amp) else: pos = next_int(0, lambda k: amp <= cls.sine_table(k)) below = cls.sine_table(pos - 1) return (angle(0, 225, 0) * (pos - 1 + ((amp - below) / (cls.sine_table(pos) - below))))
def from_fixed(cls, fixed_date): """Return the Hindu (Orissa) solar date equivalent to fixed date, 'fixed_date'.""" critical = cls.sunrise(fixed_date + 1) month = cls.zodiac(critical) year = cls.calendar_year(critical) - cls.SOLAR_ERA approx = fixed_date - 3 - mod(ifloor(cls.solar_longitude(critical)), 30) begin = next_int(approx, lambda i: (cls.zodiac(cls.sunrise(i + 1)) == month)) day = fixed_date - begin + 1 return HinduSolarDate(year, month, day)
def from_fixed(cls, fixed_date): """Return the Astronomical Hindu (Tamil) solar date equivalent to fixed date, 'fixed_date'.""" critical = cls.sunset(fixed_date) month = sidereal_zodiac(critical) year = cls.calendar_year(critical) - HinduSolarDate.SOLAR_ERA approx = fixed_date - 3 - mod(ifloor(sidereal_solar_longitude( critical)), 30) begin = next_int(approx, lambda i: (sidereal_zodiac(cls.sunset(i)) == month)) day = fixed_date - begin + 1 return HinduAstroSolar(year, month, day)
def from_fixed(cls, fixed_date): """Return Hebrew (year month day) corresponding to fixed date 'fixed_date'. # The fraction can be approximated by 365.25.""" approx = quotient(fixed_date - cls.EPOCH, Fraction(35975351, 98496)) + 1 year = final_int(approx - 1, lambda y: cls.new_year(y) <= fixed_date) start = ( HebrewMonth.TISHRI if fixed_date < HebrewDate(year, HebrewMonth.NISAN, 1).to_fixed() else HebrewMonth.NISAN ) month = next_int(start, lambda m: fixed_date <= HebrewDate(year, m, cls.last_day_of_month(m, year)).to_fixed()) day = fixed_date - HebrewDate(year, month, 1).to_fixed() + 1 return HebrewDate(year, month, day)
def to_fixed(self): """Return the fixed date of this Hindu lunar date.""" approx = OldHindu.EPOCH + (self.SIDEREAL_YEAR * (self.year + self.LUNAR_ERA + ((self.month - 1) / 12))) s = ifloor(approx - ((1/360) * self.SIDEREAL_YEAR * mod(self.hindu_solar_longitude(approx) - ((self.month - 1) * 30) + 180, 360) - 180)) k = self.lunar_day_from_moment(s + Clock.days_from_hours(6)) if (3 < k < 27): temp = k else: mid = self.lunar_from_fixed(s - 15) if ((mid.month != self.month) or (mid.leap_month and not self.leap_month)): temp = mod(k + 15, 30) - 15 else: temp = mod(k - 15, 30) + 15 est = s + self.day - temp tau = est - mod(self.lunar_day_from_moment(est + Clock.days_from_hours(6)) - self.day + 15, 30) + 15 date = next_int(tau - 1, lambda d: self.lunar_day_from_moment(self.sunrise(d)) in [self.day, amod(self.day + 1, 30)]) return date + 1 if self.leap_day else date
def hindu_date_occur(l_month, l_day, l_year): """Return the fixed date of occurrence of Hindu lunar month, l_month, day, l_day, in Hindu lunar year, l_year, taking leap and expunged days into account. When the month is expunged, then the following month is used.""" lunar = HinduLunarDate(l_year, l_month, False, l_day, False) ttry = lunar.to_fixed() mid = HinduLunarDate.from_fixed((ttry - 5) if (l_day > 15) else ttry) expunged = l_month != mid.month l_date = HinduLunarDate(mid.year, mid.month, mid.leap_month, l_day, False) if (expunged): return next_int(ttry, lambda d: (not is_hindu_lunar_on_or_before( HinduLunarDate.from_fixed(d), l_date))) - 1 elif (l_day != HinduLunarDate.from_fixed(ttry).day): return ttry - 1 else: return ttry
def to_fixed(self): """Return the fixed date corresponding to Hindu lunar date, l_date.""" approx = (OldHindu.EPOCH + self.MEAN_SIDEREAL_YEAR * (self.year + self.LUNAR_ERA + ((self.month - 1) / 12))) s = ifloor(approx - 1/360 * self.MEAN_SIDEREAL_YEAR * (mod(sidereal_solar_longitude(approx) - (self.month - 1) * 30 + 180, 360) - 180)) k = self.day_from_moment(s + Clock.days_from_hours(6)) if (3 < k < 27): temp = k else: mid = self.from_fixed(s - 15) if ((mid.month != self.month) or (mid.leap_month and not self.leap_month)): temp = mod(k + 15, 30) - 15 else: temp = mod(k - 15, 30) + 15 est = s + self.day - temp tau = est - mod(self.day_from_moment(est + Clock.days_from_hours(6)) - self.day + 15, 30) + 15 date = next_int(tau - 1, lambda d: (self.day_from_moment(self.alt_sunrise(d)) in [self.day, amod(self.day + 1, 30)])) return (date + 1) if self.leap_day else date
def new_year_on_or_before(cls, fixed_date): """Return fixed date of Future Bahai New Year on or before fixed date, 'fixed_date'.""" approx = Solar.estimate_prior_solar_longitude(Astro.SPRING, cls.sunset_in_haifa(fixed_date)) return next_int(ifloor(approx) - 1, lambda day: Solar.solar_longitude(cls.sunset_in_haifa(day)) <= Astro.SPRING + 2)
def to_fixed(self): """Return the fixed date corresponding to Astronomical Hindu solar date (Tamil rule; Saka era).""" approx = OldHindu.EPOCH - 3 + ifloor(((self.year + HinduSolarDate.SOLAR_ERA) + ((self.month - 1) / 12)) * self.MEAN_SIDEREAL_YEAR) begin = next_int(approx, lambda i: sidereal_zodiac(self.sunset(i)) == self.month) return begin + self.day - 1
def to_fixed(self): """Return the fixed date corresponding to Hindu solar date, s_date, (Saka era; Orissa rule.)""" begin = ifloor((self.year + self.SOLAR_ERA + ((self.month - 1)/12)) * self.SIDEREAL_YEAR + OldHindu.EPOCH) return self.day - 1 + next_int(begin - 3, lambda d: self.zodiac(self.sunrise(d + 1)) == self.month)
def new_year_on_or_before(cls, date): """Return the fixed date of Astronomical Persian New Year on or before fixed date, date.""" approx = Solar.estimate_prior_solar_longitude(Astro.SPRING, cls.midday_in_tehran(date)) return next_int(ifloor(approx) - 1, lambda day: (Solar.solar_longitude(cls.midday_in_tehran(day)) <= (Astro.SPRING + 2)))
def winter_solstice_on_or_before(cls, fixed_date): """Return fixed date, in the Chinese zone, of winter solstice on or before fixed date, 'fixed_date'.""" approx = Solar.estimate_prior_solar_longitude(Astro.WINTER, cls.midnight(fixed_date + 1)) return next_int(ifloor(approx) - 1, lambda day: Astro.WINTER < Solar.solar_longitude(cls.midnight(1 + day)))
def new_year_on_or_before(cls, date): """Return fixed date of French Revolutionary New Year on or before fixed date, date.""" approx = Solar.estimate_prior_solar_longitude(Astro.AUTUMN, cls.midnight_in_paris(date)) return next_int(ifloor(approx) - 1, lambda day: Astro.AUTUMN <= Solar.solar_longitude(cls.midnight_in_paris(day)))
def phasis_on_or_after(cls, fixed_date, location): """Return closest fixed date on or after date, date, on the eve of which crescent moon first became visible at location, location.""" mean = fixed_date - ifloor(Lunar.lunar_phase(fixed_date + 1) / mpf(360) * Lunar.MEAN_SYNODIC_MONTH) tau = fixed_date if fixed_date - mean <= 3 and not location.visible_crescent(fixed_date - 1) else mean + 29 return next_int(tau, lambda d: location.visible_crescent(d))
def new_moon_at_or_after(cls, tee): """Return the moment UT of first new moon at or after moment, tee.""" t0 = cls.nth_new_moon(0) phi = cls.lunar_phase(tee) n = iround((tee - t0) / cls.MEAN_SYNODIC_MONTH - phi / 360) return cls.nth_new_moon(next_int(n, lambda k: cls.nth_new_moon(k) >= tee))