Example #1
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)
Example #2
0
 def toordinal(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)
Example #3
0
def alt_orthodox_easter(year):
    """Return ordinal date of Orthodox Easter in Gregorian year g_year.
    Alternative calculation."""
    paschal_moon = (354 * year +
                    30 * quotient((7 * year) + 8, 19) +
                    quotient(year, 4)  -
                    quotient(year, 19) -
                    273 +
                    GregorianDate.EPOCH)
    return after_weekday(paschal_moon, DayOfWeek.SUNDAY)
Example #4
0
 def to_year_alt(cls, ordinal):
     """Return the year corresponding to the ordinal date.
     Alternative calculation."""
     approx = quotient(ordinal - cls.EPOCH + 2, Fraction(146097, 400))
     start  = (cls.EPOCH        +
               (365 * approx)         +
               quotient(approx, 4)    +
               -quotient(approx, 100) +
               quotient(approx, 400))
     return approx if ordinal < start else approx + 1
 def fromordinal_arithmetic(cls, ordinal):
     """Return French Revolutionary date [year, month, day] of ordinal
        ordinal, ordinal."""
     approx = quotient(ordinal - cls.EPOCH + 2, 1460969/4000) + 1
     year   = ((approx - 1)
               if (ordinal < FrenchDate(approx, 1, 1).toordinal_arithmetic())
               else approx)
     month  = 1 + quotient(ordinal - FrenchDate(year, 1, 1).toordinal_arithmetic(), 30)
     day    = ordinal -  FrenchDate(year, month, 1).toordinal_arithmetic() + 1
     return FrenchDate(year, month, day)
 def toordinal_arithmetic(self):
     """Return ordinal 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)
Example #7
0
 def to_year(cls, ordinal):
     """Return the year corresponding to the ordinal date."""
     d0   = ordinal - cls.EPOCH
     n400 = int(math.floor(d0 / 146097))
     d1   = d0 % 146097
     n100 = quotient(d1, 36524)
     d2   = d1 % 36524
     n4   = quotient(d2, 1461)
     d3   = 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 fromordinal(cls, ordinal):
     """Return French Revolutionary date of ordinal date, 'ordinal'."""
     new_year = cls.new_year_on_or_before(ordinal)
     year  = iround((new_year - cls.EPOCH) / MEAN_TROPICAL_YEAR) + 1
     month = quotient(ordinal - new_year, 30) + 1
     day   = ((ordinal - new_year) % 30) + 1
     return FrenchDate(year, month, day)
Example #9
0
 def fromordinal(cls, ordinal):
     """Return the ordinal_date corresponding to ordinal date."""
     year = cls.to_year(ordinal)
     prior_days = ordinal - cls.new_year(year)
     correction = 0 if ordinal < GregorianDate(year, MonthOfYear.MARCH, 1).toordinal() else (1 if cls.is_leap_year(year) else 2)
     month = quotient((12 * (prior_days + correction)) + 373, 367)
     day = 1 + (ordinal - GregorianDate(year, month, 1).toordinal())
     return GregorianDate(year, month, day)
Example #10
0
 def easter(cls, year):
     """Return ordinal date of Easter in Gregorian year 'year'."""
     century = quotient(year, 100) + 1
     shifted_epact = ((14 + 11 * (year % 19) - int(math.floor((3 * century) / 4)) + int(math.floor((5 + (8 * century)) / 25)) ) % 30)
     adjusted_epact = shifted_epact + 1 if shifted_epact == 0 or (shifted_epact == 1 and 10 < year % 19) else shifted_epact
     apr19 = GregorianDate(year, MonthOfYear.APRIL, 19)
     paschal_moon = apr19.toordinal() - adjusted_epact
     return after_weekday(paschal_moon, DayOfWeek.SUNDAY)