Advertisement
DeaD_EyE

schwerdtfegers_method

Sep 9th, 2019
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
  2.  
  3.  
  4. def schwerdtfegers_method(year, month, day):
  5.     """
  6.    Implementation of Schwerdtfeger's_method
  7.    of Julian calendar.
  8.    
  9.    Look here:
  10.    https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Schwerdtfeger's_method
  11.    """
  12.     if year < 0:
  13.         raise ValueError('Year must be a positive integer')
  14.     if not 1 <= month <= 12:
  15.         raise ValueError('Month must between 1 and 12')
  16.     if not 1 <= day <= 31:
  17.         raise ValueError('Day must between 1 and 31')
  18.     m_table = [None, 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
  19.     if month >= 3:
  20.         c = year // 100
  21.         g = year - 100 * c
  22.     else:
  23.         c = (year - 1) // 100
  24.         g = year - 1 - 100 * c
  25.     f = c % 7
  26.     w = (day + m_table[month] + f + g + ( g // 4)) % 7
  27.     return w
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement