Esempio n. 1
0
    def fromordinal(cls, ordinal):
        """Return the Tibetan lunar date corresponding to ordinal date, 'ordinal'."""
        cap_Y = 365 + 4975 / 18382
        years = int(math.ceil((ordinal - cls.EPOCH) / cap_Y))
        year0 = final_int(
            years, lambda y:
            (ordinal >= TibetanDate(y, 1, False, 1, False).toordinal()))
        month0 = final_int(
            1, lambda m:
            (ordinal >= TibetanDate(year0, m, False, 1, False).toordinal()))
        est = ordinal - TibetanDate(year0, month0, False, 1, False).toordinal()
        day0 = final_int(
            est - 2, lambda d:
            (ordinal >= TibetanDate(year0, month0, False, d, False).toordinal(
            )))
        leap_month = (day0 > 30)
        day = amod(day0, 30)
        if day > day0:
            temp = month0 - 1
        elif leap_month:
            temp = month0 + 1
        else:
            temp = month0
        month = amod(temp, 12)

        if day > day0 and month0 == 1:
            year = year0 - 1
        elif leap_month and month0 == 12:
            year = year0 + 1
        else:
            year = year0
        leap_day = ordinal == TibetanDate(year, month, leap_month, day,
                                          True).toordinal()
        return TibetanDate(year, month, leap_month, day, leap_day)
Esempio n. 2
0
 def toordinal(self):
     """Return the ordinal date equivalent to Hindu lunar date, l_date,
     in full_moon scheme."""
     if self.leap_month or self.day <= 15:
         m = self.month
     elif self.is_expunged(amod(self.month - 1, 12), self.year):
         m = amod(self.month - 2, 12)
     else:
         m = amod(self.month - 1, 12)
     return HinduLunarFullMoonDate(self.year, m, self.leap_month, self.day,
                                   self.leap_day).toordinal()
Esempio n. 3
0
 def jovian_year(cls, date):
     """Return year of Jupiter cycle at ordinal date date."""
     return amod(
         int(
             math.floor(
                 cls.hindu_day_count(date) /
                 (cls.ARYA_JOVIAN_PERIOD / 12))) + 27, 60)
