def from_fixed(cls, fixed_date): """Return Chinese date (cycle year month leap day) of fixed date, 'fixed_date'.""" s1 = cls.winter_solstice_on_or_before(fixed_date) s2 = cls.winter_solstice_on_or_before(s1 + 370) next_m11 = cls.new_moon_before(1 + s2) m12 = cls.new_moon_on_or_after(1 + s1) leap_year = iround((next_m11 - m12) / Lunar.MEAN_SYNODIC_MONTH) == 12 m = cls.new_moon_before(1 + fixed_date) month = amod(iround((m - m12) / Lunar.MEAN_SYNODIC_MONTH) - (1 if (leap_year and cls.is_prior_leap_month(m12, m)) else 0), 12) leap_month = (leap_year and cls.is_no_major_solar_term(m) and (not cls.is_prior_leap_month(m12, cls.new_moon_before(m)))) elapsed_years = (ifloor(mpf(1.5) - (month / 12) + ((fixed_date - cls.EPOCH) / Solar.MEAN_TROPICAL_YEAR))) cycle = 1 + quotient(elapsed_years - 1, 60) year = amod(elapsed_years, 60) day = 1 + (fixed_date - m) return ChineseDate(cycle, year, month, leap_month, day)
def from_fixed(cls, fixed_date): """Return French Revolutionary date of fixed date, 'fixed_date'.""" new_year = cls.new_year_on_or_before(fixed_date) year = iround((new_year - cls.EPOCH) / Solar.MEAN_TROPICAL_YEAR) + 1 month = quotient(fixed_date - new_year, 30) + 1 day = mod(fixed_date - new_year, 30) + 1 return FrenchDate(year, month, day)
def to_fixed(self): """Return fixed date equivalent to Observational Hebrew date.""" year1 = self.year - 1 if self.month >= HebrewMonth.TISHRI else self.year start = HebrewDate(year1, HebrewMonth.NISAN, 1).to_fixed() g_year = GregorianDate.to_year(start + 60) new_year = self.new_year(g_year) midmonth = new_year + iround(29.5 * (self.month - 1)) + 15 return JAFFA.phasis_on_or_before(midmonth) + self.day - 1
def from_fixed(cls, fixed_date): """Return Observational Islamic date (year month day) corresponding to fixed date, 'fixed_date'.""" crescent = cls.LOCATION.phasis_on_or_before(fixed_date) elapsed_months = iround((crescent - cls.EPOCH) / Lunar.MEAN_SYNODIC_MONTH) year = quotient(elapsed_months, 12) + 1 month = mod(elapsed_months, 12) + 1 day = (fixed_date - crescent) + 1 return ObservationalIslamicDate(year, month, day)
def from_fixed(cls, fixed_date): """Return Observational Hebrew date (year month day) corresponding to fixed date, 'fixed_date'.""" crescent = JAFFA.phasis_on_or_before(fixed_date) g_year = GregorianDate.to_year(fixed_date) ny = cls.new_year(g_year) new_year = cls.new_year(g_year - 1) if (fixed_date < ny) else ny month = iround((crescent - new_year) / 29.5) + 1 year = HebrewDate.from_fixed(new_year).year + (1 if month >= HebrewMonth.TISHRI else 0) day = fixed_date - crescent + 1 return HebrewObservationalDate(year, month, day)
def from_fixed(cls, date): """Return Astronomical Persian date (year month day) corresponding to fixed date, date.""" new_year = cls.new_year_on_or_before(date) y = iround((new_year - cls.EPOCH) / Solar.MEAN_TROPICAL_YEAR) + 1 year = y if (0 < y) else (y - 1) day_of_year = date - PersianDate(year, 1, 1).to_fixed() + 1 month = (iceiling(day_of_year / 31) if (day_of_year <= 186) else iceiling((day_of_year - 6) / 30)) day = date - (PersianDate(year, month, 1).to_fixed() - 1) return PersianDate(year, month, day)
def lunar_phase(cls, tee): """Return the lunar phase, as an angle in degrees, at moment tee. An angle of 0 means a new moon, 90 degrees means the first quarter, 180 means a full moon, and 270 degrees means the last quarter.""" phi = mod(cls.lunar_longitude(tee) - Solar.solar_longitude(tee), 360) t0 = cls.nth_new_moon(0) n = iround((tee - t0) / cls.MEAN_SYNODIC_MONTH) phi_prime = (360 * mod((tee - cls.nth_new_moon(n)) / cls.MEAN_SYNODIC_MONTH, 1)) if abs(phi - phi_prime) > 180: return phi_prime else: return phi
def new_year_in_sui(cls, fixed_date): """Return fixed date of Chinese New Year in sui (period from solstice to solstice) containing date, 'fixed_date'.""" s1 = cls.winter_solstice_on_or_before(fixed_date) s2 = cls.winter_solstice_on_or_before(s1 + 370) next_m11 = cls.new_moon_before(1 + s2) m12 = cls.new_moon_on_or_after(1 + s1) m13 = cls.new_moon_on_or_after(1 + m12) leap_year = iround((next_m11 - m12) / Lunar.MEAN_SYNODIC_MONTH) == 12 if (leap_year and (cls.is_no_major_solar_term(m12) or cls.is_no_major_solar_term(m13))): return cls.new_moon_on_or_after(1 + m13) else: return m13
def from_fixed(cls, fixed_date): """Return Future Bahai date corresponding to fixed date, 'fixed_date'.""" new_year = cls.new_year_on_or_before(fixed_date) years = iround((new_year - cls.EPOCH) / Solar.MEAN_TROPICAL_YEAR) major = 1 + quotient(years, 361) cycle = 1 + quotient(mod(years, 361), 19) year = 1 + mod(years, 19) days = fixed_date - new_year if fixed_date >= FutureBahaiDate(major, cycle, year, 19, 1).to_fixed(): month = 19 elif fixed_date >= FutureBahaiDate(major, cycle, year, cls.AYYAM_I_HA, 1).to_fixed(): month = cls.AYYAM_I_HA else: month = 1 + quotient(days, 19) day = fixed_date + 1 - FutureBahaiDate(major, cycle, year, month, 1).to_fixed() return FutureBahaiDate(major, cycle, year, month, day)
def calendar_year(cls, tee): """Return the astronomical Hindu solar year KY at given moment, tee.""" return iround(((tee - OldHindu.EPOCH) / cls.MEAN_SIDEREAL_YEAR) - (sidereal_solar_longitude(tee) / 360))
def calendar_year(cls, tee): """Return the solar year at given moment, tee.""" return iround(((tee - OldHindu.EPOCH) / cls.SIDEREAL_YEAR) - (cls.solar_longitude(tee) / 360))
def alt_sunrise(cls, date): """Return the astronomical sunrise at Hindu location on date, date, per Lahiri, rounded to nearest minute, as a rational number.""" rise = cls.UJJAIN.dawn(date, angle(0, 47, 0)) return 1/24 * 1/60 * iround(rise * 24 * 60)
def sine_table(cls, entry): """Return the value for entry in the Hindu sine table. Entry, entry, is an angle given as a multiplier of 225'.""" exact = 3438 * sin_degrees(entry * angle(0, 225, 0)) error = 0.215 * signum(exact) * signum(abs(exact) - 1716) return iround(exact + error) / 3438
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))
def new_moon_before(cls, tee): """Return the moment UT of last new moon before 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(final_int(n - 1, lambda k: cls.nth_new_moon(k) < tee))