Example #1
0
 def to_fixed(self):
     """Return the fixed 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).to_fixed()
Example #2
0
 def from_fixed(cls, fixed_date):
     """Return the Roman name corresponding to fixed fixed_date 'fixed_date'."""
     julian_date = JulianDate.from_fixed(fixed_date)
     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).to_fixed()
 
     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 - fixed_date + 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)
Example #3
0
 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)
Example #4
0
 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()
Example #5
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)
Example #6
0
 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)
Example #7
0
 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)
Example #8
0
 def from_fixed(cls, date):
     """Return the Hindu lunar date, new_moon scheme, 
     equivalent to fixed date, date."""
     critical = cls.sunrise(date)
     day = cls.lunar_day_from_moment(critical)
     leap_day = (day == cls.lunar_day_from_moment(cls.sunrise(date - 1)))
     last_new_moon = cls.new_moon_before(critical)
     next_new_moon = cls.new_moon_before(ifloor(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((date + 180) if (month <= 2) else date) - cls.LUNAR_ERA
     return HinduLunarDate(year, month, leap_month, day, leap_day)
Example #9
0
 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)
Example #10
0
 def from_fixed(cls, date):
     """Return the astronomical Hindu lunar date equivalent to
     fixed date, date."""
     critical = cls.alt_sunrise(date)
     day      = cls.day_from_moment(critical)
     leap_day = (day == cls.day_from_moment(cls.alt_sunrise(date - 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((date + 180)
                                          if (month <= 2)
                                          else date) - cls.LUNAR_ERA
     return HinduAstroLunar(year, month, leap_month, day, leap_day)
Example #11
0
 def to_fixed(self):
     """Return the fixed 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 = ifloor(approx -
               1/360 * self.MEAN_SIDEREAL_YEAR *
               (mod(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.from_fixed(s - 15)
         if ((mid.month != self.month) or (mid.leap_month and not self.leap_month)):
             temp = mod(k + 15, 30) - 15
         else:
             temp = mod(k - 15, 30) + 15
     est = s + self.day - temp
     tau = est - mod(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
Example #12
0
 def pancawara_from_fixed(cls, date):
     """Return the position of date date in 5_day Balinese cycle."""
     return amod(cls.day_from_fixed(date) + 2, 5)
Example #13
0
 def caturwara_from_fixed(cls, date):
     """Return the position of date date in 4_day Balinese cycle."""
     return amod(cls.asatawara_from_fixed(date), 4)
Example #14
0
 def dwiwara_from_fixed(cls, date):
     """Return the position of date date in 2_day Balinese cycle."""
     return amod(cls.dasawara_from_fixed(date), 2)
Example #15
0
 def major_solar_term(cls, fixed_date):
     """Return last Chinese major solar term (zhongqi) before
     fixed date, 'fixed_date'."""
     s = Solar.solar_longitude(cls.location(fixed_date).universal_from_standard(fixed_date))
     return amod(2 + quotient(int(s), 30), 12)
Example #16
0
 def current_minor_solar_term(cls, fixed_date):
     """Return last Chinese minor solar term (jieqi) before date, 'fixed_date'."""
     s = Solar.solar_longitude(cls.location(fixed_date).universal_from_standard(fixed_date))
     return amod(3 + quotient(s - 15, 30), 12)
Example #17
0
 def jovian_year(cls, date):
     """Return year of Jupiter cycle at fixed date date."""
     return amod(quotient(cls.hindu_day_count(date), cls.ARYA_JOVIAN_PERIOD / 12) + 27, 60)
Example #18
0
 def to_fixed(self):
     """Return the fixed date of this Hindu lunar date."""
     approx = OldHindu.EPOCH + (self.SIDEREAL_YEAR * (self.year + self.LUNAR_ERA + ((self.month - 1) / 12)))
     s = ifloor(approx - ((1/360) * self.SIDEREAL_YEAR * mod(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_from_fixed(s - 15)
         if ((mid.month != self.month) or
             (mid.leap_month and not self.leap_month)):
             temp = mod(k + 15, 30) - 15
         else:
             temp = mod(k - 15, 30) + 15
     est = s + self.day - temp
     tau = est - mod(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
Example #19
0
 def sexagesimal_name(n):
     """Return the n_th name of the Chinese sexagesimal cycle."""
     return ChineseName(amod(n, 10), amod(n, 12))