# Calendars.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-02 File created. # 2009-01-22 class ISODate used in place of Date # 2022-12-18 Converted to Python 3. # See notes at the end of this file. from ISODate import ISODate class EnglishCalendar : def __init__( self, given_month, given_year ) : self.names_of_months = \ ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ) self.week_description = \ " Week Mon Tue Wed Thu Fri Sat Sun" self.this_month = given_month self.this_year = given_year def show( self ) : a_day_in_this_month = ISODate( self.this_year, self.this_month, 1 ) day_of_week_index = 0 day_of_week_of_first_day = a_day_in_this_month.index_for_day_of_week() print( "\n\n %s %d\n\n%s\n" % \ ( self.names_of_months[ self.this_month - 1 ], self.this_year, self.week_description ) ) print( "%4d " % a_day_in_this_month.get_week_number(), end="" ) # The first week of a month is often an incomplete week, # i.e., the first part of week belongs to the previous # month. In place of the days that belong to the previous # month we print just spaces. while day_of_week_index != day_of_week_of_first_day : print( " ", end="" ) day_of_week_index += 1 while self.this_month == a_day_in_this_month.month() : if day_of_week_index >= 7 : print( "\n%4d " % a_day_in_this_month.get_week_number(), end="" ) day_of_week_index = 0 print( "%5d" % a_day_in_this_month.day(), end="" ) a_day_in_this_month.increment() day_of_week_index += 1 print( "" ) class SpanishCalendar ( EnglishCalendar ) : def __init__( self, given_month, given_year ) : self.names_of_months = \ ( "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Deciembre" ) self.week_description = \ "Semana Lun Mar Mie Jue Vie Sab Dom" self.this_month = given_month self.this_year = given_year # The main program begins. an_english_calendar = EnglishCalendar( 7, 2012 ) an_english_calendar.show() a_spanish_calendar = SpanishCalendar( 12, 2022 ) a_spanish_calendar.show() # During compilation and execution, the file ISODate.py must be in # the same folder together with this program.