Esempio n. 4
0
 def toordinal(self):
     """Return the ordinal date of this Hindu lunar date."""
     approx = OldHindu.EPOCH + (self.SIDEREAL_YEAR *
                                (self.year + self.LUNAR_ERA +
                                 ((self.month - 1) / 12)))
     s = int(
         math.floor(approx -
                    ((1 / 360) * self.SIDEREAL_YEAR *
                     ((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_fromordinal(s - 15)
         if ((mid.month != self.month)
                 or (mid.leap_month and not self.leap_month)):
             temp = ((k + 15) % 30) - 15
         else:
             temp = ((k - 15) % 30) + 15
     est = s + self.day - temp
     tau = est - (
         (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
Esempio n. 5
0
 def toordinal(self):
     """Return the ordinal 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 = int(
         math.floor(approx - 1 / 360 * self.MEAN_SIDEREAL_YEAR *
                    (((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.fromordinal(s - 15)
         if ((mid.month != self.month)
                 or (mid.leap_month and not self.leap_month)):
             temp = ((k + 15) % 30) - 15
         else:
             temp = ((k - 15) % 30) + 15
     est = s + self.day - temp
     tau = est - ((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
Esempio n. 6
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()
Esempio n. 7
0
    def fromordinal(cls, ordinal):
        """Return the Roman name corresponding to ordinal date 'ordinal'."""
        julian_date = JulianDate.fromordinal(ordinal)
        month_prime = amod(1 + julian_date.month, 12)
        year_prime = (julian_date.year if month_prime != 1 else
                      (julian_date.year + 1 if
                       (julian_date.year != -1) else 1))
        kalends1 = RomanDate(year_prime, month_prime, Event.Kalends, 1,
                             False).toordinal()

        if julian_date.day == 1:
            return RomanDate(julian_date.year, julian_date.month,
                             Event.Kalends, 1, False)
        elif julian_date.day <= cls.nones_of_month(julian_date.month):
            return RomanDate(
                julian_date.year, julian_date.month, Event.Nones,
                cls.nones_of_month(julian_date.month) - julian_date.day + 1,
                False)
        elif julian_date.day <= cls.ides_of_month(julian_date.month):
            return RomanDate(
                julian_date.year, julian_date.month, Event.Ides,
                cls.ides_of_month(julian_date.month) - julian_date.day + 1,
                False)
        elif (julian_date.month != MonthOfYear.FEBRUARY
              ) or not julian_date.is_leap_year(julian_date.year):
            return RomanDate(year_prime, month_prime, Event.Kalends,
                             kalends1 - ordinal + 1, False)
        elif julian_date.day < 25:
            return RomanDate(julian_date.year, MonthOfYear.MARCH,
                             Event.Kalends, 30 - julian_date.day, False)
        else:
            return RomanDate(julian_date.year, MonthOfYear.MARCH,
                             Event.Kalends, 31 - julian_date.day,
                             julian_date.day == 25)
Esempio n. 8
0
def karana(n):
    """Return the number (0-10) of the name of the n-th (1-60) Hindu karana."""
    if n == 1:
        return 0
    elif n > 57:
        return n - 50
    else:
        return amod(n - 1, 7)
Esempio n. 9
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)
Esempio n. 10
0
 def fromordinal_alt(cls, ordinal):
     """Return the date corresponding to ordinal date .
     Alternative calculation."""
     y = cls.to_year(cls.EPOCH - 1 + ordinal + 306)
     prior_days = ordinal - GregorianDate(y - 1, MonthOfYear.MARCH, 1).toordinal()
     month = amod(quotient(5 * prior_days + 2, 153) + 3, 12)
     year  = y - quotient(month + 9, 12)
     day   = ordinal - GregorianDate(year, month, 1).toordinal() + 1
     return GregorianDate(year, month, day)
Esempio n. 11
0
    def fromordinal(cls, ordinal):
        """Return Chinese date (cycle year month leap day) of ordinal date, 'ordinal'."""
        s1 = cls.winter_solstice_on_or_before(ordinal)
        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 = int(round((next_m11 - m12) / MEAN_SYNODIC_MONTH)) == 12

        m = cls.new_moon_before(1 + ordinal)
        month = amod(
            int(round((m - m12) / 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 = (int(
            math.floor(
                mpf(1.5) - (month / 12) +
                ((ordinal - cls.EPOCH) / MEAN_TROPICAL_YEAR))))
        cycle = 1 + int(math.floor((elapsed_years - 1) / 60))
        year = amod(elapsed_years, 60)
        day = 1 + (ordinal - m)
        return ChineseDate(cycle, year, month, leap_month, day)
Esempio n. 12
0
 def fromordinal(cls, ordinal):
     """Return the astronomical Hindu lunar date equivalent to
     ordinal date, ordinal."""
     critical = cls.alt_sunrise(ordinal)
     day = cls.day_from_moment(critical)
     leap_day = (day == cls.day_from_moment(cls.alt_sunrise(ordinal - 1)))
     last_new_moon = cls.new_moon_before(critical)
     next_new_moon = cls.new_moon_at_or_after(critical)
     solar_month = sidereal_zodiac(last_new_moon)
     leap_month = solar_month == sidereal_zodiac(next_new_moon)
     month = amod(solar_month + 1, 12)
     year = cls.calendar_year(
         ordinal + 180 if month <= 2 else ordinal) - cls.LUNAR_ERA
     return HinduAstroLunar(year, month, leap_month, day, leap_day)
Esempio n. 13
0
 def fromordinal(cls, ordinal):
     """Return the Hindu lunar date, new_moon scheme, 
     equivalent to ordinal date, ordinal."""
     critical = cls.sunrise(ordinal)
     day = cls.lunar_day_from_moment(critical)
     leap_day = (day == cls.lunar_day_from_moment(cls.sunrise(ordinal - 1)))
     last_new_moon = cls.new_moon_before(critical)
     next_new_moon = cls.new_moon_before(
         int(math.floor(last_new_moon)) + 35)
     solar_month = cls.zodiac(last_new_moon)
     leap_month = (solar_month == cls.zodiac(next_new_moon))
     month = amod(solar_month + 1, 12)
     year = cls.calendar_year(
         ordinal + 180 if month <= 2 else ordinal) - cls.LUNAR_ERA
     return HinduLunarDate(year, month, leap_month, day, leap_day)
Esempio n. 14
0
 def toordinal_alt(self):
     """Return the ordinal date equivalent.
     Alternative calculation."""
     m = amod(self.month - 2, 12)
     y = self.year + int(math.floor((self.month) + 9 / 12))
     return (self.EPOCH - 1) - 306 + 365 * (y - 1) + int(math.floor((y - 1) / 4)) - int(math.floor((y - 1) / 100)) + int(math.floor((y - 1) / 400)) + int(math.floor((3 * m - 1) / 5)) + 30 * (m - 1) + self.day
Esempio n. 15
0
 def sexagesimal_name(n):
     """Return the n_th name of the Chinese sexagesimal cycle."""
     return ChineseName(amod(n, 10), amod(n, 12))
Esempio n. 16
0
 def major_solar_term(cls, ordinal):
     """Return last Chinese major solar term (zhongqi) before
     ordinal date, 'ordinal'."""
     s = solar_longitude(
         cls.location(ordinal).universal_from_standard(ordinal))
     return amod(2 + int(math.floor(int(s) / 30)), 12)
Esempio n. 17
0
 def fromordinal(cls, ordinal):
     """Return Aztec tonalpohualli date of ordinal date."""
     count = ordinal - cls.CORRELATION + 1
     number = amod(count, 13)
     name = amod(count, 20)
     return AztecTonalpohualliDate(number, name)
Esempio n. 18
0
 def fromordinal(cls, date):
     """Return Mayan tzolkin date of ordinal date ordinal."""
     count  = date - cls.EPOCH + 1
     number = amod(count, 13)
     name   = amod(count, 20)
     return MayanTzolkinDate(number, name)
Esempio n. 19
0
 def dwiwara_fromordinal(cls, ordinal):
     """Return the position of ordinal date in 2_day Balinese cycle."""
     return amod(cls.dasawara_fromordinal(ordinal), 2)
Esempio n. 20
0
 def current_minor_solar_term(cls, ordinal):
     """Return last Chinese minor solar term (jieqi) before date, 'ordinal'."""
     s = solar_longitude(
         cls.location(ordinal).universal_from_standard(ordinal))
     return amod(3 + int(math.floor((s - 15) / 30)), 12)
Esempio n. 21
0
 def pancawara_fromordinal(cls, ordinal):
     """Return the position of date date in 5_day Balinese cycle."""
     return amod(cls.day_fromordinal(ordinal) + 2, 5)
Esempio n. 22
0
 def caturwara_fromordinal(cls, ordinal):
     """Return the position of ordinal date in 4_day Balinese cycle."""
     return amod(cls.asatawara_fromordinal(ordinal), 4)