Пример #1
0
    def fromordinal(cls, ordinal):
        """Return Bahai date [major, cycle, year, month, day] corresponding
        to ordinal date."""
        g_year = GregorianDate.to_year(ordinal)
        start = GregorianDate.to_year(cls.EPOCH)
        years = (g_year - start - (1 if (ordinal <= GregorianDate(
            g_year, MonthOfYear.MARCH, 20).toordinal()) else 0))
        major = 1 + int(math.floor(years / 361))
        cycle = 1 + int(math.floor((years % 361) / 19))
        year = 1 + years % 19
        days = ordinal - WesternBahaiDate(major, cycle, year, 1, 1).toordinal()

        # month
        if ordinal >= WesternBahaiDate(major, cycle, year, 19, 1).toordinal():
            month = 19
        elif ordinal >= WesternBahaiDate(major, cycle, year, cls.AYYAM_I_HA,
                                         1).toordinal():
            month = cls.AYYAM_I_HA
        else:
            month = 1 + int(math.floor(days / 19))

        day = ordinal + 1 - WesternBahaiDate(major, cycle, year, month,
                                             1).toordinal()

        return WesternBahaiDate(major, cycle, year, month, day)
Пример #2
0
 def feast_of_ridvan(cls, gregorian_year):
     """Return ordinal date of Feast of Ridvan in Gregorian year year, 'gregorian_year'."""
     years = gregorian_year - GregorianDate.to_year(cls.EPOCH)
     major = 1 + int(math.floor(years / 361))
     cycle = 1 + int(math.floor((years % 361) / 19))
     year = 1 + years % 19
     return FutureBahaiDate(major, cycle, year, 2, 13).toordinal()
Пример #3
0
 def dragon_festival(cls, gregorian_year):
     """Return ordinal date of the Dragon Festival occurring in Gregorian
     year 'gregorian_year'."""
     elapsed_years = 1 + gregorian_year - GregorianDate.to_year(cls.EPOCH)
     cycle = 1 + int(math.floor((elapsed_years - 1) / 60))
     year = amod(elapsed_years, 60)
     return ChineseDate(cycle, year, 5, False, 5).toordinal()
Пример #4
0
 def omer(cls, ordinal):
     """Return the number of elapsed weeks and days in the omer at date ordinal.
     Throws ValueError if that date does not fall during the omer."""
     c = ordinal - cls.passover(GregorianDate.to_year(ordinal))
     if 1 <= c <= 49:
         return [int(math.floor(c, 7)), c % 7]
     else:
         raise ValueError("Date does not fall within omer")
Пример #5
0
 def toordinal(self):
     """Return ordinal date equivalent to Observational Hebrew date."""
     year1 = self.year - 1 if self.month >= HebrewMonth.TISHRI else self.year
     start = HebrewDate(year1, HebrewMonth.NISAN, 1).toordinal()
     g_year = GregorianDate.to_year(start + 60)
     new_year = self.new_year(g_year)
     midmonth = new_year + int(round(29.5 * (self.month - 1))) + 15
     return JAFFA.phasis_on_or_before(midmonth) + self.day - 1
Пример #6
0
 def fromordinal(cls, ordinal):
     """Return the ISO date corresponding to the ordinal date 'ordinal'."""
     approx = GregorianDate.to_year(ordinal - 3)
     year = (approx + 1 if ordinal >= IsoDate(approx + 1, 1, 1).toordinal()
             else approx)
     week = 1 + int(
         math.floor(ordinal - IsoDate(year, 1, 1).toordinal() / 7))
     day = amod(ordinal, 7)
     return IsoDate(year, week, day)
Пример #7
0
 def location(cls, tee):
     """Return location of Beijing; time zone varies with time, tee."""
     year = GregorianDate.to_year(int(math.floor(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))
Пример #8
0
def japanese_location(tee):
    """Return the location for Japanese calendar; varies with moment, tee."""
    year = GregorianDate.to_year(int(math.floor(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
Пример #9
0
 def fromordinal(cls, ordinal):
     """Return Observational Hebrew date (year month day)
     corresponding to ordinal date, 'ordinal'."""
     crescent = JAFFA.phasis_on_or_before(ordinal)
     g_year = GregorianDate.to_year(ordinal)
     ny = cls.new_year(g_year)
     new_year = cls.new_year(g_year - 1) if (ordinal < ny) else ny
     month = int(round((crescent - new_year) / 29.5)) + 1
     year = HebrewDate.fromordinal(new_year).year + (
         1 if month >= HebrewMonth.TISHRI else 0)
     day = ordinal - crescent + 1
     return HebrewObservationalDate(year, month, day)
Пример #10
0
    def yom_ha_zikkaron(cls, gregorian_year):
        """Return ordinal 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).toordinal()

        if weekday_fromordinal(iyyar4) in (DayOfWeek.THURSDAY,
                                           DayOfWeek.FRIDAY):
            return before_weekday(iyyar4, DayOfWeek.WEDNESDAY)
        elif DayOfWeek.SUNDAY == weekday_fromordinal(iyyar4):
            return iyyar4 + 1
        else:
            return iyyar4
Пример #11
0
def ephemeris_correction(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(int(math.floor(tee)))
    c = GregorianDate.date_difference(
        GregorianDate(1900, MonthOfYear.JANUARY, 1),
        GregorianDate(year, MonthOfYear.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, MonthOfYear.JANUARY, 1),
            GregorianDate(year, MonthOfYear.JANUARY, 1))
        return 1 / 86400 * (((x * x) / mpf(41048480)) - 15)
Пример #12
0
    def toordinal(self):
        """Return ordinal 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).toordinal() + elapsed_months + self.day
Пример #13
0
 def yom_kippur(cls, gregorian_year):
     """Return ordinal 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).toordinal()
Пример #14
0
 def passover(cls, gregorian_year):
     """Return ordinal 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).toordinal()
Пример #15
0
 def purim(cls, gregorian_year):
     """Return ordinal 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).toordinal()
Пример #16
0
 def naw_ruz(cls, g_year):
     """Return the ordinal 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).toordinal()
Пример #17
0
 def tishah_be_av(cls, gregorian_year):
     """Return ordinal 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).toordinal()
     return av9 + (1
                   if weekday_fromordinal(av9) == DayOfWeek.SATURDAY else 0)