def dragon_festival(cls, gregorian_year): """Return fixed date of the Dragon Festival occurring in Gregorian year 'gregorian_year'.""" elapsed_years = 1 + gregorian_year - GregorianDate.to_year(cls.EPOCH) cycle = 1 + quotient(elapsed_years - 1, 60) year = amod(elapsed_years, 60) return ChineseDate(cycle, year, 5, False, 5).to_fixed()
def location(cls, tee): """Return location of Beijing; time zone varies with time, tee.""" year = GregorianDate.to_year(ifloor(tee)) if (year < 1929): return Location(angle(39, 55, 0), angle(116, 25, 0), 43.5, Clock.days_from_hours(1397/180)) else: return Location(angle(39, 55, 0), angle(116, 25, 0), 43.5, Clock.days_from_hours(8))
def feast_of_ridvan(cls, gregorian_year): """Return Fixed date of Feast of Ridvan in Gregorian year year, 'gregorian_year'.""" years = gregorian_year - GregorianDate.to_year(cls.EPOCH) major = 1 + quotient(years, 361) cycle = 1 + quotient(mod(years, 361), 19) year = 1 + mod(years, 19) return FutureBahaiDate(major, cycle, year, 2, 13).to_fixed()
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 omer(cls, fixed_date): """Return the number of elapsed weeks and days in the omer at date fixed_date. Throws ValueError if that date does not fall during the omer.""" c = fixed_date - cls.passover(GregorianDate.to_year(fixed_date)) if 1 <= c <= 49: return [quotient(c, 7), mod(c, 7)] else: raise ValueError("Date does not fall within omer")
def from_fixed(cls, date): """Return the ISO date corresponding to the fixed date 'date'.""" approx = GregorianDate.to_year(date - 3) year = (approx + 1 if date >= IsoDate(approx + 1, 1, 1).to_fixed() else approx) week = 1 + quotient(date - IsoDate(year, 1, 1).to_fixed(), 7) day = amod(date - rd(0), 7) return IsoDate(year, week, day)
def japanese_location(tee): """Return the location for Japanese calendar; varies with moment, tee.""" year = GregorianDate.to_year(ifloor(tee)) if (year < 1888): # Tokyo (139 deg 46 min east) local time loc = Location(mpf(35.7), angle(139, 46, 0), 24, Clock.days_from_hours(9 + 143/450)) else: # Longitude 135 time zone loc = Location(35, 135, 0, Clock.days_from_hours(9)) return loc
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 yom_ha_zikkaron(cls, gregorian_year): """Return fixed date of Yom ha_Zikkaron occurring in Gregorian year 'gregorian_year'.""" hebrew_year = gregorian_year - GregorianDate.to_year(cls.EPOCH) iyyar4 = HebrewDate(hebrew_year, HebrewMonth.IYYAR, 4).to_fixed() if DayOfWeek.from_fixed(iyyar4) in (DayOfWeek.Thursday, DayOfWeek.Friday): return DayOfWeek.Wednesday.before(iyyar4) elif DayOfWeek.Sunday == DayOfWeek.from_fixed(iyyar4): return iyyar4 + 1 else: return iyyar4
def from_fixed(cls, fixed_date): """Return Bahai date [major, cycle, year, month, day] corresponding to fixed date, 'fixed_date'.""" g_year = GregorianDate.to_year(fixed_date) start = GregorianDate.to_year(cls.EPOCH) years = (g_year - start - (1 if (fixed_date <= GregorianDate(g_year, MonthOfYear.March, 20).to_fixed()) else 0)) major = 1 + quotient(years, 361) cycle = 1 + quotient(mod(years, 361), 19) year = 1 + mod(years, 19) days = fixed_date - WesternBahaiDate(major, cycle, year, 1, 1).to_fixed() # month if fixed_date >= WesternBahaiDate(major, cycle, year, 19, 1).to_fixed(): month = 19 elif fixed_date >= WesternBahaiDate(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 - WesternBahaiDate(major, cycle, year, month, 1).to_fixed() return WesternBahaiDate(major, cycle, year, month, day)
def to_fixed(self): """Return fixed date equivalent to the Bahai date, b_date.""" g_year = (361 * (self.major - 1) + 19 * (self.cycle - 1) + self.year - 1 + GregorianDate.to_year(self.EPOCH)) if (self.month == self.AYYAM_I_HA): elapsed_months = 342 elif (self.month == 19): if (GregorianDate.is_leap_year(g_year + 1)): elapsed_months = 347 else: elapsed_months = 346 else: elapsed_months = 19 * (self.month - 1) return GregorianDate(g_year, MonthOfYear.March, 20).to_fixed() + elapsed_months + self.day
def ephemeris_correction(cls, tee): """Return Dynamical Time minus Universal Time (in days) for moment, tee. Adapted from "Astronomical Algorithms" by Jean Meeus, Willmann_Bell, Inc., 1991.""" year = GregorianDate.to_year(ifloor(tee)) c = GregorianDate.date_difference(GregorianDate(1900, JulianMonth.January, 1), GregorianDate(year, JulianMonth.July, 1)) / mpf(36525) if 1988 <= year <= 2019: return 1/86400 * (year - 1933) elif 1900 <= year <= 1987: return poly(c, [mpf(-0.00002), mpf(0.000297), mpf(0.025184), mpf(-0.181133), mpf(0.553040), mpf(-0.861938), mpf(0.677066), mpf(-0.212591)]) elif 1800 <= year <= 1899: return poly(c, [mpf(-0.000009), mpf(0.003844), mpf(0.083563), mpf(0.865736), mpf(4.867575), mpf(15.845535), mpf(31.332267), mpf(38.291999), mpf(28.316289), mpf(11.636204), mpf(2.043794)]) elif 1700 <= year <= 1799: return 1/86400 * poly(year - 1700, [8.118780842, -0.005092142, 0.003336121, -0.0000266484]) elif 1620 <= year <= 1699: return 1/86400 * poly(year - 1600, [mpf(196.58333), mpf(-4.0675), mpf(0.0219167)]) else: x = Clock.days_from_hours(mpf(12)) + GregorianDate.date_difference(GregorianDate(1810, JulianMonth.January, 1), GregorianDate(year, JulianMonth.January, 1)) return 1/86400 * (((x * x) / mpf(41048480)) - 15)
def yom_kippur(cls, gregorian_year): """Return fixed date of Yom Kippur occurring in Gregorian year 'gregorian_year'.""" hebrew_year = gregorian_year - GregorianDate.to_year(cls.EPOCH) + 1 return HebrewDate(hebrew_year, HebrewMonth.TISHRI, 10).to_fixed()
def purim(cls, gregorian_year): """Return fixed date of Purim occurring in Gregorian year 'gregorian_year'.""" hebrew_year = gregorian_year - GregorianDate.to_year(cls.EPOCH) last_month = cls.last_month_of_year(hebrew_year) return HebrewDate(hebrew_year, last_month, 14).to_fixed()
def passover(cls, gregorian_year): """Return fixed date of Passover occurring in Gregorian year 'gregorian_year'.""" hebrew_year = gregorian_year - GregorianDate.to_year(cls.EPOCH) return HebrewDate(hebrew_year, HebrewMonth.NISAN, 15).to_fixed()
def tishah_be_av(cls, gregorian_year): """Return fixed date of Tishah be_Av occurring in Gregorian year 'gregorian_year'.""" hebrew_year = gregorian_year - GregorianDate.to_year(cls.EPOCH) av9 = HebrewDate(hebrew_year, HebrewMonth.AV, 9).to_fixed() return av9 + 1 if DayOfWeek.from_fixed(av9) == DayOfWeek.Saturday else av9
def naw_ruz(cls, g_year): """Return the Fixed date of Persian New Year (Naw-Ruz) in Gregorian year g_year.""" persian_year = g_year - GregorianDate.to_year(cls.EPOCH) + 1 y = (persian_year - 1) if (persian_year <= 0) else persian_year return PersianDate(y, 1, 1).to_fixed()