def from_fixed(cls, fixed_date): """Return Islamic date (year month day) corresponding to fixed date 'fixed_date'.""" year = quotient(30 * (fixed_date - cls.EPOCH) + 10646, 10631) prior_days = fixed_date - ArithmeticIslamicDate(year, 1, 1).to_fixed() month = quotient(11 * prior_days + 330, 325) day = fixed_date - ArithmeticIslamicDate(year, month, 1).to_fixed() + 1 return ArithmeticIslamicDate(year, month, day)
def from_fixed(cls, date): """Return Old Hindu solar date equivalent to fixed date date.""" sun = cls.hindu_day_count(date) + Clock.days_from_hours(6) year = quotient(sun, cls.ARYA_SOLAR_YEAR) month = mod(quotient(sun, cls.ARYA_SOLAR_MONTH), 12) + 1 day = ifloor(mod(sun, cls.ARYA_SOLAR_MONTH)) + 1 return OldHinduSolarDate(year, month, day)
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 this Islamic date.""" return (self.EPOCH - 1 + (self.year - 1) * 354 + quotient(3 + 11 * self.year, 30) + 29 * (self.month - 1) + quotient(self.month, 2) + self.day)
def easter(cls, year): """Return fixed date of Easter in Gregorian year 'year'.""" century = quotient(year, 100) + 1 shifted_epact = mod(14 + 11 * mod(year, 19) - quotient(3 * century, 4) + quotient(5 + (8 * century), 25), 30) adjusted_epact = shifted_epact + 1 if shifted_epact == 0 or (shifted_epact == 1 and 10 < mod(year, 19)) else shifted_epact apr19 = GregorianDate(year, MonthOfYear.April, 19) paschal_moon = apr19.to_fixed() - adjusted_epact return DayOfWeek.Sunday.after(paschal_moon)
def elapsed_days(cls, year): """Return number of days elapsed from the (Sunday) noon prior to the epoch of the Hebrew calendar to the mean conjunction (molad) of Tishri of Hebrew year h_year, or one day later.""" months_elapsed = quotient(235 * year - 234, 19) parts_elapsed = 12084 + 13753 * months_elapsed days = 29 * months_elapsed + quotient(parts_elapsed, 25920) return days + 1 if mod(3 * (days + 1), 7) < 3 else days
def to_fixed(self): """Return the serial date equivalent.""" return ((self.EPOCH - 1) + (365 * (self.year -1)) + quotient(self.year - 1, 4) - quotient(self.year - 1, 100) + quotient(self.year - 1, 400) + quotient((367 * self.month) - 362, 12) + (0 if self.month <= 2 else (-1 if self.is_leap_year(self.year) else -2)) + self.day)
def to_fixed(self): """Return the fixed date equivalent to the Julian date 'j_date'.""" y = self.year + 1 if self.year < 0 else self.year return (self.EPOCH - 1 + (365 * (y - 1)) + quotient(y - 1, 4) + quotient(367*self.month - 362, 12) + (0 if self.month <= 2 else (-1 if self.is_leap_year(self.year) else -2)) + self.day)
def to_gregorian_alt(cls, fixed_date): """Return the date corresponding to fixed date 'fixed_date'. Alternative calculation.""" y = cls.to_year(cls.EPOCH - 1 + fixed_date + 306) prior_days = fixed_date - GregorianDate(y - 1, MonthOfYear.March, 1).to_fixed() month = amod(quotient(5 * prior_days + 2, 153) + 3, 12) year = y - quotient(month + 9, 12) day = fixed_date - GregorianDate(year, month, 1).to_fixed() + 1 return GregorianDate(year, month, day)
def to_arithmetic_year(cls, date): """Return Persian year corresponding to the fixed date, date.""" d0 = date - PersianDate(475, 1, 1).to_fixed_arithmetic() n2820 = quotient(d0, 1029983) d1 = mod(d0, 1029983) y2820 = 2820 if (d1 == 1029982) else (quotient((128 * d1) + 46878, 46751)) year = 474 + (2820 * n2820) + y2820 return year if (0 < year) else (year - 1)
def alt_orthodox_easter(g_year): """Return fixed date of Orthodox Easter in Gregorian year g_year. Alternative calculation.""" paschal_moon = (354 * g_year + 30 * quotient((7 * g_year) + 8, 19) + quotient(g_year, 4) - quotient(g_year, 19) - 273 + GregorianDate.EPOCH) return DayOfWeek.Sunday.after(paschal_moon)
def from_fixed(cls, fixed_date): """Return the Julian fixed_date corresponding to fixed fixed_date 'fixed_date'.""" approx = quotient(((4 * (fixed_date - cls.EPOCH))) + 1464, 1461) year = approx - 1 if approx <= 0 else approx prior_days = fixed_date - JulianDate(year, MonthOfYear.January, 1).to_fixed() correction = (0 if fixed_date < JulianDate(year, MonthOfYear.March, 1).to_fixed() else (1 if cls.is_leap_year(year) else 2)) month = quotient(12*(prior_days + correction) + 373, 367) day = 1 + (fixed_date - JulianDate(year, month, 1).to_fixed()) return JulianDate(year, month, day)
def to_fixed_arithmetic(self): """Return fixed date of French Revolutionary date, f_date.""" return (self.EPOCH - 1 + 365 * (self.year - 1) + quotient(self.year - 1, 4) - quotient(self.year - 1, 100) + quotient(self.year - 1, 400) - quotient(self.year - 1, 4000) + 30 * (self.month - 1) + self.day)
def to_year_alt(cls, fixed_date): """Return the year corresponding to the fixed date 'fixed_date'. Alternative calculation.""" approx = quotient(fixed_date - cls.EPOCH + 2, Fraction(146097, 400)) start = (cls.EPOCH + (365 * approx) + quotient(approx, 4) + -quotient(approx, 100) + quotient(approx, 400)) return approx if fixed_date < start else approx + 1
def from_fixed_arithmetic(cls, date): """Return French Revolutionary date [year, month, day] of fixed date, date.""" approx = quotient(date - cls.EPOCH + 2, 1460969/4000) + 1 year = ((approx - 1) if (date < FrenchDate(approx, 1, 1).to_fixed_arithmetic()) else approx) month = 1 + quotient(date - FrenchDate(year, 1, 1).to_fixed_arithmetic(), 30) day = date - FrenchDate(year, month, 1).to_fixed_arithmetic() + 1 return FrenchDate(year, month, day)
def to_year(cls, fixed_date): """Return the year corresponding to the fixed date 'fixed_date'.""" d0 = fixed_date - cls.EPOCH n400 = quotient(d0, 146097) d1 = mod(d0, 146097) n100 = quotient(d1, 36524) d2 = mod(d1, 36524) n4 = quotient(d2, 1461) d3 = mod(d2, 1461) n1 = quotient(d3, 365) year = (400 * n400) + (100 * n100) + (4 * n4) + n1 return year if n100 == 4 or n1 == 4 else year + 1
def to_fixed_arithmetic(self): """Return fixed date equivalent to Persian date p_date.""" y = (self.year - 474) if (0 < self.year) else (self.year - 473) year = mod(y, 2820) + 474 temp = (31 * (self.month - 1)) if (self.month <= 7) else ((30 * (self.month - 1)) + 6) return ((self.EPOCH - 1) + (1029983 * quotient(y, 2820)) + (365 * (year - 1)) + quotient((31 * year) - 5, 128) + temp + self.day)
def to_fixed_alt(self): """Return the fixed date equivalent. Alternative calculation.""" m = amod(self.month - 2, 12) y = self.year + quotient(self.month + 9, 12) return ((self.EPOCH - 1) + -306 + 365 * (y - 1) + quotient(y - 1, 4) + -quotient(y - 1, 100) + quotient(y - 1, 400) + quotient(3 * m - 1, 5) + 30 * (m - 1) + self.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 molad(cls, month, year): """Return moment of mean conjunction of month in Hebrew year.""" y = year + 1 if month < HebrewMonth.TISHRI else year months_elapsed = month - HebrewMonth.TISHRI + quotient(235 * y - 234, 19) return ( cls.EPOCH - Fraction(876, 25920) + months_elapsed * (29 + Clock.days_from_hours(12) + Fraction(793, 25920)) )
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 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, fixed_date): """Return Old Hindu lunar date equivalent to fixed date 'fixed_date'.""" sun = cls.hindu_day_count(fixed_date) + Clock.days_from_hours(6) new_moon = sun - mod(sun, cls.ARYA_LUNAR_MONTH) leap = cls.ARYA_SOLAR_MONTH - cls.ARYA_LUNAR_MONTH >= mod(new_moon, cls.ARYA_SOLAR_MONTH) and mod(new_moon, cls.ARYA_SOLAR_MONTH) > 0 month = mod(iceiling(new_moon / cls.ARYA_SOLAR_MONTH), 12) + 1 day = mod(quotient(sun, cls.ARYA_LUNAR_DAY), 30) + 1 year = iceiling((new_moon + cls.ARYA_SOLAR_MONTH) / cls.ARYA_SOLAR_YEAR) - 1 return OldHinduLunarDate(year, month, leap, day)
def daily_motion(cls, date): """Return the sidereal daily motion of sun on date, date.""" mean_motion = 360 / cls.SIDEREAL_YEAR anomaly = cls.mean_position(date, cls.ANOMALISTIC_YEAR) epicycle = 14/360 - abs(cls.sine(anomaly)) / 1080 entry = quotient(float(anomaly), angle(0, 225, 0)) sine_table_step = cls.sine_table(entry + 1) - cls.sine_table(entry) factor = -3438/225 * sine_table_step * epicycle return mean_motion * (factor + 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, 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 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 from_fixed(cls, fixed_date): """Return the fixed_date corresponding to fixed fixed_date 'fixed_date'.""" year = cls.to_year(fixed_date) prior_days = fixed_date - cls.new_year(year) correction = (0 if (fixed_date < GregorianDate(year, MonthOfYear.March, 1).to_fixed()) else (1 if cls.is_leap_year(year) else 2)) month = quotient((12 * (prior_days + correction)) + 373, 367) day = 1 + (fixed_date - GregorianDate(year, month, 1).to_fixed()) return GregorianDate(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 fixed date corresponding to Old Hindu lunar date l_date.""" mina = ((12 * self.year) - 1) * self.ARYA_SOLAR_MONTH lunar_new_year = self.ARYA_LUNAR_MONTH * (quotient(mina, self.ARYA_LUNAR_MONTH) + 1) if not self.leap and iceiling((lunar_new_year - mina) / (self.ARYA_SOLAR_MONTH - self.ARYA_LUNAR_MONTH)) <= self.month: temp = self.month else: temp = self.month - 1 temp = self.EPOCH + lunar_new_year + (self.ARYA_LUNAR_MONTH * temp) + ((self.day - 1) * self.ARYA_LUNAR_DAY) + Clock.days_from_hours(-6) return iceiling(temp)